From d83ffb41c7f5d42bfb43a19e38ab3d1331f0d86e Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Wed, 2 Feb 2022 11:50:53 -0500 Subject: tests: Add tests for syntactically invalid globs --- tests.sh | 24 ++++++++++++++++++++++++ tests/test_X.out | 2 ++ tests/test_files0_from_file.out | 3 +++ tests/test_files0_from_stdin.out | 3 +++ tests/test_follow_comma.out | 2 ++ tests/test_name_backslash.out | 0 tests/test_name_bracket.out | 1 + tests/test_name_character_class.out | 3 +++ tests/test_name_double_backslash.out | 1 + tests/test_nohidden.out | 2 ++ tests/test_nohidden_depth.out | 2 ++ tests/test_printx.out | 2 ++ tests/test_s.out | 1 + 13 files changed, 46 insertions(+) create mode 100644 tests/test_name_backslash.out create mode 100644 tests/test_name_bracket.out create mode 100644 tests/test_name_character_class.out create mode 100644 tests/test_name_double_backslash.out diff --git a/tests.sh b/tests.sh index 0990110..940187e 100755 --- a/tests.sh +++ b/tests.sh @@ -233,6 +233,10 @@ posix_tests=( test_name_root_depth test_name_trailing_slash test_name_star_star + test_name_character_class + test_name_bracket + test_name_backslash + test_name_double_backslash test_newer test_newer_link @@ -993,6 +997,7 @@ function make_weirdnames() { touchp "$1/.../h" touchp "$1/\\/i" touchp "$1/ /j" + touchp "$1/[/k" } make_weirdnames "$TMP/weirdnames" @@ -1301,6 +1306,25 @@ function test_name_star_star() { bfs_diff basic -name '**f**' } +function test_name_character_class() { + bfs_diff basic -name '[e-g][!a-n][!p-z]' +} + +function test_name_bracket() { + # An unclosed [ should be matched literally + bfs_diff weirdnames -name '[' +} + +function test_name_backslash() { + # An unescaped \ doesn't match + bfs_diff weirdnames -name '\' +} + +function test_name_double_backslash() { + # An escaped \\ matches + bfs_diff weirdnames -name '\\' +} + function test_path() { bfs_diff basic -path 'basic/*f*' } diff --git a/tests/test_X.out b/tests/test_X.out index 008297b..52f0278 100644 --- a/tests/test_X.out +++ b/tests/test_X.out @@ -7,6 +7,7 @@ weirdnames/) weirdnames/, weirdnames/- weirdnames/... +weirdnames/[ weirdnames/!-/e weirdnames/!/d weirdnames/(-/c @@ -15,3 +16,4 @@ weirdnames/)/g weirdnames/,/f weirdnames/-/a weirdnames/.../h +weirdnames/[/k diff --git a/tests/test_files0_from_file.out b/tests/test_files0_from_file.out index 3648854..ac8aa45 100644 --- a/tests/test_files0_from_file.out +++ b/tests/test_files0_from_file.out @@ -7,6 +7,7 @@ , - ... +[ \ /j /j @@ -26,5 +27,7 @@ -/a .../h .../h +[/k +[/k \/i \/i diff --git a/tests/test_files0_from_stdin.out b/tests/test_files0_from_stdin.out index 3648854..ac8aa45 100644 --- a/tests/test_files0_from_stdin.out +++ b/tests/test_files0_from_stdin.out @@ -7,6 +7,7 @@ , - ... +[ \ /j /j @@ -26,5 +27,7 @@ -/a .../h .../h +[/k +[/k \/i \/i diff --git a/tests/test_follow_comma.out b/tests/test_follow_comma.out index 8b90e76..64d8c51 100644 --- a/tests/test_follow_comma.out +++ b/tests/test_follow_comma.out @@ -8,6 +8,7 @@ ./, ./- ./... +./[ ./\ ./ /j ./!-/e @@ -18,4 +19,5 @@ ./,/f ./-/a ./.../h +./[/k ./\/i diff --git a/tests/test_name_backslash.out b/tests/test_name_backslash.out new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_name_bracket.out b/tests/test_name_bracket.out new file mode 100644 index 0000000..5ff3c0c --- /dev/null +++ b/tests/test_name_bracket.out @@ -0,0 +1 @@ +weirdnames/[ diff --git a/tests/test_name_character_class.out b/tests/test_name_character_class.out new file mode 100644 index 0000000..e9d47b1 --- /dev/null +++ b/tests/test_name_character_class.out @@ -0,0 +1,3 @@ +basic/j/foo +basic/k/foo +basic/l/foo diff --git a/tests/test_name_double_backslash.out b/tests/test_name_double_backslash.out new file mode 100644 index 0000000..45ceda0 --- /dev/null +++ b/tests/test_name_double_backslash.out @@ -0,0 +1 @@ +weirdnames/\ diff --git a/tests/test_nohidden.out b/tests/test_nohidden.out index d2a9690..0c9b73d 100644 --- a/tests/test_nohidden.out +++ b/tests/test_nohidden.out @@ -7,6 +7,7 @@ weirdnames/(- weirdnames/) weirdnames/, weirdnames/- +weirdnames/[ weirdnames/\ weirdnames/ /j weirdnames/!-/e @@ -16,4 +17,5 @@ weirdnames/(/b weirdnames/)/g weirdnames/,/f weirdnames/-/a +weirdnames/[/k weirdnames/\/i diff --git a/tests/test_nohidden_depth.out b/tests/test_nohidden_depth.out index d2a9690..0c9b73d 100644 --- a/tests/test_nohidden_depth.out +++ b/tests/test_nohidden_depth.out @@ -7,6 +7,7 @@ weirdnames/(- weirdnames/) weirdnames/, weirdnames/- +weirdnames/[ weirdnames/\ weirdnames/ /j weirdnames/!-/e @@ -16,4 +17,5 @@ weirdnames/(/b weirdnames/)/g weirdnames/,/f weirdnames/-/a +weirdnames/[/k weirdnames/\/i diff --git a/tests/test_printx.out b/tests/test_printx.out index 53c7547..dd87a45 100644 --- a/tests/test_printx.out +++ b/tests/test_printx.out @@ -7,6 +7,7 @@ weirdnames/) weirdnames/, weirdnames/- weirdnames/... +weirdnames/[ weirdnames/\ weirdnames/\\ weirdnames/!-/e @@ -17,5 +18,6 @@ weirdnames/)/g weirdnames/,/f weirdnames/-/a weirdnames/.../h +weirdnames/[/k weirdnames/\ /j weirdnames/\\/i diff --git a/tests/test_s.out b/tests/test_s.out index e736cb5..6b790c2 100644 --- a/tests/test_s.out +++ b/tests/test_s.out @@ -8,4 +8,5 @@ weirdnames/) weirdnames/, weirdnames/- weirdnames/... +weirdnames/[ weirdnames/\ -- cgit v1.2.3