From e01042b84abdfa224d47e6d11eb9798ce4c7d2f8 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Fri, 16 Dec 2022 14:17:07 -0500 Subject: tests: Replace skip_unless test with test || skip --- tests/gnu/exec_flush_fail.sh | 2 +- tests/gnu/exec_plus_flush_fail.sh | 2 +- tests/gnu/fprint_error.sh | 2 +- tests/gnu/fprint_noerror.sh | 2 +- tests/gnu/fstype.sh | 3 +-- tests/gnu/gid_plus.sh | 2 +- tests/gnu/gid_plus_plus.sh | 2 +- tests/gnu/inum_automount.sh | 6 +++--- tests/gnu/iwholename.sh | 2 +- tests/gnu/print_error.sh | 2 +- tests/gnu/regex_invalid_utf8.sh | 6 +++--- tests/gnu/regextype_emacs.sh | 2 +- tests/gnu/regextype_grep.sh | 2 +- tests/gnu/uid_plus.sh | 2 +- tests/gnu/uid_plus_plus.sh | 2 +- tests/gnu/xtype_bind_mount.sh | 4 ++-- 16 files changed, 21 insertions(+), 22 deletions(-) (limited to 'tests/gnu') diff --git a/tests/gnu/exec_flush_fail.sh b/tests/gnu/exec_flush_fail.sh index 4772a14..ce796b2 100644 --- a/tests/gnu/exec_flush_fail.sh +++ b/tests/gnu/exec_flush_fail.sh @@ -1,3 +1,3 @@ # Failure to flush streams before exec should be caught -skip_unless test -e /dev/full +test -e /dev/full || skip fail invoke_bfs basic -print0 -exec true \; >/dev/full diff --git a/tests/gnu/exec_plus_flush_fail.sh b/tests/gnu/exec_plus_flush_fail.sh index 5c74fd8..8beee09 100644 --- a/tests/gnu/exec_plus_flush_fail.sh +++ b/tests/gnu/exec_plus_flush_fail.sh @@ -1,2 +1,2 @@ -skip_unless test -e /dev/full +test -e /dev/full || skip fail invoke_bfs basic/a -print0 -exec echo found {} + >/dev/full diff --git a/tests/gnu/fprint_error.sh b/tests/gnu/fprint_error.sh index e7f2394..0e75b0e 100644 --- a/tests/gnu/fprint_error.sh +++ b/tests/gnu/fprint_error.sh @@ -1,2 +1,2 @@ -skip_unless test -e /dev/full +test -e /dev/full || skip fail invoke_bfs basic -maxdepth 0 -fprint /dev/full diff --git a/tests/gnu/fprint_noerror.sh b/tests/gnu/fprint_noerror.sh index 142e935..f13a62b 100644 --- a/tests/gnu/fprint_noerror.sh +++ b/tests/gnu/fprint_noerror.sh @@ -1,3 +1,3 @@ # Regression test: /dev/full should not fail until actually written to -skip_unless test -e /dev/full +test -e /dev/full || skip invoke_bfs basic -false -fprint /dev/full diff --git a/tests/gnu/fstype.sh b/tests/gnu/fstype.sh index 939438e..05645c3 100644 --- a/tests/gnu/fstype.sh +++ b/tests/gnu/fstype.sh @@ -1,3 +1,2 @@ -fstype=$(invoke_bfs basic -maxdepth 0 -printf '%F\n') -skip_if test $? -ne 0 +fstype=$(invoke_bfs basic -maxdepth 0 -printf '%F\n') || skip bfs_diff basic -fstype "$fstype" diff --git a/tests/gnu/gid_plus.sh b/tests/gnu/gid_plus.sh index 8ad493b..ccba0e6 100644 --- a/tests/gnu/gid_plus.sh +++ b/tests/gnu/gid_plus.sh @@ -1,2 +1,2 @@ -skip_if test "$(id -g)" -eq 0 +test "$(id -g)" -eq 0 && skip bfs_diff basic -gid +0 diff --git a/tests/gnu/gid_plus_plus.sh b/tests/gnu/gid_plus_plus.sh index 7982633..ec7ae86 100644 --- a/tests/gnu/gid_plus_plus.sh +++ b/tests/gnu/gid_plus_plus.sh @@ -1,2 +1,2 @@ -skip_if test "$(id -g)" -eq 0 +test "$(id -g)" -eq 0 && skip bfs_diff basic -gid ++0 diff --git a/tests/gnu/inum_automount.sh b/tests/gnu/inum_automount.sh index 648ea05..6bf2977 100644 --- a/tests/gnu/inum_automount.sh +++ b/tests/gnu/inum_automount.sh @@ -1,11 +1,11 @@ # bfs shouldn't trigger automounts unless it descends into them -skip_unless test "$SUDO" -skip_unless command -v systemd-mount &>/dev/null +test "$SUDO" || skip +command -v systemd-mount &>/dev/null || skip clean_scratch mkdir scratch/{foo,automnt} -skip_unless sudo systemd-mount -A -o bind basic scratch/automnt +sudo systemd-mount -A -o bind basic scratch/automnt || skip before=$(inum scratch/automnt) bfs_diff scratch -inum "$before" -prune diff --git a/tests/gnu/iwholename.sh b/tests/gnu/iwholename.sh index 67e9630..0b2d038 100644 --- a/tests/gnu/iwholename.sh +++ b/tests/gnu/iwholename.sh @@ -1,2 +1,2 @@ -skip_unless invoke_bfs -quit -iwholename PATTERN +invoke_bfs -quit -iwholename PATTERN || skip bfs_diff basic -iwholename 'basic/*F*' diff --git a/tests/gnu/print_error.sh b/tests/gnu/print_error.sh index 9fd5af5..62a32b4 100644 --- a/tests/gnu/print_error.sh +++ b/tests/gnu/print_error.sh @@ -1,2 +1,2 @@ -skip_unless test -e /dev/full +test -e /dev/full || skip fail invoke_bfs basic -maxdepth 0 >/dev/full diff --git a/tests/gnu/regex_invalid_utf8.sh b/tests/gnu/regex_invalid_utf8.sh index edb4b1e..603d688 100644 --- a/tests/gnu/regex_invalid_utf8.sh +++ b/tests/gnu/regex_invalid_utf8.sh @@ -1,8 +1,8 @@ clean_scratch # Incomplete UTF-8 sequences -skip_unless touch scratch/$'\xC3' -skip_unless touch scratch/$'\xE2\x84' -skip_unless touch scratch/$'\xF0\x9F\x92' +touch scratch/$'\xC3' || skip +touch scratch/$'\xE2\x84' || skip +touch scratch/$'\xF0\x9F\x92' || skip bfs_diff scratch -regex 'scratch/..' diff --git a/tests/gnu/regextype_emacs.sh b/tests/gnu/regextype_emacs.sh index d0f68cc..3cc388c 100644 --- a/tests/gnu/regextype_emacs.sh +++ b/tests/gnu/regextype_emacs.sh @@ -1,3 +1,3 @@ -skip_unless invoke_bfs -regextype emacs -quit +invoke_bfs -regextype emacs -quit || skip bfs_diff basic -regextype emacs -regex '.*/\(f+o?o?\|bar\)' diff --git a/tests/gnu/regextype_grep.sh b/tests/gnu/regextype_grep.sh index 0136700..0830667 100644 --- a/tests/gnu/regextype_grep.sh +++ b/tests/gnu/regextype_grep.sh @@ -1,3 +1,3 @@ -skip_unless invoke_bfs -regextype grep -quit +invoke_bfs -regextype grep -quit || skip bfs_diff basic -regextype grep -regex '.*/f\+o\?o\?' diff --git a/tests/gnu/uid_plus.sh b/tests/gnu/uid_plus.sh index fc4bce3..22b2c8e 100644 --- a/tests/gnu/uid_plus.sh +++ b/tests/gnu/uid_plus.sh @@ -1,2 +1,2 @@ -skip_if test "$(id -u)" -eq 0 +test "$(id -u)" -eq 0 && skip bfs_diff basic -uid +0 diff --git a/tests/gnu/uid_plus_plus.sh b/tests/gnu/uid_plus_plus.sh index 5d5e086..e021888 100644 --- a/tests/gnu/uid_plus_plus.sh +++ b/tests/gnu/uid_plus_plus.sh @@ -1,2 +1,2 @@ -skip_if test "$(id -u)" -eq 0 +test "$(id -u)" -eq 0 && skip bfs_diff basic -uid ++0 diff --git a/tests/gnu/xtype_bind_mount.sh b/tests/gnu/xtype_bind_mount.sh index 264b6f8..a6dbed3 100644 --- a/tests/gnu/xtype_bind_mount.sh +++ b/tests/gnu/xtype_bind_mount.sh @@ -1,5 +1,5 @@ -skip_unless test "$SUDO" -skip_unless test "$UNAME" = "Linux" +test "$SUDO" || skip +test "$UNAME" = "Linux" || skip clean_scratch "$XTOUCH" scratch/{file,null} -- cgit v1.2.3 From 7d87b96b421b76e387cee903b7b7c1bc16c54310 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Fri, 16 Dec 2022 14:39:18 -0500 Subject: tests: Move crash detection into invoke_bfs, use ! instead of fail --- tests/bfs/D_incomplete.sh | 2 +- tests/bfs/and_incomplete.sh | 2 +- tests/bfs/comma_incomplete.sh | 2 +- tests/bfs/exclude_exclude.sh | 2 +- tests/bfs/exclude_print.sh | 2 +- tests/bfs/exec_flush_fprint_fail.sh | 2 +- tests/bfs/fprint_error_stderr.sh | 2 +- tests/bfs/fprint_error_stdout.sh | 2 +- tests/bfs/high_byte.sh | 2 +- tests/bfs/links_empty.sh | 2 +- tests/bfs/links_invalid.sh | 2 +- tests/bfs/links_negative.sh | 2 +- tests/bfs/links_noarg.sh | 2 +- tests/bfs/newerma_nonexistent.sh | 2 +- tests/bfs/newermq.sh | 2 +- tests/bfs/newermt_invalid.sh | 2 +- tests/bfs/newerqm.sh | 2 +- tests/bfs/or_incomplete.sh | 2 +- tests/bfs/perm_symbolic_double_comma.sh | 2 +- tests/bfs/perm_symbolic_missing_action.sh | 2 +- tests/bfs/perm_symbolic_trailing_comma.sh | 2 +- tests/bfs/printf_duplicate_flag.sh | 2 +- tests/bfs/printf_everything.sh | 4 ++-- tests/bfs/printf_incomplete_escape.sh | 2 +- tests/bfs/printf_incomplete_format.sh | 2 +- tests/bfs/printf_invalid_escape.sh | 2 +- tests/bfs/printf_invalid_format.sh | 2 +- tests/bfs/printf_must_be_numeric.sh | 2 +- tests/bfs/stderr_fails_loudly.sh | 2 +- tests/bfs/unexpected_operator.sh | 2 +- tests/bfs/xtype_depth.sh | 2 +- tests/bsd/f_incomplete.sh | 2 +- tests/bsd/mtime_bad_unit.sh | 2 +- tests/bsd/mtime_missing_unit.sh | 2 +- tests/common/maxdepth_incomplete.sh | 2 +- tests/common/mindepth_incomplete.sh | 2 +- tests/gnu/exec_flush_fail.sh | 2 +- tests/gnu/exec_nothing.sh | 2 +- tests/gnu/exec_plus_flush_fail.sh | 2 +- tests/gnu/files0_from_empty.sh | 2 +- tests/gnu/files0_from_error.sh | 2 +- tests/gnu/files0_from_none.sh | 2 +- tests/gnu/files0_from_nothing.sh | 2 +- tests/gnu/files0_from_nowhere.sh | 2 +- tests/gnu/files0_from_ok.sh | 2 +- tests/gnu/fls_nonexistent.sh | 2 +- tests/gnu/fprint0_nonexistent.sh | 2 +- tests/gnu/fprint_error.sh | 2 +- tests/gnu/fprint_noarg.sh | 2 +- tests/gnu/fprint_nonexistent.sh | 2 +- tests/gnu/fprintf_nofile.sh | 2 +- tests/gnu/fprintf_noformat.sh | 2 +- tests/gnu/fprintf_nonexistent.sh | 2 +- tests/gnu/ignore_readdir_race_root.sh | 2 +- tests/gnu/ok_nothing.sh | 2 +- tests/gnu/print_error.sh | 2 +- tests/gnu/regex_error.sh | 2 +- tests/posix/closed_stderr.sh | 2 +- tests/posix/closed_stdout.sh | 2 +- tests/posix/exec_plus_nothing.sh | 2 +- tests/posix/extra_paren.sh | 2 +- tests/posix/incomplete.sh | 2 +- tests/posix/missing_paren.sh | 2 +- tests/posix/newer_nonexistent.sh | 2 +- tests/posix/ok_plus_nothing.sh | 2 +- tests/posix/readdir_error.sh | 2 +- tests/tests.sh | 16 +++++----------- 67 files changed, 72 insertions(+), 78 deletions(-) (limited to 'tests/gnu') diff --git a/tests/bfs/D_incomplete.sh b/tests/bfs/D_incomplete.sh index 396d365..30c522a 100644 --- a/tests/bfs/D_incomplete.sh +++ b/tests/bfs/D_incomplete.sh @@ -1 +1 @@ -fail invoke_bfs -D +! invoke_bfs -D diff --git a/tests/bfs/and_incomplete.sh b/tests/bfs/and_incomplete.sh index f7bc2c3..05abc2d 100644 --- a/tests/bfs/and_incomplete.sh +++ b/tests/bfs/and_incomplete.sh @@ -1 +1 @@ -fail invoke_bfs -print -a +! invoke_bfs -print -a diff --git a/tests/bfs/comma_incomplete.sh b/tests/bfs/comma_incomplete.sh index 07cf505..bd60168 100644 --- a/tests/bfs/comma_incomplete.sh +++ b/tests/bfs/comma_incomplete.sh @@ -1 +1 @@ -fail invoke_bfs -print , +! invoke_bfs -print , diff --git a/tests/bfs/exclude_exclude.sh b/tests/bfs/exclude_exclude.sh index c687623..739342f 100644 --- a/tests/bfs/exclude_exclude.sh +++ b/tests/bfs/exclude_exclude.sh @@ -1 +1 @@ -fail invoke_bfs basic -exclude -exclude -name foo +! invoke_bfs basic -exclude -exclude -name foo diff --git a/tests/bfs/exclude_print.sh b/tests/bfs/exclude_print.sh index 52ff0fd..dc89e1d 100644 --- a/tests/bfs/exclude_print.sh +++ b/tests/bfs/exclude_print.sh @@ -1 +1 @@ -fail invoke_bfs basic -exclude -print +! invoke_bfs basic -exclude -print diff --git a/tests/bfs/exec_flush_fprint_fail.sh b/tests/bfs/exec_flush_fprint_fail.sh index b58624a..cd38e41 100644 --- a/tests/bfs/exec_flush_fprint_fail.sh +++ b/tests/bfs/exec_flush_fprint_fail.sh @@ -1,2 +1,2 @@ test -e /dev/full || skip -fail invoke_bfs basic/a -fprint /dev/full -exec true \; +! invoke_bfs basic/a -fprint /dev/full -exec true \; diff --git a/tests/bfs/fprint_error_stderr.sh b/tests/bfs/fprint_error_stderr.sh index e51d026..2cc4037 100644 --- a/tests/bfs/fprint_error_stderr.sh +++ b/tests/bfs/fprint_error_stderr.sh @@ -1,2 +1,2 @@ test -e /dev/full || skip -fail invoke_bfs basic -maxdepth 0 -fprint /dev/full 2>/dev/full +! invoke_bfs basic -maxdepth 0 -fprint /dev/full 2>/dev/full diff --git a/tests/bfs/fprint_error_stdout.sh b/tests/bfs/fprint_error_stdout.sh index 6aa4b11..42a7b36 100644 --- a/tests/bfs/fprint_error_stdout.sh +++ b/tests/bfs/fprint_error_stdout.sh @@ -1,2 +1,2 @@ test -e /dev/full || skip -fail invoke_bfs basic -maxdepth 0 -fprint /dev/full >/dev/full +! invoke_bfs basic -maxdepth 0 -fprint /dev/full >/dev/full diff --git a/tests/bfs/high_byte.sh b/tests/bfs/high_byte.sh index 222f24b..c76199f 100644 --- a/tests/bfs/high_byte.sh +++ b/tests/bfs/high_byte.sh @@ -1 +1 @@ -fail invoke_bfs -$'\xFF' +! invoke_bfs -$'\xFF' diff --git a/tests/bfs/links_empty.sh b/tests/bfs/links_empty.sh index 34c7c25..42cf6e5 100644 --- a/tests/bfs/links_empty.sh +++ b/tests/bfs/links_empty.sh @@ -1 +1 @@ -fail invoke_bfs links -links '' +! invoke_bfs links -links '' diff --git a/tests/bfs/links_invalid.sh b/tests/bfs/links_invalid.sh index ff69fa6..4d139c9 100644 --- a/tests/bfs/links_invalid.sh +++ b/tests/bfs/links_invalid.sh @@ -1 +1 @@ -fail invoke_bfs links -links ASDF +! invoke_bfs links -links ASDF diff --git a/tests/bfs/links_negative.sh b/tests/bfs/links_negative.sh index b5d9c58..e664b99 100644 --- a/tests/bfs/links_negative.sh +++ b/tests/bfs/links_negative.sh @@ -1 +1 @@ -fail invoke_bfs links -links +-1 +! invoke_bfs links -links +-1 diff --git a/tests/bfs/links_noarg.sh b/tests/bfs/links_noarg.sh index 5dede5f..5c948dc 100644 --- a/tests/bfs/links_noarg.sh +++ b/tests/bfs/links_noarg.sh @@ -1 +1 @@ -fail invoke_bfs links -links +! invoke_bfs links -links diff --git a/tests/bfs/newerma_nonexistent.sh b/tests/bfs/newerma_nonexistent.sh index 7f3695f..cdedb4a 100644 --- a/tests/bfs/newerma_nonexistent.sh +++ b/tests/bfs/newerma_nonexistent.sh @@ -1 +1 @@ -fail invoke_bfs times -newerma basic/nonexistent +! invoke_bfs times -newerma basic/nonexistent diff --git a/tests/bfs/newermq.sh b/tests/bfs/newermq.sh index 2a22586..2f705dc 100644 --- a/tests/bfs/newermq.sh +++ b/tests/bfs/newermq.sh @@ -1 +1 @@ -fail invoke_bfs times -newermq times/a +! invoke_bfs times -newermq times/a diff --git a/tests/bfs/newermt_invalid.sh b/tests/bfs/newermt_invalid.sh index 61d2485..98efece 100644 --- a/tests/bfs/newermt_invalid.sh +++ b/tests/bfs/newermt_invalid.sh @@ -1 +1 @@ -fail invoke_bfs times -newermt not_a_date_time +! invoke_bfs times -newermt not_a_date_time diff --git a/tests/bfs/newerqm.sh b/tests/bfs/newerqm.sh index da84350..c0cff98 100644 --- a/tests/bfs/newerqm.sh +++ b/tests/bfs/newerqm.sh @@ -1 +1 @@ -fail invoke_bfs times -newerqm times/a +! invoke_bfs times -newerqm times/a diff --git a/tests/bfs/or_incomplete.sh b/tests/bfs/or_incomplete.sh index c941b95..4af31b6 100644 --- a/tests/bfs/or_incomplete.sh +++ b/tests/bfs/or_incomplete.sh @@ -1 +1 @@ -fail invoke_bfs -print -o +! invoke_bfs -print -o diff --git a/tests/bfs/perm_symbolic_double_comma.sh b/tests/bfs/perm_symbolic_double_comma.sh index 66db0ac..48f9d4b 100644 --- a/tests/bfs/perm_symbolic_double_comma.sh +++ b/tests/bfs/perm_symbolic_double_comma.sh @@ -1 +1 @@ -fail invoke_bfs perms -perm a+r,,u+w +! invoke_bfs perms -perm a+r,,u+w diff --git a/tests/bfs/perm_symbolic_missing_action.sh b/tests/bfs/perm_symbolic_missing_action.sh index 3b18721..28446ab 100644 --- a/tests/bfs/perm_symbolic_missing_action.sh +++ b/tests/bfs/perm_symbolic_missing_action.sh @@ -1 +1 @@ -fail invoke_bfs perms -perm a +! invoke_bfs perms -perm a diff --git a/tests/bfs/perm_symbolic_trailing_comma.sh b/tests/bfs/perm_symbolic_trailing_comma.sh index c52ebe6..01bbc16 100644 --- a/tests/bfs/perm_symbolic_trailing_comma.sh +++ b/tests/bfs/perm_symbolic_trailing_comma.sh @@ -1 +1 @@ -fail invoke_bfs perms -perm a+r, +! invoke_bfs perms -perm a+r, diff --git a/tests/bfs/printf_duplicate_flag.sh b/tests/bfs/printf_duplicate_flag.sh index 77650d0..5ff29f1 100644 --- a/tests/bfs/printf_duplicate_flag.sh +++ b/tests/bfs/printf_duplicate_flag.sh @@ -1 +1 @@ -fail invoke_bfs basic -printf '%--p' +! invoke_bfs basic -printf '%--p' diff --git a/tests/bfs/printf_everything.sh b/tests/bfs/printf_everything.sh index 5f20718..5e95830 100644 --- a/tests/bfs/printf_everything.sh +++ b/tests/bfs/printf_everything.sh @@ -1,14 +1,14 @@ everything=(%{a,b,c,d,D,f,g,G,h,H,i,k,l,m,M,n,p,P,s,S,t,u,U,y,Y}) # Check if we have fstypes -if ! fail invoke_bfs basic -printf '%F' -quit >/dev/null; then +if ! ! invoke_bfs basic -printf '%F' -quit >/dev/null; then everything+=(%F) fi everything+=(%{A,C,T}{%,+,@,a,A,b,B,c,C,d,D,e,F,g,G,h,H,I,j,k,l,m,M,n,p,r,R,s,S,t,T,u,U,V,w,W,x,X,y,Y,z,Z}) # Check if we have birth times -if ! fail invoke_bfs basic -printf '%w' -quit >/dev/null; then +if ! ! invoke_bfs basic -printf '%w' -quit >/dev/null; then everything+=(%w %{B,W}{%,+,@,a,A,b,B,c,C,d,D,e,F,g,G,h,H,I,j,k,l,m,M,n,p,r,R,s,S,t,T,u,U,V,w,W,x,X,y,Y,z,Z}) fi diff --git a/tests/bfs/printf_incomplete_escape.sh b/tests/bfs/printf_incomplete_escape.sh index 144add5..f560d28 100644 --- a/tests/bfs/printf_incomplete_escape.sh +++ b/tests/bfs/printf_incomplete_escape.sh @@ -1 +1 @@ -fail invoke_bfs basic -printf '\' +! invoke_bfs basic -printf '\' diff --git a/tests/bfs/printf_incomplete_format.sh b/tests/bfs/printf_incomplete_format.sh index 347a0f4..92c6afc 100644 --- a/tests/bfs/printf_incomplete_format.sh +++ b/tests/bfs/printf_incomplete_format.sh @@ -1 +1 @@ -fail invoke_bfs basic -printf '%' +! invoke_bfs basic -printf '%' diff --git a/tests/bfs/printf_invalid_escape.sh b/tests/bfs/printf_invalid_escape.sh index ce12233..4338f9b 100644 --- a/tests/bfs/printf_invalid_escape.sh +++ b/tests/bfs/printf_invalid_escape.sh @@ -1 +1 @@ -fail invoke_bfs basic -printf '\!' +! invoke_bfs basic -printf '\!' diff --git a/tests/bfs/printf_invalid_format.sh b/tests/bfs/printf_invalid_format.sh index 1717615..59d63a7 100644 --- a/tests/bfs/printf_invalid_format.sh +++ b/tests/bfs/printf_invalid_format.sh @@ -1 +1 @@ -fail invoke_bfs basic -printf '%!' +! invoke_bfs basic -printf '%!' diff --git a/tests/bfs/printf_must_be_numeric.sh b/tests/bfs/printf_must_be_numeric.sh index eabb3d6..7c7c3fa 100644 --- a/tests/bfs/printf_must_be_numeric.sh +++ b/tests/bfs/printf_must_be_numeric.sh @@ -1 +1 @@ -fail invoke_bfs basic -printf '%+p' +! invoke_bfs basic -printf '%+p' diff --git a/tests/bfs/stderr_fails_loudly.sh b/tests/bfs/stderr_fails_loudly.sh index c423d9e..8572d5a 100644 --- a/tests/bfs/stderr_fails_loudly.sh +++ b/tests/bfs/stderr_fails_loudly.sh @@ -1,2 +1,2 @@ test -e /dev/full || skip -fail invoke_bfs -D all basic -false -fprint /dev/full 2>/dev/full +! invoke_bfs -D all basic -false -fprint /dev/full 2>/dev/full diff --git a/tests/bfs/unexpected_operator.sh b/tests/bfs/unexpected_operator.sh index b3658f6..2eb0e71 100644 --- a/tests/bfs/unexpected_operator.sh +++ b/tests/bfs/unexpected_operator.sh @@ -1 +1 @@ -fail invoke_bfs \! -o -print +! invoke_bfs \! -o -print diff --git a/tests/bfs/xtype_depth.sh b/tests/bfs/xtype_depth.sh index cd478af..02c8173 100644 --- a/tests/bfs/xtype_depth.sh +++ b/tests/bfs/xtype_depth.sh @@ -1,2 +1,2 @@ # Make sure -xtype is considered side-effecting for facts_when_impure -fail invoke_bfs loops -xtype l -depth 100 +! invoke_bfs loops -xtype l -depth 100 diff --git a/tests/bsd/f_incomplete.sh b/tests/bsd/f_incomplete.sh index acb63af..50afe42 100644 --- a/tests/bsd/f_incomplete.sh +++ b/tests/bsd/f_incomplete.sh @@ -1,2 +1,2 @@ -fail invoke_bfs -f +! invoke_bfs -f diff --git a/tests/bsd/mtime_bad_unit.sh b/tests/bsd/mtime_bad_unit.sh index 3921f80..6e2caf1 100644 --- a/tests/bsd/mtime_bad_unit.sh +++ b/tests/bsd/mtime_bad_unit.sh @@ -1 +1 @@ -fail invoke_bfs times -mtime +1q +! invoke_bfs times -mtime +1q diff --git a/tests/bsd/mtime_missing_unit.sh b/tests/bsd/mtime_missing_unit.sh index 3ac4c97..f6b1f93 100644 --- a/tests/bsd/mtime_missing_unit.sh +++ b/tests/bsd/mtime_missing_unit.sh @@ -1 +1 @@ -fail invoke_bfs times -mtime +1w2 +! invoke_bfs times -mtime +1w2 diff --git a/tests/common/maxdepth_incomplete.sh b/tests/common/maxdepth_incomplete.sh index 536dcf5..0bcb461 100644 --- a/tests/common/maxdepth_incomplete.sh +++ b/tests/common/maxdepth_incomplete.sh @@ -1 +1 @@ -fail invoke_bfs basic -maxdepth +! invoke_bfs basic -maxdepth diff --git a/tests/common/mindepth_incomplete.sh b/tests/common/mindepth_incomplete.sh index 19a3b21..6f55a42 100644 --- a/tests/common/mindepth_incomplete.sh +++ b/tests/common/mindepth_incomplete.sh @@ -1 +1 @@ -fail invoke_bfs basic -mindepth +! invoke_bfs basic -mindepth diff --git a/tests/gnu/exec_flush_fail.sh b/tests/gnu/exec_flush_fail.sh index ce796b2..5505f7a 100644 --- a/tests/gnu/exec_flush_fail.sh +++ b/tests/gnu/exec_flush_fail.sh @@ -1,3 +1,3 @@ # Failure to flush streams before exec should be caught test -e /dev/full || skip -fail invoke_bfs basic -print0 -exec true \; >/dev/full +! invoke_bfs basic -print0 -exec true \; >/dev/full diff --git a/tests/gnu/exec_nothing.sh b/tests/gnu/exec_nothing.sh index 9d613e8..443aa0d 100644 --- a/tests/gnu/exec_nothing.sh +++ b/tests/gnu/exec_nothing.sh @@ -1,2 +1,2 @@ # Regression test: don't segfault on missing command -fail invoke_bfs basic -exec \; +! invoke_bfs basic -exec \; diff --git a/tests/gnu/exec_plus_flush_fail.sh b/tests/gnu/exec_plus_flush_fail.sh index 8beee09..53a50e5 100644 --- a/tests/gnu/exec_plus_flush_fail.sh +++ b/tests/gnu/exec_plus_flush_fail.sh @@ -1,2 +1,2 @@ test -e /dev/full || skip -fail invoke_bfs basic/a -print0 -exec echo found {} + >/dev/full +! invoke_bfs basic/a -print0 -exec echo found {} + >/dev/full diff --git a/tests/gnu/files0_from_empty.sh b/tests/gnu/files0_from_empty.sh index bd4fbf4..85eee8f 100644 --- a/tests/gnu/files0_from_empty.sh +++ b/tests/gnu/files0_from_empty.sh @@ -1 +1 @@ -printf "\0" | fail invoke_bfs -files0-from - +! printf "\0" | invoke_bfs -files0-from - diff --git a/tests/gnu/files0_from_error.sh b/tests/gnu/files0_from_error.sh index ab27ea2..1515d0b 100644 --- a/tests/gnu/files0_from_error.sh +++ b/tests/gnu/files0_from_error.sh @@ -1 +1 @@ -fail invoke_bfs -files0-from basic +! invoke_bfs -files0-from basic diff --git a/tests/gnu/files0_from_none.sh b/tests/gnu/files0_from_none.sh index c6e5b97..090fce0 100644 --- a/tests/gnu/files0_from_none.sh +++ b/tests/gnu/files0_from_none.sh @@ -1 +1 @@ -printf "" | fail invoke_bfs -files0-from - +! printf "" | invoke_bfs -files0-from - diff --git a/tests/gnu/files0_from_nothing.sh b/tests/gnu/files0_from_nothing.sh index 5fdae60..fee50a8 100644 --- a/tests/gnu/files0_from_nothing.sh +++ b/tests/gnu/files0_from_nothing.sh @@ -1 +1 @@ -fail invoke_bfs -files0-from basic/nonexistent +! invoke_bfs -files0-from basic/nonexistent diff --git a/tests/gnu/files0_from_nowhere.sh b/tests/gnu/files0_from_nowhere.sh index 2337613..68eea4b 100644 --- a/tests/gnu/files0_from_nowhere.sh +++ b/tests/gnu/files0_from_nowhere.sh @@ -1 +1 @@ -fail invoke_bfs -files0-from +! invoke_bfs -files0-from diff --git a/tests/gnu/files0_from_ok.sh b/tests/gnu/files0_from_ok.sh index 5387e5c..8e145ce 100644 --- a/tests/gnu/files0_from_ok.sh +++ b/tests/gnu/files0_from_ok.sh @@ -1 +1 @@ -printf "basic\0" | fail invoke_bfs -files0-from - -ok echo {} \; +! printf "basic\0" | invoke_bfs -files0-from - -ok echo {} \; diff --git a/tests/gnu/fls_nonexistent.sh b/tests/gnu/fls_nonexistent.sh index 4756834..ff86763 100644 --- a/tests/gnu/fls_nonexistent.sh +++ b/tests/gnu/fls_nonexistent.sh @@ -1 +1 @@ -fail invoke_bfs rainbow -fls scratch/nonexistent/path +! invoke_bfs rainbow -fls scratch/nonexistent/path diff --git a/tests/gnu/fprint0_nonexistent.sh b/tests/gnu/fprint0_nonexistent.sh index d8e0f30..ec14c2d 100644 --- a/tests/gnu/fprint0_nonexistent.sh +++ b/tests/gnu/fprint0_nonexistent.sh @@ -1 +1 @@ -fail invoke_bfs basic -fprint0 scratch/nonexistent/path +! invoke_bfs basic -fprint0 scratch/nonexistent/path diff --git a/tests/gnu/fprint_error.sh b/tests/gnu/fprint_error.sh index 0e75b0e..7617034 100644 --- a/tests/gnu/fprint_error.sh +++ b/tests/gnu/fprint_error.sh @@ -1,2 +1,2 @@ test -e /dev/full || skip -fail invoke_bfs basic -maxdepth 0 -fprint /dev/full +! invoke_bfs basic -maxdepth 0 -fprint /dev/full diff --git a/tests/gnu/fprint_noarg.sh b/tests/gnu/fprint_noarg.sh index bf772f3..8511649 100644 --- a/tests/gnu/fprint_noarg.sh +++ b/tests/gnu/fprint_noarg.sh @@ -1 +1 @@ -fail invoke_bfs basic -fprint +! invoke_bfs basic -fprint diff --git a/tests/gnu/fprint_nonexistent.sh b/tests/gnu/fprint_nonexistent.sh index b6dac8a..4409162 100644 --- a/tests/gnu/fprint_nonexistent.sh +++ b/tests/gnu/fprint_nonexistent.sh @@ -1 +1 @@ -fail invoke_bfs basic -fprint scratch/nonexistent/path +! invoke_bfs basic -fprint scratch/nonexistent/path diff --git a/tests/gnu/fprintf_nofile.sh b/tests/gnu/fprintf_nofile.sh index c2c48a5..4e79002 100644 --- a/tests/gnu/fprintf_nofile.sh +++ b/tests/gnu/fprintf_nofile.sh @@ -1 +1 @@ -fail invoke_bfs basic -fprintf +! invoke_bfs basic -fprintf diff --git a/tests/gnu/fprintf_noformat.sh b/tests/gnu/fprintf_noformat.sh index 0d285c3..fd97f4c 100644 --- a/tests/gnu/fprintf_noformat.sh +++ b/tests/gnu/fprintf_noformat.sh @@ -1 +1 @@ -fail invoke_bfs basic -fprintf /dev/null +! invoke_bfs basic -fprintf /dev/null diff --git a/tests/gnu/fprintf_nonexistent.sh b/tests/gnu/fprintf_nonexistent.sh index 6ed141a..160e739 100644 --- a/tests/gnu/fprintf_nonexistent.sh +++ b/tests/gnu/fprintf_nonexistent.sh @@ -1 +1 @@ -fail invoke_bfs basic -fprintf scratch/nonexistent/path '%p\n' +! invoke_bfs basic -fprintf scratch/nonexistent/path '%p\n' diff --git a/tests/gnu/ignore_readdir_race_root.sh b/tests/gnu/ignore_readdir_race_root.sh index bad7391..dc41e7f 100644 --- a/tests/gnu/ignore_readdir_race_root.sh +++ b/tests/gnu/ignore_readdir_race_root.sh @@ -1,2 +1,2 @@ # Make sure -ignore_readdir_race doesn't suppress ENOENT at the root -fail invoke_bfs basic/nonexistent -ignore_readdir_race +! invoke_bfs basic/nonexistent -ignore_readdir_race diff --git a/tests/gnu/ok_nothing.sh b/tests/gnu/ok_nothing.sh index 439687b..52c3547 100644 --- a/tests/gnu/ok_nothing.sh +++ b/tests/gnu/ok_nothing.sh @@ -1,2 +1,2 @@ # Regression test: don't segfault on missing command -fail invoke_bfs basic -ok \; +! invoke_bfs basic -ok \; diff --git a/tests/gnu/print_error.sh b/tests/gnu/print_error.sh index 62a32b4..bc79637 100644 --- a/tests/gnu/print_error.sh +++ b/tests/gnu/print_error.sh @@ -1,2 +1,2 @@ test -e /dev/full || skip -fail invoke_bfs basic -maxdepth 0 >/dev/full +! invoke_bfs basic -maxdepth 0 >/dev/full diff --git a/tests/gnu/regex_error.sh b/tests/gnu/regex_error.sh index 9bd4c8d..4af933f 100644 --- a/tests/gnu/regex_error.sh +++ b/tests/gnu/regex_error.sh @@ -1 +1 @@ -fail invoke_bfs basic -regex '[' +! invoke_bfs basic -regex '[' diff --git a/tests/posix/closed_stderr.sh b/tests/posix/closed_stderr.sh index cc746ef..570d5bb 100644 --- a/tests/posix/closed_stderr.sh +++ b/tests/posix/closed_stderr.sh @@ -1 +1 @@ -fail invoke_bfs basic >&- 2>&- +! invoke_bfs basic >&- 2>&- diff --git a/tests/posix/closed_stdout.sh b/tests/posix/closed_stdout.sh index 446bf56..25c060d 100644 --- a/tests/posix/closed_stdout.sh +++ b/tests/posix/closed_stdout.sh @@ -1 +1 @@ -fail invoke_bfs basic >&- +! invoke_bfs basic >&- diff --git a/tests/posix/exec_plus_nothing.sh b/tests/posix/exec_plus_nothing.sh index ef01968..347722d 100644 --- a/tests/posix/exec_plus_nothing.sh +++ b/tests/posix/exec_plus_nothing.sh @@ -1,2 +1,2 @@ # Regression test: don't look OOB for {} + -fail invoke_bfs basic -exec + +! invoke_bfs basic -exec + diff --git a/tests/posix/extra_paren.sh b/tests/posix/extra_paren.sh index cd8e8f8..d15022f 100644 --- a/tests/posix/extra_paren.sh +++ b/tests/posix/extra_paren.sh @@ -1 +1 @@ -fail invoke_bfs basic -print \) +! invoke_bfs basic -print \) diff --git a/tests/posix/incomplete.sh b/tests/posix/incomplete.sh index 07b1b61..bca5a13 100644 --- a/tests/posix/incomplete.sh +++ b/tests/posix/incomplete.sh @@ -1 +1 @@ -fail invoke_bfs basic \( +! invoke_bfs basic \( diff --git a/tests/posix/missing_paren.sh b/tests/posix/missing_paren.sh index ac8dd60..d906fbe 100644 --- a/tests/posix/missing_paren.sh +++ b/tests/posix/missing_paren.sh @@ -1 +1 @@ -fail invoke_bfs basic \( -print +! invoke_bfs basic \( -print diff --git a/tests/posix/newer_nonexistent.sh b/tests/posix/newer_nonexistent.sh index 789cadf..5f2da4b 100644 --- a/tests/posix/newer_nonexistent.sh +++ b/tests/posix/newer_nonexistent.sh @@ -1 +1 @@ -fail invoke_bfs times -newer times/nonexistent +! invoke_bfs times -newer times/nonexistent diff --git a/tests/posix/ok_plus_nothing.sh b/tests/posix/ok_plus_nothing.sh index 7cb7de5..77c7644 100644 --- a/tests/posix/ok_plus_nothing.sh +++ b/tests/posix/ok_plus_nothing.sh @@ -1,2 +1,2 @@ # Regression test: don't look OOB for {} + -fail invoke_bfs basic -ok + +! invoke_bfs basic -ok + diff --git a/tests/posix/readdir_error.sh b/tests/posix/readdir_error.sh index 483f543..e45ec5c 100644 --- a/tests/posix/readdir_error.sh +++ b/tests/posix/readdir_error.sh @@ -34,4 +34,4 @@ done # On Linux, open(/proc/$pid/net) will succeed but readdir() will fail test -r "/proc/$pid/net" || skip -fail invoke_bfs "/proc/$pid/net" >/dev/null +! invoke_bfs "/proc/$pid/net" >/dev/null diff --git a/tests/tests.sh b/tests/tests.sh index 3047bf4..844de5c 100755 --- a/tests/tests.sh +++ b/tests/tests.sh @@ -476,19 +476,13 @@ function bfs_verbose() { function invoke_bfs() { bfs_verbose "$@" "${BFS[@]}" "$@" -} - -# Expect a command to fail, but not crash -function fail() { - "$@" - local STATUS="$?" + local status=$? - if ((STATUS > 125)); then - exit "$STATUS" - elif ((STATUS > 0)); then - return 0 + # Allow bfs to fail, but not crash + if ((status > 125)); then + exit $status else - return 1 + return $status fi } -- cgit v1.2.3 From e50c19f284dad6b4b7b79f91cc8576a97626be8a Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Fri, 16 Dec 2022 15:32:04 -0500 Subject: tests: Turn on set -e --- tests/bfs/D_unknown.sh | 2 +- tests/bfs/O9.sh | 2 +- tests/bfs/execdir_plus_nonexistent.sh | 7 +++---- tests/bfs/help.sh | 10 ++++------ tests/bsd/X.sh | 3 +-- tests/bsd/exit.sh | 10 ++-------- tests/common/L_mount.sh | 7 +++---- tests/common/execdir_nonexistent.sh | 7 +++---- tests/common/inum_bind_mount.sh | 6 ++---- tests/common/inum_mount.sh | 6 ++---- tests/common/mount.sh | 7 +++---- tests/gnu/L_delete.sh | 2 +- tests/gnu/L_loops_continue.sh | 3 +-- tests/gnu/inum_automount.sh | 8 +++----- tests/gnu/printf_Y_error.sh | 10 +++------- tests/gnu/xtype_bind_mount.sh | 8 +++----- tests/posix/L_loops.sh | 2 +- tests/posix/L_xdev.sh | 7 +++---- tests/posix/depth_error.sh | 10 +++------- tests/posix/exec_nonexistent.sh | 7 +++---- tests/posix/exec_plus_nonexistent.sh | 7 +++---- tests/posix/exec_plus_status.sh | 3 +-- tests/posix/readdir_error.sh | 2 +- tests/posix/type_bind_mount.sh | 6 ++---- tests/posix/xdev.sh | 7 +++---- tests/tests.sh | 18 +++++++++++++----- 26 files changed, 69 insertions(+), 98 deletions(-) (limited to 'tests/gnu') diff --git a/tests/bfs/D_unknown.sh b/tests/bfs/D_unknown.sh index e3614ba..cac9bd9 100644 --- a/tests/bfs/D_unknown.sh +++ b/tests/bfs/D_unknown.sh @@ -1,4 +1,4 @@ stderr=$(invoke_bfs -warn -D unknown basic 2>&1 >"$OUT") -[ -n "$stderr" ] || return 1 +[ -n "$stderr" ] sort_output diff_output diff --git a/tests/bfs/O9.sh b/tests/bfs/O9.sh index 12f6c2d..c12a7a3 100644 --- a/tests/bfs/O9.sh +++ b/tests/bfs/O9.sh @@ -1,4 +1,4 @@ stderr=$(invoke_bfs -warn -O9 basic 2>&1 >"$OUT") -[ -n "$stderr" ] || return 1 +[ -n "$stderr" ] sort_output diff_output diff --git a/tests/bfs/execdir_plus_nonexistent.sh b/tests/bfs/execdir_plus_nonexistent.sh index 8436953..88f3e90 100644 --- a/tests/bfs/execdir_plus_nonexistent.sh +++ b/tests/bfs/execdir_plus_nonexistent.sh @@ -1,5 +1,4 @@ -stderr=$(invoke_bfs basic -execdir "$TESTS/nonexistent" {} + 2>&1 >/dev/null) -[ -n "$stderr" ] || return 1 +! stderr=$(invoke_bfs basic -execdir "$TESTS/nonexistent" {} + 2>&1 >/dev/null) +[ -n "$stderr" ] -bfs_diff basic -execdir "$TESTS/nonexistent" {} + -print -(($? == EX_BFS)) +check_exit $EX_BFS bfs_diff basic -execdir "$TESTS/nonexistent" {} + -print diff --git a/tests/bfs/help.sh b/tests/bfs/help.sh index 5e5c684..2c0b28a 100644 --- a/tests/bfs/help.sh +++ b/tests/bfs/help.sh @@ -1,6 +1,4 @@ -invoke_bfs -help | grep -E '\{...?\}' && return 1 -invoke_bfs -D help | grep -E '\{...?\}' && return 1 -invoke_bfs -S help | grep -E '\{...?\}' && return 1 -invoke_bfs -regextype help | grep -E '\{...?\}' && return 1 - -return 0 +! invoke_bfs -help | grep -E '\{...?\}' +! invoke_bfs -D help | grep -E '\{...?\}' +! invoke_bfs -S help | grep -E '\{...?\}' +! invoke_bfs -regextype help | grep -E '\{...?\}' diff --git a/tests/bsd/X.sh b/tests/bsd/X.sh index 03d9eee..df9a261 100644 --- a/tests/bsd/X.sh +++ b/tests/bsd/X.sh @@ -1,2 +1 @@ -bfs_diff -X weirdnames -[ $? -eq $EX_BFS ] +check_exit $EX_BFS bfs_diff -X weirdnames diff --git a/tests/bsd/exit.sh b/tests/bsd/exit.sh index 524a75f..248349c 100644 --- a/tests/bsd/exit.sh +++ b/tests/bsd/exit.sh @@ -1,11 +1,5 @@ -invoke_bfs basic -name foo -exit 42 -if [ $? -ne 42 ]; then - return 1 -fi +check_exit 42 invoke_bfs basic -name foo -exit 42 -invoke_bfs basic -name qux -exit 42 -if [ $? -ne 0 ]; then - return 1 -fi +check_exit 0 invoke_bfs basic -name qux -exit 42 bfs_diff basic/g -print -name g -exit diff --git a/tests/common/L_mount.sh b/tests/common/L_mount.sh index 5b56762..9ab785e 100644 --- a/tests/common/L_mount.sh +++ b/tests/common/L_mount.sh @@ -3,13 +3,12 @@ test "$UNAME" = "Darwin" && skip clean_scratch mkdir scratch/{foo,mnt} + sudo mount -t tmpfs tmpfs scratch/mnt +trap "sudo umount scratch/mnt" EXIT + ln -s ../mnt scratch/foo/bar "$XTOUCH" scratch/mnt/baz ln -s ../mnt/baz scratch/foo/qux bfs_diff -L scratch -mount -ret=$? - -sudo umount scratch/mnt -return $ret diff --git a/tests/common/execdir_nonexistent.sh b/tests/common/execdir_nonexistent.sh index 5d116e5..af17fe5 100644 --- a/tests/common/execdir_nonexistent.sh +++ b/tests/common/execdir_nonexistent.sh @@ -1,5 +1,4 @@ -stderr=$(invoke_bfs basic -execdir "$TESTS/nonexistent" {} \; 2>&1 >/dev/null) -[ -n "$stderr" ] || return 1 +! stderr=$(invoke_bfs basic -execdir "$TESTS/nonexistent" {} \; 2>&1 >/dev/null) +[ -n "$stderr" ] -bfs_diff basic -print -execdir "$TESTS/nonexistent" {} \; -print -(($? == EX_BFS)) +check_exit $EX_BFS bfs_diff basic -print -execdir "$TESTS/nonexistent" {} \; -print diff --git a/tests/common/inum_bind_mount.sh b/tests/common/inum_bind_mount.sh index a9e01bf..625ee3d 100644 --- a/tests/common/inum_bind_mount.sh +++ b/tests/common/inum_bind_mount.sh @@ -3,10 +3,8 @@ test "$UNAME" = "Linux" || skip clean_scratch "$XTOUCH" scratch/{foo,bar} + sudo mount --bind scratch/{foo,bar} +trap "sudo umount scratch/bar" EXIT bfs_diff scratch -inum "$(inum scratch/bar)" -ret=$? - -sudo umount scratch/bar -return $ret diff --git a/tests/common/inum_mount.sh b/tests/common/inum_mount.sh index 7cc5e40..91d06e2 100644 --- a/tests/common/inum_mount.sh +++ b/tests/common/inum_mount.sh @@ -3,10 +3,8 @@ test "$UNAME" = "Darwin" && skip clean_scratch mkdir scratch/{foo,mnt} + sudo mount -t tmpfs tmpfs scratch/mnt +trap "sudo umount scratch/mnt" EXIT bfs_diff scratch -inum "$(inum scratch/mnt)" -ret=$? - -sudo umount scratch/mnt -return $ret diff --git a/tests/common/mount.sh b/tests/common/mount.sh index f077ea2..3f3ed38 100644 --- a/tests/common/mount.sh +++ b/tests/common/mount.sh @@ -3,11 +3,10 @@ test "$UNAME" = "Darwin" && skip clean_scratch mkdir scratch/{foo,mnt} + sudo mount -t tmpfs tmpfs scratch/mnt +trap "sudo umount scratch/mnt" EXIT + "$XTOUCH" scratch/foo/bar scratch/mnt/baz bfs_diff scratch -mount -ret=$? - -sudo umount scratch/mnt -return $ret diff --git a/tests/gnu/L_delete.sh b/tests/gnu/L_delete.sh index 6ec167c..8fdb12a 100644 --- a/tests/gnu/L_delete.sh +++ b/tests/gnu/L_delete.sh @@ -4,6 +4,6 @@ mkdir scratch/bar ln -s ../foo scratch/bar/baz # Don't try to rmdir() a symlink -invoke_bfs -L scratch/bar -delete || return 1 +invoke_bfs -L scratch/bar -delete bfs_diff scratch diff --git a/tests/gnu/L_loops_continue.sh b/tests/gnu/L_loops_continue.sh index 0244137..d4c95f1 100644 --- a/tests/gnu/L_loops_continue.sh +++ b/tests/gnu/L_loops_continue.sh @@ -1,2 +1 @@ -bfs_diff -L loops -[ $? -eq $EX_BFS ] +check_exit $EX_BFS bfs_diff -L loops diff --git a/tests/gnu/inum_automount.sh b/tests/gnu/inum_automount.sh index 6bf2977..da2e3b0 100644 --- a/tests/gnu/inum_automount.sh +++ b/tests/gnu/inum_automount.sh @@ -5,13 +5,11 @@ command -v systemd-mount &>/dev/null || skip clean_scratch mkdir scratch/{foo,automnt} + sudo systemd-mount -A -o bind basic scratch/automnt || skip +trap "sudo systemd-umount scratch/automnt" EXIT before=$(inum scratch/automnt) bfs_diff scratch -inum "$before" -prune -ret=$? after=$(inum scratch/automnt) - -sudo systemd-umount scratch/automnt - -((ret == 0 && before == after)) +((before == after)) diff --git a/tests/gnu/printf_Y_error.sh b/tests/gnu/printf_Y_error.sh index 6487711..e9a2083 100644 --- a/tests/gnu/printf_Y_error.sh +++ b/tests/gnu/printf_Y_error.sh @@ -1,12 +1,8 @@ clean_scratch mkdir scratch/foo -chmod -x scratch/foo ln -s foo/bar scratch/bar -bfs_diff scratch -printf '(%p) (%l) %y %Y\n' -ret=$? - -chmod +x scratch/foo -clean_scratch +chmod -x scratch/foo +trap "chmod +x scratch/foo" EXIT -[ $ret -eq $EX_BFS ] +check_exit $EX_BFS bfs_diff scratch -printf '(%p) (%l) %y %Y\n' diff --git a/tests/gnu/xtype_bind_mount.sh b/tests/gnu/xtype_bind_mount.sh index a6dbed3..9babd9d 100644 --- a/tests/gnu/xtype_bind_mount.sh +++ b/tests/gnu/xtype_bind_mount.sh @@ -3,11 +3,9 @@ test "$UNAME" = "Linux" || skip clean_scratch "$XTOUCH" scratch/{file,null} -sudo mount --bind /dev/null scratch/null ln -s /dev/null scratch/link -bfs_diff -L scratch -type c -ret=$? +sudo mount --bind /dev/null scratch/null +trap "sudo umount scratch/null" EXIT -sudo umount scratch/null -return $ret +bfs_diff -L scratch -type c diff --git a/tests/posix/L_loops.sh b/tests/posix/L_loops.sh index f737cea..1314401 100644 --- a/tests/posix/L_loops.sh +++ b/tests/posix/L_loops.sh @@ -1,4 +1,4 @@ # POSIX says it's okay to either stop or keep going on seeing a filesystem # loop, as long as a diagnostic is printed -errors=$(invoke_bfs -L loops 2>&1 >/dev/null) +! errors=$(invoke_bfs -L loops 2>&1 >/dev/null) [ -n "$errors" ] diff --git a/tests/posix/L_xdev.sh b/tests/posix/L_xdev.sh index 2fc99dd..587c8bb 100644 --- a/tests/posix/L_xdev.sh +++ b/tests/posix/L_xdev.sh @@ -3,13 +3,12 @@ test "$UNAME" = "Darwin" && skip clean_scratch mkdir scratch/{foo,mnt} + sudo mount -t tmpfs tmpfs scratch/mnt +trap "sudo umount scratch/mnt" EXIT + ln -s ../mnt scratch/foo/bar "$XTOUCH" scratch/mnt/baz ln -s ../mnt/baz scratch/foo/qux bfs_diff -L scratch -xdev -ret=$? - -sudo umount scratch/mnt -return $ret diff --git a/tests/posix/depth_error.sh b/tests/posix/depth_error.sh index f770210..15cc82d 100644 --- a/tests/posix/depth_error.sh +++ b/tests/posix/depth_error.sh @@ -1,11 +1,7 @@ clean_scratch "$XTOUCH" -p scratch/foo/bar -chmod a-r scratch/foo - -bfs_diff scratch -depth -ret=$? -chmod +r scratch/foo -clean_scratch +chmod a-r scratch/foo +trap "chmod +r scratch/foo" EXIT -[ $ret -eq $EX_BFS ] +check_exit $EX_BFS bfs_diff scratch -depth diff --git a/tests/posix/exec_nonexistent.sh b/tests/posix/exec_nonexistent.sh index b4e08e0..d4ad92a 100644 --- a/tests/posix/exec_nonexistent.sh +++ b/tests/posix/exec_nonexistent.sh @@ -1,8 +1,7 @@ # Failure to execute the command should lead to an error message and # non-zero exit status. See https://unix.stackexchange.com/q/704522/56202 -stderr=$(invoke_bfs basic -exec "$TESTS/nonexistent" {} \; 2>&1 >/dev/null) -[ -n "$stderr" ] || return 1 +! stderr=$(invoke_bfs basic -exec "$TESTS/nonexistent" {} \; 2>&1 >/dev/null) +[ -n "$stderr" ] -bfs_diff basic -print -exec "$TESTS/nonexistent" {} \; -print -(($? == EX_BFS)) +check_exit $EX_BFS bfs_diff basic -print -exec "$TESTS/nonexistent" {} \; -print diff --git a/tests/posix/exec_plus_nonexistent.sh b/tests/posix/exec_plus_nonexistent.sh index f96099e..6c9cb8c 100644 --- a/tests/posix/exec_plus_nonexistent.sh +++ b/tests/posix/exec_plus_nonexistent.sh @@ -1,5 +1,4 @@ -stderr=$(invoke_bfs basic -exec "$TESTS/nonexistent" {} + 2>&1 >/dev/null) -[ -n "$stderr" ] || return 1 +! stderr=$(invoke_bfs basic -exec "$TESTS/nonexistent" {} + 2>&1 >/dev/null) +[ -n "$stderr" ] -bfs_diff basic -exec "$TESTS/nonexistent" {} + -print -(($? == EX_BFS)) +check_exit $EX_BFS bfs_diff basic -exec "$TESTS/nonexistent" {} + -print diff --git a/tests/posix/exec_plus_status.sh b/tests/posix/exec_plus_status.sh index ea9e5ef..f44062e 100644 --- a/tests/posix/exec_plus_status.sh +++ b/tests/posix/exec_plus_status.sh @@ -1,4 +1,3 @@ # -exec ... {} + should always return true, but if the command fails, bfs # should exit with a non-zero status -bfs_diff basic -exec false {} + -print -(($? == EX_BFS)) +check_exit $EX_BFS bfs_diff basic -exec false {} + -print diff --git a/tests/posix/readdir_error.sh b/tests/posix/readdir_error.sh index e45ec5c..9a002a1 100644 --- a/tests/posix/readdir_error.sh +++ b/tests/posix/readdir_error.sh @@ -29,7 +29,7 @@ kill -9 "$pid" # Wait until it's really a zombie state=R while [ "$state" != "Z" ]; do - read -r _ _ state _ <"/proc/$pid/stat" || exit 1 + read -r _ _ state _ <"/proc/$pid/stat" done # On Linux, open(/proc/$pid/net) will succeed but readdir() will fail diff --git a/tests/posix/type_bind_mount.sh b/tests/posix/type_bind_mount.sh index fe32875..2d913db 100644 --- a/tests/posix/type_bind_mount.sh +++ b/tests/posix/type_bind_mount.sh @@ -3,10 +3,8 @@ test "$UNAME" = "Linux" || skip clean_scratch "$XTOUCH" scratch/{file,null} + sudo mount --bind /dev/null scratch/null +trap "sudo umount scratch/null" EXIT bfs_diff scratch -type c -ret=$? - -sudo umount scratch/null -return $ret diff --git a/tests/posix/xdev.sh b/tests/posix/xdev.sh index 44e04dd..9d21b14 100644 --- a/tests/posix/xdev.sh +++ b/tests/posix/xdev.sh @@ -3,11 +3,10 @@ test "$UNAME" = "Darwin" && skip clean_scratch mkdir scratch/{foo,mnt} + sudo mount -t tmpfs tmpfs scratch/mnt +trap "sudo umount scratch/mnt" EXIT + "$XTOUCH" scratch/foo/bar scratch/mnt/baz bfs_diff scratch -xdev -ret=$? - -sudo umount scratch/mnt -return $ret diff --git a/tests/tests.sh b/tests/tests.sh index 844de5c..7ccd9b5 100755 --- a/tests/tests.sh +++ b/tests/tests.sh @@ -476,16 +476,24 @@ function bfs_verbose() { function invoke_bfs() { bfs_verbose "$@" "${BFS[@]}" "$@" - local status=$? + local status="$?" # Allow bfs to fail, but not crash if ((status > 125)); then - exit $status + exit "$status" else - return $status + return "$status" fi } +function check_exit() { + local expected="$1" + local actual="0" + shift + "$@" || actual="$?" + ((actual == expected)) +} + # Detect colored diff support if [ -t 2 ] && diff --color=always /dev/null /dev/null 2>/dev/null; then DIFF="diff --color=always" @@ -655,9 +663,9 @@ for TEST in "${TEST_CASES[@]}"; do mkdir -p "${OUT%/*}" if [ "$VERBOSE_ERRORS" ]; then - (. "$TESTS/$TEST.sh") + (set -e; . "$TESTS/$TEST.sh") else - (. "$TESTS/$TEST.sh") 2>"$TMP/stderr" + (set -e; . "$TESTS/$TEST.sh") 2>"$TMP/stderr" fi status=$? -- cgit v1.2.3 From e2b540c9e2a52500b17fa1005b26b2dd5a652c09 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Fri, 16 Dec 2022 16:43:25 -0500 Subject: tests: Fail early in bfs_diff if the diff fails Otherwise, propagate the exit code from bfs --- tests/bfs/execdir_plus_nonexistent.sh | 2 +- tests/bsd/X.sh | 2 +- tests/common/execdir_nonexistent.sh | 2 +- tests/gnu/L_loops_continue.sh | 2 +- tests/gnu/printf_Y_error.sh | 2 +- tests/posix/depth_error.sh | 2 +- tests/posix/exec_nonexistent.sh | 2 +- tests/posix/exec_plus_nonexistent.sh | 2 +- tests/posix/exec_plus_status.sh | 2 +- tests/tests.sh | 13 +++---------- 10 files changed, 12 insertions(+), 19 deletions(-) (limited to 'tests/gnu') diff --git a/tests/bfs/execdir_plus_nonexistent.sh b/tests/bfs/execdir_plus_nonexistent.sh index 88f3e90..e3b4d2d 100644 --- a/tests/bfs/execdir_plus_nonexistent.sh +++ b/tests/bfs/execdir_plus_nonexistent.sh @@ -1,4 +1,4 @@ ! stderr=$(invoke_bfs basic -execdir "$TESTS/nonexistent" {} + 2>&1 >/dev/null) [ -n "$stderr" ] -check_exit $EX_BFS bfs_diff basic -execdir "$TESTS/nonexistent" {} + -print +! bfs_diff basic -execdir "$TESTS/nonexistent" {} + -print diff --git a/tests/bsd/X.sh b/tests/bsd/X.sh index df9a261..54000cf 100644 --- a/tests/bsd/X.sh +++ b/tests/bsd/X.sh @@ -1 +1 @@ -check_exit $EX_BFS bfs_diff -X weirdnames +! bfs_diff -X weirdnames diff --git a/tests/common/execdir_nonexistent.sh b/tests/common/execdir_nonexistent.sh index af17fe5..4bb4fdb 100644 --- a/tests/common/execdir_nonexistent.sh +++ b/tests/common/execdir_nonexistent.sh @@ -1,4 +1,4 @@ ! stderr=$(invoke_bfs basic -execdir "$TESTS/nonexistent" {} \; 2>&1 >/dev/null) [ -n "$stderr" ] -check_exit $EX_BFS bfs_diff basic -print -execdir "$TESTS/nonexistent" {} \; -print +! bfs_diff basic -print -execdir "$TESTS/nonexistent" {} \; -print diff --git a/tests/gnu/L_loops_continue.sh b/tests/gnu/L_loops_continue.sh index d4c95f1..55aeb33 100644 --- a/tests/gnu/L_loops_continue.sh +++ b/tests/gnu/L_loops_continue.sh @@ -1 +1 @@ -check_exit $EX_BFS bfs_diff -L loops +! bfs_diff -L loops diff --git a/tests/gnu/printf_Y_error.sh b/tests/gnu/printf_Y_error.sh index e9a2083..3aa816e 100644 --- a/tests/gnu/printf_Y_error.sh +++ b/tests/gnu/printf_Y_error.sh @@ -5,4 +5,4 @@ ln -s foo/bar scratch/bar chmod -x scratch/foo trap "chmod +x scratch/foo" EXIT -check_exit $EX_BFS bfs_diff scratch -printf '(%p) (%l) %y %Y\n' +! bfs_diff scratch -printf '(%p) (%l) %y %Y\n' diff --git a/tests/posix/depth_error.sh b/tests/posix/depth_error.sh index 15cc82d..e91fbf6 100644 --- a/tests/posix/depth_error.sh +++ b/tests/posix/depth_error.sh @@ -4,4 +4,4 @@ clean_scratch chmod a-r scratch/foo trap "chmod +r scratch/foo" EXIT -check_exit $EX_BFS bfs_diff scratch -depth +! bfs_diff scratch -depth diff --git a/tests/posix/exec_nonexistent.sh b/tests/posix/exec_nonexistent.sh index d4ad92a..901be86 100644 --- a/tests/posix/exec_nonexistent.sh +++ b/tests/posix/exec_nonexistent.sh @@ -4,4 +4,4 @@ ! stderr=$(invoke_bfs basic -exec "$TESTS/nonexistent" {} \; 2>&1 >/dev/null) [ -n "$stderr" ] -check_exit $EX_BFS bfs_diff basic -print -exec "$TESTS/nonexistent" {} \; -print +! bfs_diff basic -print -exec "$TESTS/nonexistent" {} \; -print diff --git a/tests/posix/exec_plus_nonexistent.sh b/tests/posix/exec_plus_nonexistent.sh index 6c9cb8c..6bddc67 100644 --- a/tests/posix/exec_plus_nonexistent.sh +++ b/tests/posix/exec_plus_nonexistent.sh @@ -1,4 +1,4 @@ ! stderr=$(invoke_bfs basic -exec "$TESTS/nonexistent" {} + 2>&1 >/dev/null) [ -n "$stderr" ] -check_exit $EX_BFS bfs_diff basic -exec "$TESTS/nonexistent" {} + -print +! bfs_diff basic -exec "$TESTS/nonexistent" {} + -print diff --git a/tests/posix/exec_plus_status.sh b/tests/posix/exec_plus_status.sh index f44062e..a814c4e 100644 --- a/tests/posix/exec_plus_status.sh +++ b/tests/posix/exec_plus_status.sh @@ -1,3 +1,3 @@ # -exec ... {} + should always return true, but if the command fails, bfs # should exit with a non-zero status -check_exit $EX_BFS bfs_diff basic -exec false {} + -print +! bfs_diff basic -exec false {} + -print diff --git a/tests/tests.sh b/tests/tests.sh index 4a95fca..9bf9b8b 100755 --- a/tests/tests.sh +++ b/tests/tests.sh @@ -500,8 +500,6 @@ else DIFF="diff" fi -# Return value when bfs fails -EX_BFS=10 # Return value when a difference is detected EX_DIFF=20 # Return value when a test is skipped @@ -529,15 +527,10 @@ function bfs_diff() ( exec 3>&- "${BFS[@]}" "$@" | sort >"$OUT" - local STATUS="${PIPESTATUS[0]}" + local status="${PIPESTATUS[0]}" - diff_output || return $EX_DIFF - - if [ "$STATUS" -eq 0 ]; then - return 0 - else - return $EX_BFS - fi + diff_output || exit $EX_DIFF + return "$status" ) function skip() { -- cgit v1.2.3 From f92fa445c278ffa601b13b4ba98f35c8af16b761 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Fri, 16 Dec 2022 17:44:29 -0500 Subject: tests: New test for -fstype on a stacked mount point --- tests/gnu/fstype_stacked.out | 1 + tests/gnu/fstype_stacked.sh | 13 +++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 tests/gnu/fstype_stacked.out create mode 100644 tests/gnu/fstype_stacked.sh (limited to 'tests/gnu') diff --git a/tests/gnu/fstype_stacked.out b/tests/gnu/fstype_stacked.out new file mode 100644 index 0000000..99c7511 --- /dev/null +++ b/tests/gnu/fstype_stacked.out @@ -0,0 +1 @@ +scratch/mnt diff --git a/tests/gnu/fstype_stacked.sh b/tests/gnu/fstype_stacked.sh new file mode 100644 index 0000000..7110402 --- /dev/null +++ b/tests/gnu/fstype_stacked.sh @@ -0,0 +1,13 @@ +test "$SUDO" || skip +test "$UNAME" = "Linux" || skip + +clean_scratch +mkdir scratch/mnt + +sudo mount -t tmpfs tmpfs scratch/mnt +trap "sudo umount scratch/mnt" EXIT + +sudo mount -t ramfs ramfs scratch/mnt +trap "sudo umount scratch/mnt; sudo umount scratch/mnt" EXIT + +bfs_diff scratch/mnt -fstype ramfs -print -o -printf '%p: %F\n' -- cgit v1.2.3 From b6859d7a6f7e0b3a3cb70fa75e7e46998e8f0f03 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Thu, 29 Dec 2022 13:05:06 -0500 Subject: tests: Use bfs_sudo wrapper instead of testing $SUDO --- tests/bfs/L_capable.sh | 3 +-- tests/bfs/capable.sh | 3 +-- tests/common/L_mount.sh | 5 ++--- tests/common/inum_bind_mount.sh | 5 ++--- tests/common/inum_mount.sh | 5 ++--- tests/common/mount.sh | 5 ++--- tests/gnu/fstype_stacked.sh | 9 ++++----- tests/gnu/inum_automount.sh | 5 ++--- tests/gnu/xtype_bind_mount.sh | 5 ++--- tests/posix/L_xdev.sh | 5 ++--- tests/posix/type_bind_mount.sh | 5 ++--- tests/posix/xdev.sh | 5 ++--- tests/tests.sh | 40 +++++++++++++++++++++++++--------------- 13 files changed, 49 insertions(+), 51 deletions(-) (limited to 'tests/gnu') diff --git a/tests/bfs/L_capable.sh b/tests/bfs/L_capable.sh index a349677..232d6ac 100644 --- a/tests/bfs/L_capable.sh +++ b/tests/bfs/L_capable.sh @@ -1,4 +1,3 @@ -test "$SUDO" || skip test "$UNAME" = "Linux" || skip clean_scratch @@ -6,7 +5,7 @@ clean_scratch invoke_bfs scratch -quit -capable || skip "$XTOUCH" scratch/{normal,capable} -sudo setcap all+ep scratch/capable +bfs_sudo setcap all+ep scratch/capable || skip ln -s capable scratch/link bfs_diff -L scratch -capable diff --git a/tests/bfs/capable.sh b/tests/bfs/capable.sh index 8b60ea6..e5cad63 100644 --- a/tests/bfs/capable.sh +++ b/tests/bfs/capable.sh @@ -1,4 +1,3 @@ -test "$SUDO" || skip test "$UNAME" = "Linux" || skip clean_scratch @@ -6,7 +5,7 @@ clean_scratch invoke_bfs scratch -quit -capable || skip "$XTOUCH" scratch/{normal,capable} -sudo setcap all+ep scratch/capable +bfs_sudo setcap all+ep scratch/capable || skip ln -s capable scratch/link bfs_diff scratch -capable diff --git a/tests/common/L_mount.sh b/tests/common/L_mount.sh index 9ab785e..b04acd0 100644 --- a/tests/common/L_mount.sh +++ b/tests/common/L_mount.sh @@ -1,11 +1,10 @@ -test "$SUDO" || skip test "$UNAME" = "Darwin" && skip clean_scratch mkdir scratch/{foo,mnt} -sudo mount -t tmpfs tmpfs scratch/mnt -trap "sudo umount scratch/mnt" EXIT +bfs_sudo mount -t tmpfs tmpfs scratch/mnt || skip +trap "bfs_sudo umount scratch/mnt" EXIT ln -s ../mnt scratch/foo/bar "$XTOUCH" scratch/mnt/baz diff --git a/tests/common/inum_bind_mount.sh b/tests/common/inum_bind_mount.sh index 625ee3d..ecb4ec3 100644 --- a/tests/common/inum_bind_mount.sh +++ b/tests/common/inum_bind_mount.sh @@ -1,10 +1,9 @@ -test "$SUDO" || skip test "$UNAME" = "Linux" || skip clean_scratch "$XTOUCH" scratch/{foo,bar} -sudo mount --bind scratch/{foo,bar} -trap "sudo umount scratch/bar" EXIT +bfs_sudo mount --bind scratch/{foo,bar} || skip +trap "bfs_sudo umount scratch/bar" EXIT bfs_diff scratch -inum "$(inum scratch/bar)" diff --git a/tests/common/inum_mount.sh b/tests/common/inum_mount.sh index 91d06e2..a4832e4 100644 --- a/tests/common/inum_mount.sh +++ b/tests/common/inum_mount.sh @@ -1,10 +1,9 @@ -test "$SUDO" || skip test "$UNAME" = "Darwin" && skip clean_scratch mkdir scratch/{foo,mnt} -sudo mount -t tmpfs tmpfs scratch/mnt -trap "sudo umount scratch/mnt" EXIT +bfs_sudo mount -t tmpfs tmpfs scratch/mnt || skip +trap "bfs_sudo umount scratch/mnt" EXIT bfs_diff scratch -inum "$(inum scratch/mnt)" diff --git a/tests/common/mount.sh b/tests/common/mount.sh index 3f3ed38..b13b43c 100644 --- a/tests/common/mount.sh +++ b/tests/common/mount.sh @@ -1,11 +1,10 @@ -test "$SUDO" || skip test "$UNAME" = "Darwin" && skip clean_scratch mkdir scratch/{foo,mnt} -sudo mount -t tmpfs tmpfs scratch/mnt -trap "sudo umount scratch/mnt" EXIT +bfs_sudo mount -t tmpfs tmpfs scratch/mnt || skip +trap "bfs_sudo umount scratch/mnt" EXIT "$XTOUCH" scratch/foo/bar scratch/mnt/baz diff --git a/tests/gnu/fstype_stacked.sh b/tests/gnu/fstype_stacked.sh index 7110402..16f428f 100644 --- a/tests/gnu/fstype_stacked.sh +++ b/tests/gnu/fstype_stacked.sh @@ -1,13 +1,12 @@ -test "$SUDO" || skip test "$UNAME" = "Linux" || skip clean_scratch mkdir scratch/mnt -sudo mount -t tmpfs tmpfs scratch/mnt -trap "sudo umount scratch/mnt" EXIT +bfs_sudo mount -t tmpfs tmpfs scratch/mnt || skip +trap "bfs_sudo umount scratch/mnt" EXIT -sudo mount -t ramfs ramfs scratch/mnt -trap "sudo umount scratch/mnt; sudo umount scratch/mnt" EXIT +bfs_sudo mount -t ramfs ramfs scratch/mnt || skip +trap "bfs_sudo umount scratch/mnt; bfs_sudo umount scratch/mnt" EXIT bfs_diff scratch/mnt -fstype ramfs -print -o -printf '%p: %F\n' diff --git a/tests/gnu/inum_automount.sh b/tests/gnu/inum_automount.sh index da2e3b0..c4450ef 100644 --- a/tests/gnu/inum_automount.sh +++ b/tests/gnu/inum_automount.sh @@ -1,13 +1,12 @@ # bfs shouldn't trigger automounts unless it descends into them -test "$SUDO" || skip command -v systemd-mount &>/dev/null || skip clean_scratch mkdir scratch/{foo,automnt} -sudo systemd-mount -A -o bind basic scratch/automnt || skip -trap "sudo systemd-umount scratch/automnt" EXIT +bfs_sudo systemd-mount -A -o bind basic scratch/automnt || skip +trap "bfs_sudo systemd-umount scratch/automnt" EXIT before=$(inum scratch/automnt) bfs_diff scratch -inum "$before" -prune diff --git a/tests/gnu/xtype_bind_mount.sh b/tests/gnu/xtype_bind_mount.sh index 9babd9d..99a11ab 100644 --- a/tests/gnu/xtype_bind_mount.sh +++ b/tests/gnu/xtype_bind_mount.sh @@ -1,11 +1,10 @@ -test "$SUDO" || skip test "$UNAME" = "Linux" || skip clean_scratch "$XTOUCH" scratch/{file,null} ln -s /dev/null scratch/link -sudo mount --bind /dev/null scratch/null -trap "sudo umount scratch/null" EXIT +bfs_sudo mount --bind /dev/null scratch/null || skip +trap "bfs_sudo umount scratch/null" EXIT bfs_diff -L scratch -type c diff --git a/tests/posix/L_xdev.sh b/tests/posix/L_xdev.sh index 587c8bb..172ea23 100644 --- a/tests/posix/L_xdev.sh +++ b/tests/posix/L_xdev.sh @@ -1,11 +1,10 @@ -test "$SUDO" || skip test "$UNAME" = "Darwin" && skip clean_scratch mkdir scratch/{foo,mnt} -sudo mount -t tmpfs tmpfs scratch/mnt -trap "sudo umount scratch/mnt" EXIT +bfs_sudo mount -t tmpfs tmpfs scratch/mnt || skip +trap "bfs_sudo umount scratch/mnt" EXIT ln -s ../mnt scratch/foo/bar "$XTOUCH" scratch/mnt/baz diff --git a/tests/posix/type_bind_mount.sh b/tests/posix/type_bind_mount.sh index 2d913db..c9a161d 100644 --- a/tests/posix/type_bind_mount.sh +++ b/tests/posix/type_bind_mount.sh @@ -1,10 +1,9 @@ -test "$SUDO" || skip test "$UNAME" = "Linux" || skip clean_scratch "$XTOUCH" scratch/{file,null} -sudo mount --bind /dev/null scratch/null -trap "sudo umount scratch/null" EXIT +bfs_sudo mount --bind /dev/null scratch/null || skip +trap "bfs_sudo umount scratch/null" EXIT bfs_diff scratch -type c diff --git a/tests/posix/xdev.sh b/tests/posix/xdev.sh index 9d21b14..33412bf 100644 --- a/tests/posix/xdev.sh +++ b/tests/posix/xdev.sh @@ -1,11 +1,10 @@ -test "$SUDO" || skip test "$UNAME" = "Darwin" && skip clean_scratch mkdir scratch/{foo,mnt} -sudo mount -t tmpfs tmpfs scratch/mnt -trap "sudo umount scratch/mnt" EXIT +bfs_sudo mount -t tmpfs tmpfs scratch/mnt || skip +trap "bfs_sudo umount scratch/mnt" EXIT "$XTOUCH" scratch/foo/bar scratch/mnt/baz diff --git a/tests/tests.sh b/tests/tests.sh index 962a2cf..e57db4e 100755 --- a/tests/tests.sh +++ b/tests/tests.sh @@ -101,18 +101,15 @@ fi function usage() { local pad=$(printf "%*s" ${#0} "") cat </dev/null; then + if ((${#SUDO[@]})) && command -v mountpoint &>/dev/null; then for path in "$TMP"/scratch/*; do if mountpoint -q "$path"; then sudo umount "$path" @@ -608,10 +619,9 @@ function make_xattrs() { *) # Linux tmpfs doesn't support the user.* namespace, so we use the security.* # namespace, which is writable by root and readable by others - [ "$SUDO" ] \ - && sudo setfattr -n security.bfs_test scratch/xattr \ - && sudo setfattr -n security.bfs_test_2 scratch/xattr_2 \ - && sudo setfattr -h -n security.bfs_test scratch/xattr_link + bfs_sudo setfattr -n security.bfs_test scratch/xattr \ + && bfs_sudo setfattr -n security.bfs_test_2 scratch/xattr_2 \ + && bfs_sudo setfattr -h -n security.bfs_test scratch/xattr_link ;; esac } -- cgit v1.2.3 From 869e4010433c8610ba59f9a6a310df8be228d718 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Sun, 22 Jan 2023 14:21:36 -0500 Subject: mtab: Mitigate the race between bfs_mtab_parse() and bfs_mtab_fill_types() Fixes #97. --- src/mtab.c | 37 +++++++++++++++++++++++++++++++++++-- tests/gnu/fstype_umount.out | 0 tests/gnu/fstype_umount.sh | 12 ++++++++++++ 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 tests/gnu/fstype_umount.out create mode 100644 tests/gnu/fstype_umount.sh (limited to 'tests/gnu') diff --git a/src/mtab.c b/src/mtab.c index 39676e5..35ae51d 100644 --- a/src/mtab.c +++ b/src/mtab.c @@ -193,18 +193,51 @@ fail: } static void bfs_mtab_fill_types(struct bfs_mtab *mtab) { + const enum bfs_stat_flags flags = BFS_STAT_NOFOLLOW | BFS_STAT_NOSYNC; + for (size_t i = 0; i < darray_length(mtab->entries); ++i) { struct bfs_mtab_entry *entry = &mtab->entries[i]; + // It's possible that /path/to/mount was unmounted between bfs_mtab_parse() and bfs_mtab_fill_types(). + // In that case, the dev_t of /path/to/mount will be the same as /path/to, which should not get its + // fstype from the old mount record of /path/to/mount. + int fd = -1; + const char *path = entry->path; + char *dir = xdirname(path); + if (dir) { + fd = open(dir, O_SEARCH | O_CLOEXEC | O_DIRECTORY); + } + if (fd >= 0) { + path += xbaseoff(path); + } else { + fd = AT_FDCWD; + } + struct bfs_stat sb; - if (bfs_stat(AT_FDCWD, entry->path, BFS_STAT_NOFOLLOW | BFS_STAT_NOSYNC, &sb) != 0) { - continue; + if (bfs_stat(fd, path, flags, &sb) != 0) { + goto next; + } + + if (fd >= 0) { + struct bfs_stat parent; + if (bfs_stat(fd, NULL, flags, &parent) == 0) { + if (parent.dev == sb.dev) { + // Not a mount point any more (or a bind mount, but with the same fstype) + goto next; + } + } } struct trie_leaf *leaf = trie_insert_mem(&mtab->types, &sb.dev, sizeof(sb.dev)); if (leaf) { leaf->value = entry->type; } + + next: + free(dir); + if (fd >= 0) { + xclose(fd); + } } mtab->types_filled = true; diff --git a/tests/gnu/fstype_umount.out b/tests/gnu/fstype_umount.out new file mode 100644 index 0000000..e69de29 diff --git a/tests/gnu/fstype_umount.sh b/tests/gnu/fstype_umount.sh new file mode 100644 index 0000000..e817831 --- /dev/null +++ b/tests/gnu/fstype_umount.sh @@ -0,0 +1,12 @@ +test "$UNAME" = "Linux" || skip + +clean_scratch + +mkdir scratch/tmp +bfs_sudo mount -t tmpfs tmpfs scratch/tmp || skip +trap "bfs_sudo umount -R scratch/tmp" EXIT + +mkdir scratch/tmp/ram +bfs_sudo mount -t ramfs ramfs scratch/tmp/ram || skip + +bfs_diff scratch/tmp -path scratch/tmp -exec "${SUDO[@]}" umount scratch/tmp/ram \; , -fstype ramfs -print -- cgit v1.2.3 From 93749993508eaa9035dbcb005f960bc0b64752f0 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Thu, 22 Jun 2023 17:02:31 -0400 Subject: tests/gnu/printf_times: Correct %T@ to %A@ --- tests/gnu/printf_times.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/gnu') diff --git a/tests/gnu/printf_times.sh b/tests/gnu/printf_times.sh index d952620..e4f5155 100644 --- a/tests/gnu/printf_times.sh +++ b/tests/gnu/printf_times.sh @@ -1 +1 @@ -bfs_diff times -type f -printf '%p | %a %AY-%Am-%Ad %AH:%AI:%AS %T@ | %t %TY-%Tm-%Td %TH:%TI:%TS %T@\n' +bfs_diff times -type f -printf '%p | %a %AY-%Am-%Ad %AH:%AI:%AS %A@ | %t %TY-%Tm-%Td %TH:%TI:%TS %T@\n' -- cgit v1.2.3 From ec50b98d5584b0bb291a463a0c39905ce05acfe7 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Tue, 27 Jun 2023 12:07:14 -0400 Subject: tests/bfs/color: Add mixed-case extensions --- tests/bfs/color.out | 11 ++++++++--- tests/bfs/color_L.out | 11 ++++++++--- tests/bfs/color_L_ln_target.out | 11 ++++++++--- tests/bfs/color_L_no_stat.out | 11 ++++++++--- tests/bfs/color_cd0_no.out | 11 ++++++++--- tests/bfs/color_escapes.out | 11 ++++++++--- tests/bfs/color_ext.out | 11 ++++++++--- tests/bfs/color_ext0.out | 11 ++++++++--- tests/bfs/color_ext_override.out | 11 ++++++++--- tests/bfs/color_ext_underride.out | 11 ++++++++--- tests/bfs/color_fi0_no.out | 11 ++++++++--- tests/bfs/color_fi_no.out | 11 ++++++++--- tests/bfs/color_ln_target.out | 11 ++++++++--- tests/bfs/color_mh.out | 11 ++++++++--- tests/bfs/color_mh0.out | 11 ++++++++--- tests/bfs/color_mi.out | 11 ++++++++--- tests/bfs/color_missing_colon.out | 11 ++++++++--- tests/bfs/color_no.out | 11 ++++++++--- tests/bfs/color_no_stat.out | 11 ++++++++--- tests/bfs/color_or.out | 11 ++++++++--- tests/bfs/color_or0_mi.out | 11 ++++++++--- tests/bfs/color_or0_mi0.out | 11 ++++++++--- tests/bfs/color_or_mi.out | 11 ++++++++--- tests/bfs/color_or_mi0.out | 11 ++++++++--- tests/bfs/color_rs_lc_rc_ec.out | 11 ++++++++--- tests/bfs/color_st0_tw0_ow.out | 11 ++++++++--- tests/bfs/color_st0_tw0_ow0.out | 11 ++++++++--- tests/bfs/color_st0_tw_ow.out | 11 ++++++++--- tests/bfs/color_st0_tw_ow0.out | 11 ++++++++--- tests/bfs/color_st_tw0_ow.out | 11 ++++++++--- tests/bfs/color_st_tw0_ow0.out | 11 ++++++++--- tests/bfs/color_st_tw_ow0.out | 11 ++++++++--- tests/bfs/color_star.out | 11 ++++++++--- tests/bfs/color_su0_sg.out | 11 ++++++++--- tests/bfs/color_su0_sg0.out | 11 ++++++++--- tests/bfs/color_su_sg0.out | 11 ++++++++--- tests/bfs/nocolor.out | 11 ++++++++--- tests/bfs/printf_color.out | 11 ++++++++--- tests/gnu/empty_special.out | 11 ++++++++--- tests/tests.sh | 4 +++- 40 files changed, 315 insertions(+), 118 deletions(-) (limited to 'tests/gnu') diff --git a/tests/bfs/color.out b/tests/bfs/color.out index 77fc8a8..34c7153 100644 --- a/tests/bfs/color.out +++ b/tests/bfs/color.out @@ -13,8 +13,13 @@ rainbow/sticky rainbow/file.dat rainbow/file.txt +rainbow/lower.gz +rainbow/lower.tar +rainbow/lower.tar.gz +rainbow/lu.tar.GZ rainbow/mh1 rainbow/mh2 -rainbow/star.gz -rainbow/star.tar -rainbow/star.tar.gz +rainbow/ul.TAR.gz +rainbow/upper.GZ +rainbow/upper.TAR +rainbow/upper.TAR.GZ diff --git a/tests/bfs/color_L.out b/tests/bfs/color_L.out index b60dd4a..89f9410 100644 --- a/tests/bfs/color_L.out +++ b/tests/bfs/color_L.out @@ -13,8 +13,13 @@ rainbow/file.dat rainbow/file.txt rainbow/link.txt +rainbow/lower.gz +rainbow/lower.tar +rainbow/lower.tar.gz +rainbow/lu.tar.GZ rainbow/mh1 rainbow/mh2 -rainbow/star.gz -rainbow/star.tar -rainbow/star.tar.gz +rainbow/ul.TAR.gz +rainbow/upper.GZ +rainbow/upper.TAR +rainbow/upper.TAR.GZ diff --git a/tests/bfs/color_L_ln_target.out b/tests/bfs/color_L_ln_target.out index cd4ec5e..2562c98 100644 --- a/tests/bfs/color_L_ln_target.out +++ b/tests/bfs/color_L_ln_target.out @@ -13,8 +13,13 @@ rainbow/file.dat rainbow/file.txt rainbow/link.txt +rainbow/lower.gz +rainbow/lower.tar +rainbow/lower.tar.gz +rainbow/lu.tar.GZ rainbow/mh1 rainbow/mh2 -rainbow/star.gz -rainbow/star.tar -rainbow/star.tar.gz +rainbow/ul.TAR.gz +rainbow/upper.GZ +rainbow/upper.TAR +rainbow/upper.TAR.GZ diff --git a/tests/bfs/color_L_no_stat.out b/tests/bfs/color_L_no_stat.out index c0bb1be..4fe99c0 100644 --- a/tests/bfs/color_L_no_stat.out +++ b/tests/bfs/color_L_no_stat.out @@ -10,11 +10,16 @@ rainbow/pipe rainbow/exec.sh rainbow/file.dat +rainbow/lower.gz +rainbow/lower.tar +rainbow/lower.tar.gz +rainbow/lu.tar.GZ rainbow/mh1 rainbow/mh2 rainbow/sgid -rainbow/star.gz -rainbow/star.tar -rainbow/star.tar.gz rainbow/sugid rainbow/suid +rainbow/ul.TAR.gz +rainbow/upper.GZ +rainbow/upper.TAR +rainbow/upper.TAR.GZ diff --git a/tests/bfs/color_cd0_no.out b/tests/bfs/color_cd0_no.out index d5c98a9..30ad97f 100644 --- a/tests/bfs/color_cd0_no.out +++ b/tests/bfs/color_cd0_no.out @@ -5,11 +5,16 @@ rainbow/file.dat rainbow/file.txt rainbow/link.txt +rainbow/lower.gz +rainbow/lower.tar +rainbow/lower.tar.gz +rainbow/lu.tar.GZ rainbow/mh1 rainbow/mh2 -rainbow/star.gz -rainbow/star.tar -rainbow/star.tar.gz +rainbow/ul.TAR.gz +rainbow/upper.GZ +rainbow/upper.TAR +rainbow/upper.TAR.GZ rainbow/sticky_ow rainbow/sgid rainbow/pipe diff --git a/tests/bfs/color_escapes.out b/tests/bfs/color_escapes.out index b71e138..808585e 100644 --- a/tests/bfs/color_escapes.out +++ b/tests/bfs/color_escapes.out @@ -13,8 +13,13 @@ :rainbow/:sticky :rainbow/file.dat :rainbow/file.txt +:rainbow/lower.gz +:rainbow/lower.tar +:rainbow/lower.tar.gz +:rainbow/lu.tar.GZ :rainbow/mh1 :rainbow/mh2 -:rainbow/star.gz -:rainbow/star.tar -:rainbow/star.tar.gz +:rainbow/ul.TAR.gz +:rainbow/upper.GZ +:rainbow/upper.TAR +:rainbow/upper.TAR.GZ diff --git a/tests/bfs/color_ext.out b/tests/bfs/color_ext.out index cf26e73..be22b82 100644 --- a/tests/bfs/color_ext.out +++ b/tests/bfs/color_ext.out @@ -13,8 +13,13 @@ rainbow/suid rainbow/sticky rainbow/file.dat +rainbow/lower.gz +rainbow/lower.tar +rainbow/lower.tar.gz +rainbow/lu.tar.GZ rainbow/mh1 rainbow/mh2 -rainbow/star.gz -rainbow/star.tar -rainbow/star.tar.gz +rainbow/ul.TAR.gz +rainbow/upper.GZ +rainbow/upper.TAR +rainbow/upper.TAR.GZ diff --git a/tests/bfs/color_ext0.out b/tests/bfs/color_ext0.out index e764a6b..d151319 100644 --- a/tests/bfs/color_ext0.out +++ b/tests/bfs/color_ext0.out @@ -13,8 +13,13 @@ rainbow/suid rainbow/sticky rainbow/file.dat +rainbow/lower.gz +rainbow/lower.tar +rainbow/lower.tar.gz +rainbow/lu.tar.GZ rainbow/mh1 rainbow/mh2 -rainbow/star.gz -rainbow/star.tar -rainbow/star.tar.gz +rainbow/ul.TAR.gz +rainbow/upper.GZ +rainbow/upper.TAR +rainbow/upper.TAR.GZ diff --git a/tests/bfs/color_ext_override.out b/tests/bfs/color_ext_override.out index 1377b65..3a09cd2 100644 --- a/tests/bfs/color_ext_override.out +++ b/tests/bfs/color_ext_override.out @@ -1,8 +1,13 @@ rainbow rainbow/exec.sh -rainbow/star.tar -rainbow/star.gz -rainbow/star.tar.gz +rainbow/lower.tar +rainbow/upper.TAR +rainbow/lower.gz +rainbow/lower.tar.gz +rainbow/lu.tar.GZ +rainbow/ul.TAR.gz +rainbow/upper.GZ +rainbow/upper.TAR.GZ rainbow/socket rainbow/broken rainbow/chardev_link diff --git a/tests/bfs/color_ext_underride.out b/tests/bfs/color_ext_underride.out index 787248a..073d176 100644 --- a/tests/bfs/color_ext_underride.out +++ b/tests/bfs/color_ext_underride.out @@ -1,8 +1,13 @@ rainbow -rainbow/star.tar.gz +rainbow/lower.tar.gz +rainbow/lu.tar.GZ +rainbow/ul.TAR.gz +rainbow/upper.TAR.GZ rainbow/exec.sh -rainbow/star.tar -rainbow/star.gz +rainbow/lower.tar +rainbow/upper.TAR +rainbow/lower.gz +rainbow/upper.GZ rainbow/socket rainbow/broken rainbow/chardev_link diff --git a/tests/bfs/color_fi0_no.out b/tests/bfs/color_fi0_no.out index 77fc8a8..34c7153 100644 --- a/tests/bfs/color_fi0_no.out +++ b/tests/bfs/color_fi0_no.out @@ -13,8 +13,13 @@ rainbow/sticky rainbow/file.dat rainbow/file.txt +rainbow/lower.gz +rainbow/lower.tar +rainbow/lower.tar.gz +rainbow/lu.tar.GZ rainbow/mh1 rainbow/mh2 -rainbow/star.gz -rainbow/star.tar -rainbow/star.tar.gz +rainbow/ul.TAR.gz +rainbow/upper.GZ +rainbow/upper.TAR +rainbow/upper.TAR.GZ diff --git a/tests/bfs/color_fi_no.out b/tests/bfs/color_fi_no.out index 7162ded..8df9355 100644 --- a/tests/bfs/color_fi_no.out +++ b/tests/bfs/color_fi_no.out @@ -6,11 +6,16 @@ rainbow/link.txt rainbow/file.dat rainbow/file.txt +rainbow/lower.gz +rainbow/lower.tar +rainbow/lower.tar.gz +rainbow/lu.tar.GZ rainbow/mh1 rainbow/mh2 -rainbow/star.gz -rainbow/star.tar -rainbow/star.tar.gz +rainbow/ul.TAR.gz +rainbow/upper.GZ +rainbow/upper.TAR +rainbow/upper.TAR.GZ rainbow/sticky_ow rainbow/sgid rainbow/pipe diff --git a/tests/bfs/color_ln_target.out b/tests/bfs/color_ln_target.out index cd4ec5e..2562c98 100644 --- a/tests/bfs/color_ln_target.out +++ b/tests/bfs/color_ln_target.out @@ -13,8 +13,13 @@ rainbow/file.dat rainbow/file.txt rainbow/link.txt +rainbow/lower.gz +rainbow/lower.tar +rainbow/lower.tar.gz +rainbow/lu.tar.GZ rainbow/mh1 rainbow/mh2 -rainbow/star.gz -rainbow/star.tar -rainbow/star.tar.gz +rainbow/ul.TAR.gz +rainbow/upper.GZ +rainbow/upper.TAR +rainbow/upper.TAR.GZ diff --git a/tests/bfs/color_mh.out b/tests/bfs/color_mh.out index 757a6a1..7521b31 100644 --- a/tests/bfs/color_mh.out +++ b/tests/bfs/color_mh.out @@ -15,6 +15,11 @@ rainbow/sticky rainbow/file.dat rainbow/file.txt -rainbow/star.gz -rainbow/star.tar -rainbow/star.tar.gz +rainbow/lower.gz +rainbow/lower.tar +rainbow/lower.tar.gz +rainbow/lu.tar.GZ +rainbow/ul.TAR.gz +rainbow/upper.GZ +rainbow/upper.TAR +rainbow/upper.TAR.GZ diff --git a/tests/bfs/color_mh0.out b/tests/bfs/color_mh0.out index 77fc8a8..34c7153 100644 --- a/tests/bfs/color_mh0.out +++ b/tests/bfs/color_mh0.out @@ -13,8 +13,13 @@ rainbow/sticky rainbow/file.dat rainbow/file.txt +rainbow/lower.gz +rainbow/lower.tar +rainbow/lower.tar.gz +rainbow/lu.tar.GZ rainbow/mh1 rainbow/mh2 -rainbow/star.gz -rainbow/star.tar -rainbow/star.tar.gz +rainbow/ul.TAR.gz +rainbow/upper.GZ +rainbow/upper.TAR +rainbow/upper.TAR.GZ diff --git a/tests/bfs/color_mi.out b/tests/bfs/color_mi.out index 77fc8a8..34c7153 100644 --- a/tests/bfs/color_mi.out +++ b/tests/bfs/color_mi.out @@ -13,8 +13,13 @@ rainbow/sticky rainbow/file.dat rainbow/file.txt +rainbow/lower.gz +rainbow/lower.tar +rainbow/lower.tar.gz +rainbow/lu.tar.GZ rainbow/mh1 rainbow/mh2 -rainbow/star.gz -rainbow/star.tar -rainbow/star.tar.gz +rainbow/ul.TAR.gz +rainbow/upper.GZ +rainbow/upper.TAR +rainbow/upper.TAR.GZ diff --git a/tests/bfs/color_missing_colon.out b/tests/bfs/color_missing_colon.out index cf26e73..be22b82 100644 --- a/tests/bfs/color_missing_colon.out +++ b/tests/bfs/color_missing_colon.out @@ -13,8 +13,13 @@ rainbow/suid rainbow/sticky rainbow/file.dat +rainbow/lower.gz +rainbow/lower.tar +rainbow/lower.tar.gz +rainbow/lu.tar.GZ rainbow/mh1 rainbow/mh2 -rainbow/star.gz -rainbow/star.tar -rainbow/star.tar.gz +rainbow/ul.TAR.gz +rainbow/upper.GZ +rainbow/upper.TAR +rainbow/upper.TAR.GZ diff --git a/tests/bfs/color_no.out b/tests/bfs/color_no.out index 9f0dd66..b70e47d 100644 --- a/tests/bfs/color_no.out +++ b/tests/bfs/color_no.out @@ -6,11 +6,16 @@ rainbow/link.txt rainbow/file.dat rainbow/file.txt +rainbow/lower.gz +rainbow/lower.tar +rainbow/lower.tar.gz +rainbow/lu.tar.GZ rainbow/mh1 rainbow/mh2 -rainbow/star.gz -rainbow/star.tar -rainbow/star.tar.gz +rainbow/ul.TAR.gz +rainbow/upper.GZ +rainbow/upper.TAR +rainbow/upper.TAR.GZ rainbow/sticky_ow rainbow/sgid rainbow/pipe diff --git a/tests/bfs/color_no_stat.out b/tests/bfs/color_no_stat.out index 1fc5324..7d7d767 100644 --- a/tests/bfs/color_no_stat.out +++ b/tests/bfs/color_no_stat.out @@ -10,11 +10,16 @@ rainbow/pipe rainbow/exec.sh rainbow/file.dat +rainbow/lower.gz +rainbow/lower.tar +rainbow/lower.tar.gz +rainbow/lu.tar.GZ rainbow/mh1 rainbow/mh2 rainbow/sgid -rainbow/star.gz -rainbow/star.tar -rainbow/star.tar.gz rainbow/sugid rainbow/suid +rainbow/ul.TAR.gz +rainbow/upper.GZ +rainbow/upper.TAR +rainbow/upper.TAR.GZ diff --git a/tests/bfs/color_or.out b/tests/bfs/color_or.out index 9e1fe5c..98efb63 100644 --- a/tests/bfs/color_or.out +++ b/tests/bfs/color_or.out @@ -13,8 +13,13 @@ rainbow/sticky rainbow/file.dat rainbow/file.txt +rainbow/lower.gz +rainbow/lower.tar +rainbow/lower.tar.gz +rainbow/lu.tar.GZ rainbow/mh1 rainbow/mh2 -rainbow/star.gz -rainbow/star.tar -rainbow/star.tar.gz +rainbow/ul.TAR.gz +rainbow/upper.GZ +rainbow/upper.TAR +rainbow/upper.TAR.GZ diff --git a/tests/bfs/color_or0_mi.out b/tests/bfs/color_or0_mi.out index 77fc8a8..34c7153 100644 --- a/tests/bfs/color_or0_mi.out +++ b/tests/bfs/color_or0_mi.out @@ -13,8 +13,13 @@ rainbow/sticky rainbow/file.dat rainbow/file.txt +rainbow/lower.gz +rainbow/lower.tar +rainbow/lower.tar.gz +rainbow/lu.tar.GZ rainbow/mh1 rainbow/mh2 -rainbow/star.gz -rainbow/star.tar -rainbow/star.tar.gz +rainbow/ul.TAR.gz +rainbow/upper.GZ +rainbow/upper.TAR +rainbow/upper.TAR.GZ diff --git a/tests/bfs/color_or0_mi0.out b/tests/bfs/color_or0_mi0.out index 77fc8a8..34c7153 100644 --- a/tests/bfs/color_or0_mi0.out +++ b/tests/bfs/color_or0_mi0.out @@ -13,8 +13,13 @@ rainbow/sticky rainbow/file.dat rainbow/file.txt +rainbow/lower.gz +rainbow/lower.tar +rainbow/lower.tar.gz +rainbow/lu.tar.GZ rainbow/mh1 rainbow/mh2 -rainbow/star.gz -rainbow/star.tar -rainbow/star.tar.gz +rainbow/ul.TAR.gz +rainbow/upper.GZ +rainbow/upper.TAR +rainbow/upper.TAR.GZ diff --git a/tests/bfs/color_or_mi.out b/tests/bfs/color_or_mi.out index 5667f56..a9dc229 100644 --- a/tests/bfs/color_or_mi.out +++ b/tests/bfs/color_or_mi.out @@ -13,8 +13,13 @@ rainbow/sticky rainbow/file.dat rainbow/file.txt +rainbow/lower.gz +rainbow/lower.tar +rainbow/lower.tar.gz +rainbow/lu.tar.GZ rainbow/mh1 rainbow/mh2 -rainbow/star.gz -rainbow/star.tar -rainbow/star.tar.gz +rainbow/ul.TAR.gz +rainbow/upper.GZ +rainbow/upper.TAR +rainbow/upper.TAR.GZ diff --git a/tests/bfs/color_or_mi0.out b/tests/bfs/color_or_mi0.out index 5667f56..a9dc229 100644 --- a/tests/bfs/color_or_mi0.out +++ b/tests/bfs/color_or_mi0.out @@ -13,8 +13,13 @@ rainbow/sticky rainbow/file.dat rainbow/file.txt +rainbow/lower.gz +rainbow/lower.tar +rainbow/lower.tar.gz +rainbow/lu.tar.GZ rainbow/mh1 rainbow/mh2 -rainbow/star.gz -rainbow/star.tar -rainbow/star.tar.gz +rainbow/ul.TAR.gz +rainbow/upper.GZ +rainbow/upper.TAR +rainbow/upper.TAR.GZ diff --git a/tests/bfs/color_rs_lc_rc_ec.out b/tests/bfs/color_rs_lc_rc_ec.out index d39bbe7..82d94ec 100644 --- a/tests/bfs/color_rs_lc_rc_ec.out +++ b/tests/bfs/color_rs_lc_rc_ec.out @@ -12,9 +12,14 @@ LC01;34RCrainbow/ECLC37;41RCsuidEC LC01;34RCrainbow/ECLC37;44RCstickyEC LC01;34RCrainbow/ECfile.dat LC01;34RCrainbow/ECfile.txt +LC01;34RCrainbow/EClower.gz +LC01;34RCrainbow/EClower.tar +LC01;34RCrainbow/EClower.tar.gz +LC01;34RCrainbow/EClu.tar.GZ LC01;34RCrainbow/ECmh1 LC01;34RCrainbow/ECmh2 -LC01;34RCrainbow/ECstar.gz -LC01;34RCrainbow/ECstar.tar -LC01;34RCrainbow/ECstar.tar.gz +LC01;34RCrainbow/ECul.TAR.gz +LC01;34RCrainbow/ECupper.GZ +LC01;34RCrainbow/ECupper.TAR +LC01;34RCrainbow/ECupper.TAR.GZ LC01;34RCrainbowEC diff --git a/tests/bfs/color_st0_tw0_ow.out b/tests/bfs/color_st0_tw0_ow.out index 9a47ef2..bdc5942 100644 --- a/tests/bfs/color_st0_tw0_ow.out +++ b/tests/bfs/color_st0_tw0_ow.out @@ -13,8 +13,13 @@ rainbow/suid rainbow/file.dat rainbow/file.txt +rainbow/lower.gz +rainbow/lower.tar +rainbow/lower.tar.gz +rainbow/lu.tar.GZ rainbow/mh1 rainbow/mh2 -rainbow/star.gz -rainbow/star.tar -rainbow/star.tar.gz +rainbow/ul.TAR.gz +rainbow/upper.GZ +rainbow/upper.TAR +rainbow/upper.TAR.GZ diff --git a/tests/bfs/color_st0_tw0_ow0.out b/tests/bfs/color_st0_tw0_ow0.out index 2b86fe4..f13b7f3 100644 --- a/tests/bfs/color_st0_tw0_ow0.out +++ b/tests/bfs/color_st0_tw0_ow0.out @@ -13,8 +13,13 @@ rainbow/suid rainbow/file.dat rainbow/file.txt +rainbow/lower.gz +rainbow/lower.tar +rainbow/lower.tar.gz +rainbow/lu.tar.GZ rainbow/mh1 rainbow/mh2 -rainbow/star.gz -rainbow/star.tar -rainbow/star.tar.gz +rainbow/ul.TAR.gz +rainbow/upper.GZ +rainbow/upper.TAR +rainbow/upper.TAR.GZ diff --git a/tests/bfs/color_st0_tw_ow.out b/tests/bfs/color_st0_tw_ow.out index 42549a1..2d7f682 100644 --- a/tests/bfs/color_st0_tw_ow.out +++ b/tests/bfs/color_st0_tw_ow.out @@ -13,8 +13,13 @@ rainbow/sticky_ow rainbow/file.dat rainbow/file.txt +rainbow/lower.gz +rainbow/lower.tar +rainbow/lower.tar.gz +rainbow/lu.tar.GZ rainbow/mh1 rainbow/mh2 -rainbow/star.gz -rainbow/star.tar -rainbow/star.tar.gz +rainbow/ul.TAR.gz +rainbow/upper.GZ +rainbow/upper.TAR +rainbow/upper.TAR.GZ diff --git a/tests/bfs/color_st0_tw_ow0.out b/tests/bfs/color_st0_tw_ow0.out index 535b8ae..7e343b8 100644 --- a/tests/bfs/color_st0_tw_ow0.out +++ b/tests/bfs/color_st0_tw_ow0.out @@ -13,8 +13,13 @@ rainbow/sticky_ow rainbow/file.dat rainbow/file.txt +rainbow/lower.gz +rainbow/lower.tar +rainbow/lower.tar.gz +rainbow/lu.tar.GZ rainbow/mh1 rainbow/mh2 -rainbow/star.gz -rainbow/star.tar -rainbow/star.tar.gz +rainbow/ul.TAR.gz +rainbow/upper.GZ +rainbow/upper.TAR +rainbow/upper.TAR.GZ diff --git a/tests/bfs/color_st_tw0_ow.out b/tests/bfs/color_st_tw0_ow.out index c9a86f4..c61a327 100644 --- a/tests/bfs/color_st_tw0_ow.out +++ b/tests/bfs/color_st_tw0_ow.out @@ -13,8 +13,13 @@ rainbow/sticky rainbow/file.dat rainbow/file.txt +rainbow/lower.gz +rainbow/lower.tar +rainbow/lower.tar.gz +rainbow/lu.tar.GZ rainbow/mh1 rainbow/mh2 -rainbow/star.gz -rainbow/star.tar -rainbow/star.tar.gz +rainbow/ul.TAR.gz +rainbow/upper.GZ +rainbow/upper.TAR +rainbow/upper.TAR.GZ diff --git a/tests/bfs/color_st_tw0_ow0.out b/tests/bfs/color_st_tw0_ow0.out index 2d94f3a..929a993 100644 --- a/tests/bfs/color_st_tw0_ow0.out +++ b/tests/bfs/color_st_tw0_ow0.out @@ -13,8 +13,13 @@ rainbow/sticky_ow rainbow/file.dat rainbow/file.txt +rainbow/lower.gz +rainbow/lower.tar +rainbow/lower.tar.gz +rainbow/lu.tar.GZ rainbow/mh1 rainbow/mh2 -rainbow/star.gz -rainbow/star.tar -rainbow/star.tar.gz +rainbow/ul.TAR.gz +rainbow/upper.GZ +rainbow/upper.TAR +rainbow/upper.TAR.GZ diff --git a/tests/bfs/color_st_tw_ow0.out b/tests/bfs/color_st_tw_ow0.out index 317ef90..7092f5a 100644 --- a/tests/bfs/color_st_tw_ow0.out +++ b/tests/bfs/color_st_tw_ow0.out @@ -13,8 +13,13 @@ rainbow/sticky_ow rainbow/file.dat rainbow/file.txt +rainbow/lower.gz +rainbow/lower.tar +rainbow/lower.tar.gz +rainbow/lu.tar.GZ rainbow/mh1 rainbow/mh2 -rainbow/star.gz -rainbow/star.tar -rainbow/star.tar.gz +rainbow/ul.TAR.gz +rainbow/upper.GZ +rainbow/upper.TAR +rainbow/upper.TAR.GZ diff --git a/tests/bfs/color_star.out b/tests/bfs/color_star.out index 77fc8a8..34c7153 100644 --- a/tests/bfs/color_star.out +++ b/tests/bfs/color_star.out @@ -13,8 +13,13 @@ rainbow/sticky rainbow/file.dat rainbow/file.txt +rainbow/lower.gz +rainbow/lower.tar +rainbow/lower.tar.gz +rainbow/lu.tar.GZ rainbow/mh1 rainbow/mh2 -rainbow/star.gz -rainbow/star.tar -rainbow/star.tar.gz +rainbow/ul.TAR.gz +rainbow/upper.GZ +rainbow/upper.TAR +rainbow/upper.TAR.GZ diff --git a/tests/bfs/color_su0_sg.out b/tests/bfs/color_su0_sg.out index 8b8c8b8..2bce534 100644 --- a/tests/bfs/color_su0_sg.out +++ b/tests/bfs/color_su0_sg.out @@ -12,9 +12,14 @@ rainbow/sticky rainbow/file.dat rainbow/file.txt +rainbow/lower.gz +rainbow/lower.tar +rainbow/lower.tar.gz +rainbow/lu.tar.GZ rainbow/mh1 rainbow/mh2 -rainbow/star.gz -rainbow/star.tar -rainbow/star.tar.gz rainbow/suid +rainbow/ul.TAR.gz +rainbow/upper.GZ +rainbow/upper.TAR +rainbow/upper.TAR.GZ diff --git a/tests/bfs/color_su0_sg0.out b/tests/bfs/color_su0_sg0.out index 0cd5f9a..0c3d757 100644 --- a/tests/bfs/color_su0_sg0.out +++ b/tests/bfs/color_su0_sg0.out @@ -10,11 +10,16 @@ rainbow/sticky rainbow/file.dat rainbow/file.txt +rainbow/lower.gz +rainbow/lower.tar +rainbow/lower.tar.gz +rainbow/lu.tar.GZ rainbow/mh1 rainbow/mh2 rainbow/sgid -rainbow/star.gz -rainbow/star.tar -rainbow/star.tar.gz rainbow/sugid rainbow/suid +rainbow/ul.TAR.gz +rainbow/upper.GZ +rainbow/upper.TAR +rainbow/upper.TAR.GZ diff --git a/tests/bfs/color_su_sg0.out b/tests/bfs/color_su_sg0.out index a9e8c5d..7a70598 100644 --- a/tests/bfs/color_su_sg0.out +++ b/tests/bfs/color_su_sg0.out @@ -12,9 +12,14 @@ rainbow/sticky rainbow/file.dat rainbow/file.txt +rainbow/lower.gz +rainbow/lower.tar +rainbow/lower.tar.gz +rainbow/lu.tar.GZ rainbow/mh1 rainbow/mh2 rainbow/sgid -rainbow/star.gz -rainbow/star.tar -rainbow/star.tar.gz +rainbow/ul.TAR.gz +rainbow/upper.GZ +rainbow/upper.TAR +rainbow/upper.TAR.GZ diff --git a/tests/bfs/nocolor.out b/tests/bfs/nocolor.out index b53fe03..29e7de8 100644 --- a/tests/bfs/nocolor.out +++ b/tests/bfs/nocolor.out @@ -5,16 +5,21 @@ rainbow/exec.sh rainbow/file.dat rainbow/file.txt rainbow/link.txt +rainbow/lower.gz +rainbow/lower.tar +rainbow/lower.tar.gz +rainbow/lu.tar.GZ rainbow/mh1 rainbow/mh2 rainbow/ow rainbow/pipe rainbow/sgid rainbow/socket -rainbow/star.gz -rainbow/star.tar -rainbow/star.tar.gz rainbow/sticky rainbow/sticky_ow rainbow/sugid rainbow/suid +rainbow/ul.TAR.gz +rainbow/upper.GZ +rainbow/upper.TAR +rainbow/upper.TAR.GZ diff --git a/tests/bfs/printf_color.out b/tests/bfs/printf_color.out index d9cd1a4..0468f7d 100644 --- a/tests/bfs/printf_color.out +++ b/tests/bfs/printf_color.out @@ -13,8 +13,13 @@ . ./rainbow sticky ./rainbow/sticky rainbow/sticky . ./rainbow file.dat ./rainbow/file.dat rainbow/file.dat . ./rainbow file.txt ./rainbow/file.txt rainbow/file.txt +. ./rainbow lower.gz ./rainbow/lower.gz rainbow/lower.gz +. ./rainbow lower.tar ./rainbow/lower.tar rainbow/lower.tar +. ./rainbow lower.tar.gz ./rainbow/lower.tar.gz rainbow/lower.tar.gz +. ./rainbow lu.tar.GZ ./rainbow/lu.tar.GZ rainbow/lu.tar.GZ . ./rainbow mh1 ./rainbow/mh1 rainbow/mh1 . ./rainbow mh2 ./rainbow/mh2 rainbow/mh2 -. ./rainbow star.gz ./rainbow/star.gz rainbow/star.gz -. ./rainbow star.tar ./rainbow/star.tar rainbow/star.tar -. ./rainbow star.tar.gz ./rainbow/star.tar.gz rainbow/star.tar.gz +. ./rainbow ul.TAR.gz ./rainbow/ul.TAR.gz rainbow/ul.TAR.gz +. ./rainbow upper.GZ ./rainbow/upper.GZ rainbow/upper.GZ +. ./rainbow upper.TAR ./rainbow/upper.TAR rainbow/upper.TAR +. ./rainbow upper.TAR.GZ ./rainbow/upper.TAR.GZ rainbow/upper.TAR.GZ diff --git a/tests/gnu/empty_special.out b/tests/gnu/empty_special.out index 3927f2b..3aa57d2 100644 --- a/tests/gnu/empty_special.out +++ b/tests/gnu/empty_special.out @@ -1,14 +1,19 @@ rainbow/exec.sh rainbow/file.dat rainbow/file.txt +rainbow/lower.gz +rainbow/lower.tar +rainbow/lower.tar.gz +rainbow/lu.tar.GZ rainbow/mh1 rainbow/mh2 rainbow/ow rainbow/sgid -rainbow/star.gz -rainbow/star.tar -rainbow/star.tar.gz rainbow/sticky rainbow/sticky_ow rainbow/sugid rainbow/suid +rainbow/ul.TAR.gz +rainbow/upper.GZ +rainbow/upper.TAR +rainbow/upper.TAR.GZ diff --git a/tests/tests.sh b/tests/tests.sh index 9265481..46e3e33 100755 --- a/tests/tests.sh +++ b/tests/tests.sh @@ -413,7 +413,9 @@ make_deep "$TMP/deep" function make_rainbow() { "$XTOUCH" -p "$1/file.txt" "$XTOUCH" -p "$1/file.dat" - "$XTOUCH" -p "$1/star".{gz,tar,tar.gz} + "$XTOUCH" -p "$1/lower".{gz,tar,tar.gz} + "$XTOUCH" -p "$1/upper".{GZ,TAR,TAR.GZ} + "$XTOUCH" -p "$1/lu.tar.GZ" "$1/ul.TAR.gz" ln -s file.txt "$1/link.txt" "$XTOUCH" -p "$1/mh1" ln "$1/mh1" "$1/mh2" -- cgit v1.2.3 From c5a2bfd924445dfccd943ea34374a5d1266f5cb9 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Thu, 13 Jul 2023 15:22:42 -0400 Subject: color: TTY-escape filenames --- src/color.c | 10 +++++++++- src/color.h | 1 + src/printf.c | 4 ++-- tests/bfs/color.out | 2 ++ tests/bfs/color_L.out | 2 ++ tests/bfs/color_L_ln_target.out | 2 ++ tests/bfs/color_L_no_stat.out | 2 ++ tests/bfs/color_cd0_no.out | 2 ++ tests/bfs/color_escapes.out | 2 ++ tests/bfs/color_ext.out | 2 ++ tests/bfs/color_ext0.out | 2 ++ tests/bfs/color_ext_case.out | 2 ++ tests/bfs/color_ext_override.out | 2 ++ tests/bfs/color_ext_underride.out | 2 ++ tests/bfs/color_fi0_no.out | 2 ++ tests/bfs/color_fi_no.out | 2 ++ tests/bfs/color_ln_target.out | 2 ++ tests/bfs/color_mh.out | 2 ++ tests/bfs/color_mh0.out | 2 ++ tests/bfs/color_mi.out | 2 ++ tests/bfs/color_missing_colon.out | 2 ++ tests/bfs/color_no.out | 2 ++ tests/bfs/color_no_stat.out | 2 ++ tests/bfs/color_nul.out | 2 ++ tests/bfs/color_or.out | 2 ++ tests/bfs/color_or0_mi.out | 2 ++ tests/bfs/color_or0_mi0.out | 2 ++ tests/bfs/color_or_mi.out | 2 ++ tests/bfs/color_or_mi0.out | 2 ++ tests/bfs/color_rs_lc_rc_ec.out | 2 ++ tests/bfs/color_st0_tw0_ow.out | 2 ++ tests/bfs/color_st0_tw0_ow0.out | 2 ++ tests/bfs/color_st0_tw_ow.out | 2 ++ tests/bfs/color_st0_tw_ow0.out | 2 ++ tests/bfs/color_st_tw0_ow.out | 2 ++ tests/bfs/color_st_tw0_ow0.out | 2 ++ tests/bfs/color_st_tw_ow0.out | 2 ++ tests/bfs/color_su0_sg.out | 2 ++ tests/bfs/color_su0_sg0.out | 2 ++ tests/bfs/color_su_sg0.out | 2 ++ tests/bfs/nocolor.out | 2 ++ tests/gnu/empty_special.out | 1 + tests/tests.sh | 1 + 43 files changed, 90 insertions(+), 3 deletions(-) (limited to 'tests/gnu') diff --git a/src/color.c b/src/color.c index 00d7920..6593f5b 100644 --- a/src/color.c +++ b/src/color.c @@ -922,9 +922,12 @@ static int print_colored(CFILE *cfile, const struct esc_seq *esc, const char *st if (print_esc(cfile, esc) != 0) { return -1; } - if (dstrxcat(&cfile->buffer, str, len) != 0) { + + // Don't let the string itself interfere with the colors + if (print_wordesc(cfile, str, len, WESC_TTY) != 0) { return -1; } + if (print_reset(cfile) != 0) { return -1; } @@ -1242,6 +1245,11 @@ static int cvbuff(CFILE *cfile, const char *format, va_list args) { return -1; } break; + case 'Q': + if (print_wordesc(cfile, va_arg(args, const char *), SIZE_MAX, WESC_TTY) != 0) { + return -1; + } + break; case 'F': if (print_name(cfile, va_arg(args, const struct BFTW *)) != 0) { diff --git a/src/color.h b/src/color.h index 932d551..0d46c33 100644 --- a/src/color.h +++ b/src/color.h @@ -87,6 +87,7 @@ int cfclose(CFILE *cfile); * %zu: A size_t * %m: strerror(errno) * %pq: A shell-escaped string, like bash's printf %q + * %pQ: A TTY-escaped string. * %pF: A colored file name, from a const struct BFTW * argument * %pP: A colored file path, from a const struct BFTW * argument * %pL: A colored link target, from a const struct BFTW * argument diff --git a/src/printf.c b/src/printf.c index 6520d2d..f0910fa 100644 --- a/src/printf.c +++ b/src/printf.c @@ -298,7 +298,7 @@ static int bfs_printf_h(CFILE *cfile, const struct bfs_printf *directive, const int ret; if (should_color(cfile, directive)) { - ret = cfprintf(cfile, "${di}%s${rs}", buf); + ret = cfprintf(cfile, "${di}%pQ${rs}", buf); } else { ret = dyn_fprintf(cfile->file, directive, buf); } @@ -313,7 +313,7 @@ static int bfs_printf_H(CFILE *cfile, const struct bfs_printf *directive, const if (ftwbuf->depth == 0) { return cfprintf(cfile, "%pP", ftwbuf); } else { - return cfprintf(cfile, "${di}%s${rs}", ftwbuf->root); + return cfprintf(cfile, "${di}%pQ${rs}", ftwbuf->root); } } else { return dyn_fprintf(cfile->file, directive, ftwbuf->root); diff --git a/tests/bfs/color.out b/tests/bfs/color.out index 34c7153..5c6b43e 100644 --- a/tests/bfs/color.out +++ b/tests/bfs/color.out @@ -1,5 +1,7 @@ +$'rainbow/\e[1m/'$'\e[0m' rainbow rainbow/exec.sh +rainbow/$'\e[1m' rainbow/socket rainbow/broken rainbow/chardev_link diff --git a/tests/bfs/color_L.out b/tests/bfs/color_L.out index 89f9410..6904e39 100644 --- a/tests/bfs/color_L.out +++ b/tests/bfs/color_L.out @@ -1,6 +1,8 @@ +$'rainbow/\e[1m/'$'\e[0m' rainbow rainbow/exec.sh rainbow/chardev_link +rainbow/$'\e[1m' rainbow/socket rainbow/broken rainbow/sticky_ow diff --git a/tests/bfs/color_L_ln_target.out b/tests/bfs/color_L_ln_target.out index 2562c98..50105c3 100644 --- a/tests/bfs/color_L_ln_target.out +++ b/tests/bfs/color_L_ln_target.out @@ -1,7 +1,9 @@ +$'rainbow/\e[1m/'$'\e[0m' rainbow rainbow/broken rainbow/exec.sh rainbow/chardev_link +rainbow/$'\e[1m' rainbow/socket rainbow/sticky_ow rainbow/sgid diff --git a/tests/bfs/color_L_no_stat.out b/tests/bfs/color_L_no_stat.out index 4fe99c0..beb538c 100644 --- a/tests/bfs/color_L_no_stat.out +++ b/tests/bfs/color_L_no_stat.out @@ -1,5 +1,7 @@ +$'rainbow/\e[1m/'$'\e[0m' rainbow rainbow/chardev_link +rainbow/$'\e[1m' rainbow/ow rainbow/sticky rainbow/sticky_ow diff --git a/tests/bfs/color_cd0_no.out b/tests/bfs/color_cd0_no.out index 30ad97f..4d710fd 100644 --- a/tests/bfs/color_cd0_no.out +++ b/tests/bfs/color_cd0_no.out @@ -1,5 +1,7 @@ +$'rainbow/\e[1m/'$'\e[0m' rainbow rainbow/exec.sh +rainbow/$'\e[1m' rainbow/socket rainbow/broken rainbow/file.dat diff --git a/tests/bfs/color_escapes.out b/tests/bfs/color_escapes.out index 808585e..746a9ea 100644 --- a/tests/bfs/color_escapes.out +++ b/tests/bfs/color_escapes.out @@ -1,5 +1,7 @@ +:$'rainbow/\e[1m/'$'\e[0m' :rainbow :rainbow/:exec.sh +:rainbow/:$'\e[1m' :rainbow/:socket :rainbow/:broken :rainbow/:chardev_link diff --git a/tests/bfs/color_ext.out b/tests/bfs/color_ext.out index be22b82..a35ca0b 100644 --- a/tests/bfs/color_ext.out +++ b/tests/bfs/color_ext.out @@ -1,5 +1,7 @@ +$'rainbow/\e[1m/'$'\e[0m' rainbow rainbow/exec.sh +rainbow/$'\e[1m' rainbow/socket rainbow/broken rainbow/chardev_link diff --git a/tests/bfs/color_ext0.out b/tests/bfs/color_ext0.out index d151319..37301cc 100644 --- a/tests/bfs/color_ext0.out +++ b/tests/bfs/color_ext0.out @@ -1,6 +1,8 @@ +$'rainbow/\e[1m/'$'\e[0m' rainbow rainbow/file.txt rainbow/exec.sh +rainbow/$'\e[1m' rainbow/socket rainbow/broken rainbow/chardev_link diff --git a/tests/bfs/color_ext_case.out b/tests/bfs/color_ext_case.out index 4e7258d..9388343 100644 --- a/tests/bfs/color_ext_case.out +++ b/tests/bfs/color_ext_case.out @@ -1,3 +1,4 @@ +$'rainbow/\e[1m/'$'\e[0m' rainbow rainbow/lower.gz rainbow/lower.tar.gz @@ -6,6 +7,7 @@ rainbow/upper.TAR.GZ rainbow/lower.tar rainbow/upper.TAR +rainbow/$'\e[1m' rainbow/ul.TAR.gz rainbow/lu.tar.GZ rainbow/socket diff --git a/tests/bfs/color_ext_override.out b/tests/bfs/color_ext_override.out index 3a09cd2..1e0146c 100644 --- a/tests/bfs/color_ext_override.out +++ b/tests/bfs/color_ext_override.out @@ -1,3 +1,4 @@ +$'rainbow/\e[1m/'$'\e[0m' rainbow rainbow/exec.sh rainbow/lower.tar @@ -8,6 +9,7 @@ rainbow/ul.TAR.gz rainbow/upper.GZ rainbow/upper.TAR.GZ +rainbow/$'\e[1m' rainbow/socket rainbow/broken rainbow/chardev_link diff --git a/tests/bfs/color_ext_underride.out b/tests/bfs/color_ext_underride.out index 073d176..1ed66da 100644 --- a/tests/bfs/color_ext_underride.out +++ b/tests/bfs/color_ext_underride.out @@ -1,3 +1,4 @@ +$'rainbow/\e[1m/'$'\e[0m' rainbow rainbow/lower.tar.gz rainbow/lu.tar.GZ @@ -8,6 +9,7 @@ rainbow/upper.TAR rainbow/lower.gz rainbow/upper.GZ +rainbow/$'\e[1m' rainbow/socket rainbow/broken rainbow/chardev_link diff --git a/tests/bfs/color_fi0_no.out b/tests/bfs/color_fi0_no.out index 34c7153..5c6b43e 100644 --- a/tests/bfs/color_fi0_no.out +++ b/tests/bfs/color_fi0_no.out @@ -1,5 +1,7 @@ +$'rainbow/\e[1m/'$'\e[0m' rainbow rainbow/exec.sh +rainbow/$'\e[1m' rainbow/socket rainbow/broken rainbow/chardev_link diff --git a/tests/bfs/color_fi_no.out b/tests/bfs/color_fi_no.out index 8df9355..e64684d 100644 --- a/tests/bfs/color_fi_no.out +++ b/tests/bfs/color_fi_no.out @@ -1,5 +1,7 @@ +$'rainbow/\e[1m/'$'\e[0m' rainbow rainbow/exec.sh +rainbow/$'\e[1m' rainbow/socket rainbow/broken rainbow/chardev_link diff --git a/tests/bfs/color_ln_target.out b/tests/bfs/color_ln_target.out index 2562c98..50105c3 100644 --- a/tests/bfs/color_ln_target.out +++ b/tests/bfs/color_ln_target.out @@ -1,7 +1,9 @@ +$'rainbow/\e[1m/'$'\e[0m' rainbow rainbow/broken rainbow/exec.sh rainbow/chardev_link +rainbow/$'\e[1m' rainbow/socket rainbow/sticky_ow rainbow/sgid diff --git a/tests/bfs/color_mh.out b/tests/bfs/color_mh.out index 7521b31..93bfde1 100644 --- a/tests/bfs/color_mh.out +++ b/tests/bfs/color_mh.out @@ -1,5 +1,7 @@ +$'rainbow/\e[1m/'$'\e[0m' rainbow rainbow/exec.sh +rainbow/$'\e[1m' rainbow/socket rainbow/broken rainbow/chardev_link diff --git a/tests/bfs/color_mh0.out b/tests/bfs/color_mh0.out index 34c7153..5c6b43e 100644 --- a/tests/bfs/color_mh0.out +++ b/tests/bfs/color_mh0.out @@ -1,5 +1,7 @@ +$'rainbow/\e[1m/'$'\e[0m' rainbow rainbow/exec.sh +rainbow/$'\e[1m' rainbow/socket rainbow/broken rainbow/chardev_link diff --git a/tests/bfs/color_mi.out b/tests/bfs/color_mi.out index 34c7153..5c6b43e 100644 --- a/tests/bfs/color_mi.out +++ b/tests/bfs/color_mi.out @@ -1,5 +1,7 @@ +$'rainbow/\e[1m/'$'\e[0m' rainbow rainbow/exec.sh +rainbow/$'\e[1m' rainbow/socket rainbow/broken rainbow/chardev_link diff --git a/tests/bfs/color_missing_colon.out b/tests/bfs/color_missing_colon.out index be22b82..a35ca0b 100644 --- a/tests/bfs/color_missing_colon.out +++ b/tests/bfs/color_missing_colon.out @@ -1,5 +1,7 @@ +$'rainbow/\e[1m/'$'\e[0m' rainbow rainbow/exec.sh +rainbow/$'\e[1m' rainbow/socket rainbow/broken rainbow/chardev_link diff --git a/tests/bfs/color_no.out b/tests/bfs/color_no.out index b70e47d..c61d246 100644 --- a/tests/bfs/color_no.out +++ b/tests/bfs/color_no.out @@ -1,5 +1,7 @@ +$'rainbow/\e[1m/'$'\e[0m' rainbow rainbow/exec.sh +rainbow/$'\e[1m' rainbow/socket rainbow/broken rainbow/chardev_link diff --git a/tests/bfs/color_no_stat.out b/tests/bfs/color_no_stat.out index 7d7d767..e57e11a 100644 --- a/tests/bfs/color_no_stat.out +++ b/tests/bfs/color_no_stat.out @@ -1,4 +1,6 @@ +$'rainbow/\e[1m/'$'\e[0m' rainbow +rainbow/$'\e[1m' rainbow/ow rainbow/sticky rainbow/sticky_ow diff --git a/tests/bfs/color_nul.out b/tests/bfs/color_nul.out index 4ea4d85..7140e32 100644 --- a/tests/bfs/color_nul.out +++ b/tests/bfs/color_nul.out @@ -1,3 +1,4 @@ +$'rainbow/\e[1m/'$'\e[0m' rainbow rainbow/lower.gz rainbow/lower.tar.gz @@ -6,6 +7,7 @@ rainbow/upper.GZ rainbow/upper.TAR.GZ rainbow/exec.sh +rainbow/$'\e[1m' rainbow/socket rainbow/broken rainbow/chardev_link diff --git a/tests/bfs/color_or.out b/tests/bfs/color_or.out index 98efb63..07916da 100644 --- a/tests/bfs/color_or.out +++ b/tests/bfs/color_or.out @@ -1,5 +1,7 @@ +$'rainbow/\e[1m/'$'\e[0m' rainbow rainbow/exec.sh +rainbow/$'\e[1m' rainbow/socket rainbow/chardev_link rainbow/link.txt diff --git a/tests/bfs/color_or0_mi.out b/tests/bfs/color_or0_mi.out index 34c7153..5c6b43e 100644 --- a/tests/bfs/color_or0_mi.out +++ b/tests/bfs/color_or0_mi.out @@ -1,5 +1,7 @@ +$'rainbow/\e[1m/'$'\e[0m' rainbow rainbow/exec.sh +rainbow/$'\e[1m' rainbow/socket rainbow/broken rainbow/chardev_link diff --git a/tests/bfs/color_or0_mi0.out b/tests/bfs/color_or0_mi0.out index 34c7153..5c6b43e 100644 --- a/tests/bfs/color_or0_mi0.out +++ b/tests/bfs/color_or0_mi0.out @@ -1,5 +1,7 @@ +$'rainbow/\e[1m/'$'\e[0m' rainbow rainbow/exec.sh +rainbow/$'\e[1m' rainbow/socket rainbow/broken rainbow/chardev_link diff --git a/tests/bfs/color_or_mi.out b/tests/bfs/color_or_mi.out index a9dc229..20bc61d 100644 --- a/tests/bfs/color_or_mi.out +++ b/tests/bfs/color_or_mi.out @@ -1,6 +1,8 @@ +$'rainbow/\e[1m/'$'\e[0m' rainbow rainbow/broken rainbow/exec.sh +rainbow/$'\e[1m' rainbow/socket rainbow/chardev_link rainbow/link.txt diff --git a/tests/bfs/color_or_mi0.out b/tests/bfs/color_or_mi0.out index a9dc229..20bc61d 100644 --- a/tests/bfs/color_or_mi0.out +++ b/tests/bfs/color_or_mi0.out @@ -1,6 +1,8 @@ +$'rainbow/\e[1m/'$'\e[0m' rainbow rainbow/broken rainbow/exec.sh +rainbow/$'\e[1m' rainbow/socket rainbow/chardev_link rainbow/link.txt diff --git a/tests/bfs/color_rs_lc_rc_ec.out b/tests/bfs/color_rs_lc_rc_ec.out index 82d94ec..f78b41f 100644 --- a/tests/bfs/color_rs_lc_rc_ec.out +++ b/tests/bfs/color_rs_lc_rc_ec.out @@ -1,4 +1,6 @@ +LC01;34RC$'rainbow/\e[1m/'EC$'\e[0m' LC01;34RCrainbow/ECLC01;32RCexec.shEC +LC01;34RCrainbow/ECLC01;34RC$'\e[1m'EC LC01;34RCrainbow/ECLC01;35RCsocketEC LC01;34RCrainbow/ECLC01;36RCbrokenEC LC01;34RCrainbow/ECLC01;36RCchardev_linkEC diff --git a/tests/bfs/color_st0_tw0_ow.out b/tests/bfs/color_st0_tw0_ow.out index bdc5942..d1fec74 100644 --- a/tests/bfs/color_st0_tw0_ow.out +++ b/tests/bfs/color_st0_tw0_ow.out @@ -1,5 +1,7 @@ +$'rainbow/\e[1m/'$'\e[0m' rainbow rainbow/exec.sh +rainbow/$'\e[1m' rainbow/sticky rainbow/socket rainbow/broken diff --git a/tests/bfs/color_st0_tw0_ow0.out b/tests/bfs/color_st0_tw0_ow0.out index f13b7f3..cb80cb8 100644 --- a/tests/bfs/color_st0_tw0_ow0.out +++ b/tests/bfs/color_st0_tw0_ow0.out @@ -1,5 +1,7 @@ +$'rainbow/\e[1m/'$'\e[0m' rainbow rainbow/exec.sh +rainbow/$'\e[1m' rainbow/ow rainbow/sticky rainbow/sticky_ow diff --git a/tests/bfs/color_st0_tw_ow.out b/tests/bfs/color_st0_tw_ow.out index 2d7f682..a183932 100644 --- a/tests/bfs/color_st0_tw_ow.out +++ b/tests/bfs/color_st0_tw_ow.out @@ -1,5 +1,7 @@ +$'rainbow/\e[1m/'$'\e[0m' rainbow rainbow/exec.sh +rainbow/$'\e[1m' rainbow/sticky rainbow/socket rainbow/broken diff --git a/tests/bfs/color_st0_tw_ow0.out b/tests/bfs/color_st0_tw_ow0.out index 7e343b8..cdc5cdd 100644 --- a/tests/bfs/color_st0_tw_ow0.out +++ b/tests/bfs/color_st0_tw_ow0.out @@ -1,5 +1,7 @@ +$'rainbow/\e[1m/'$'\e[0m' rainbow rainbow/exec.sh +rainbow/$'\e[1m' rainbow/ow rainbow/sticky rainbow/socket diff --git a/tests/bfs/color_st_tw0_ow.out b/tests/bfs/color_st_tw0_ow.out index c61a327..f45c75c 100644 --- a/tests/bfs/color_st_tw0_ow.out +++ b/tests/bfs/color_st_tw0_ow.out @@ -1,5 +1,7 @@ +$'rainbow/\e[1m/'$'\e[0m' rainbow rainbow/exec.sh +rainbow/$'\e[1m' rainbow/socket rainbow/broken rainbow/chardev_link diff --git a/tests/bfs/color_st_tw0_ow0.out b/tests/bfs/color_st_tw0_ow0.out index 929a993..d95d12a 100644 --- a/tests/bfs/color_st_tw0_ow0.out +++ b/tests/bfs/color_st_tw0_ow0.out @@ -1,5 +1,7 @@ +$'rainbow/\e[1m/'$'\e[0m' rainbow rainbow/exec.sh +rainbow/$'\e[1m' rainbow/ow rainbow/socket rainbow/broken diff --git a/tests/bfs/color_st_tw_ow0.out b/tests/bfs/color_st_tw_ow0.out index 7092f5a..f1059dd 100644 --- a/tests/bfs/color_st_tw_ow0.out +++ b/tests/bfs/color_st_tw_ow0.out @@ -1,5 +1,7 @@ +$'rainbow/\e[1m/'$'\e[0m' rainbow rainbow/exec.sh +rainbow/$'\e[1m' rainbow/ow rainbow/socket rainbow/broken diff --git a/tests/bfs/color_su0_sg.out b/tests/bfs/color_su0_sg.out index 2bce534..31d5108 100644 --- a/tests/bfs/color_su0_sg.out +++ b/tests/bfs/color_su0_sg.out @@ -1,5 +1,7 @@ +$'rainbow/\e[1m/'$'\e[0m' rainbow rainbow/exec.sh +rainbow/$'\e[1m' rainbow/socket rainbow/broken rainbow/chardev_link diff --git a/tests/bfs/color_su0_sg0.out b/tests/bfs/color_su0_sg0.out index 0c3d757..4804030 100644 --- a/tests/bfs/color_su0_sg0.out +++ b/tests/bfs/color_su0_sg0.out @@ -1,5 +1,7 @@ +$'rainbow/\e[1m/'$'\e[0m' rainbow rainbow/exec.sh +rainbow/$'\e[1m' rainbow/socket rainbow/broken rainbow/chardev_link diff --git a/tests/bfs/color_su_sg0.out b/tests/bfs/color_su_sg0.out index 7a70598..3dbc7fe 100644 --- a/tests/bfs/color_su_sg0.out +++ b/tests/bfs/color_su_sg0.out @@ -1,5 +1,7 @@ +$'rainbow/\e[1m/'$'\e[0m' rainbow rainbow/exec.sh +rainbow/$'\e[1m' rainbow/socket rainbow/broken rainbow/chardev_link diff --git a/tests/bfs/nocolor.out b/tests/bfs/nocolor.out index 29e7de8..d51d24d 100644 --- a/tests/bfs/nocolor.out +++ b/tests/bfs/nocolor.out @@ -1,4 +1,6 @@ rainbow +rainbow/ +rainbow// rainbow/broken rainbow/chardev_link rainbow/exec.sh diff --git a/tests/gnu/empty_special.out b/tests/gnu/empty_special.out index 3aa57d2..fa35478 100644 --- a/tests/gnu/empty_special.out +++ b/tests/gnu/empty_special.out @@ -1,3 +1,4 @@ +rainbow// rainbow/exec.sh rainbow/file.dat rainbow/file.txt diff --git a/tests/tests.sh b/tests/tests.sh index 46e3e33..66a79a8 100755 --- a/tests/tests.sh +++ b/tests/tests.sh @@ -432,6 +432,7 @@ function make_rainbow() { chmod +t "$1"/sticky* "$XTOUCH" -p "$1"/exec.sh chmod +x "$1"/exec.sh + "$XTOUCH" -p "$1/"$'\e[1m/\e[0m' } make_rainbow "$TMP/rainbow" -- cgit v1.2.3 From 92f0c513ba4e9119c5b6977366ce997151a44977 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Mon, 14 Aug 2023 15:59:04 -0400 Subject: parse: Allow -files0-from an empty set of paths This follows a behaviour change in GNU findutils 4.9.0. --- src/parse.c | 13 +++---------- tests/gnu/files0_from_none.sh | 2 +- 2 files changed, 4 insertions(+), 11 deletions(-) (limited to 'tests/gnu') diff --git a/src/parse.c b/src/parse.c index 6b1eaa0..37940de 100644 --- a/src/parse.c +++ b/src/parse.c @@ -194,8 +194,6 @@ struct parser_state { char **mount_arg; /** An "-xdev" argument, if any. */ char **xdev_arg; - /** A "-files0-from" argument, if any. */ - char **files0_arg; /** A "-files0-from -" argument, if any. */ char **files0_stdin_arg; /** An "-ok"-type expression, if any. */ @@ -1318,7 +1316,6 @@ static struct bfs_expr *parse_files0_from(struct parser_state *state, int arg1, return NULL; } - state->files0_arg = expr->argv; const char *from = expr->argv[1]; FILE *file; @@ -1350,7 +1347,7 @@ static struct bfs_expr *parse_files0_from(struct parser_state *state, int arg1, } if (file == stdin) { - state->files0_stdin_arg = state->files0_arg; + state->files0_stdin_arg = expr->argv; } else { fclose(file); } @@ -3720,7 +3717,6 @@ struct bfs_ctx *bfs_parse_cmdline(int argc, char *argv[]) { .prune_arg = NULL, .mount_arg = NULL, .xdev_arg = NULL, - .files0_arg = NULL, .files0_stdin_arg = NULL, .ok_expr = NULL, .now = ctx->now, @@ -3748,11 +3744,8 @@ struct bfs_ctx *bfs_parse_cmdline(int argc, char *argv[]) { goto fail; } - if (darray_length(ctx->paths) == 0) { - if (!state.implicit_root) { - parse_argv_error(&state, state.files0_arg, 2, "No root paths specified.\n"); - goto fail; - } else if (parse_root(&state, ".") != 0) { + if (darray_length(ctx->paths) == 0 && state.implicit_root) { + if (parse_root(&state, ".") != 0) { goto fail; } } diff --git a/tests/gnu/files0_from_none.sh b/tests/gnu/files0_from_none.sh index 090fce0..1633163 100644 --- a/tests/gnu/files0_from_none.sh +++ b/tests/gnu/files0_from_none.sh @@ -1 +1 @@ -! printf "" | invoke_bfs -files0-from - +printf "" | bfs_diff -files0-from - -- cgit v1.2.3 From b327e3813162e44e53805c307672dc8dc69eeb06 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Mon, 14 Aug 2023 16:05:35 -0400 Subject: tests: Add missing .out file --- tests/gnu/files0_from_none.out | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/gnu/files0_from_none.out (limited to 'tests/gnu') diff --git a/tests/gnu/files0_from_none.out b/tests/gnu/files0_from_none.out new file mode 100644 index 0000000..e69de29 -- cgit v1.2.3 From c78e5ddfc8aa0a6373b063dd787f416e9de8002e Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Thu, 19 Oct 2023 09:31:33 -0400 Subject: tests: New defer function --- tests/bsd/type_w.sh | 20 ++++---------------- tests/common/L_mount.sh | 2 +- tests/common/inum_bind_mount.sh | 2 +- tests/common/inum_mount.sh | 2 +- tests/common/mount.sh | 2 +- tests/gnu/fstype_stacked.sh | 4 ++-- tests/gnu/fstype_umount.sh | 2 +- tests/gnu/inum_automount.sh | 2 +- tests/gnu/printf_Y_error.sh | 2 +- tests/gnu/xtype_bind_mount.sh | 2 +- tests/posix/L_xdev.sh | 2 +- tests/posix/depth_error.sh | 2 +- tests/posix/overlayfs.sh | 6 +++++- tests/posix/readdir_error.sh | 2 +- tests/posix/type_bind_mount.sh | 2 +- tests/posix/unionfs.sh | 2 +- tests/posix/xdev.sh | 2 +- tests/tests.sh | 30 +++++++++++++++++++++++++++++- 18 files changed, 54 insertions(+), 34 deletions(-) (limited to 'tests/gnu') diff --git a/tests/bsd/type_w.sh b/tests/bsd/type_w.sh index d0cb58c..15b4e68 100644 --- a/tests/bsd/type_w.sh +++ b/tests/bsd/type_w.sh @@ -2,23 +2,12 @@ command -v mdconfig &>/dev/null || skip command -v newfs &>/dev/null || skip -cleanup=() -do_cleanup() { - # Run cleanup hooks in reverse order - while ((${#cleanup[@]} > 0)); do - cmd="${cleanup[-1]}" - unset 'cleanup[-1]' - eval "bfs_sudo $cmd" - done -} -trap do_cleanup EXIT - clean_scratch # Create a ramdisk truncate -s1M scratch/img md=$(bfs_sudo mdconfig scratch/img) || skip -cleanup+=("mdconfig -du $md") +defer bfs_sudo mdconfig -du "$md" # Make an ffs filesystem bfs_sudo newfs -n "/dev/$md" >&2 || skip @@ -26,7 +15,7 @@ mkdir scratch/mnt # Mount it bfs_sudo mount "/dev/$md" scratch/mnt || skip -cleanup+=("umount scratch/mnt") +defer bfs_sudo umount scratch/mnt # Make it owned by us bfs_sudo chown "$(id -u):$(id -g)" scratch/mnt @@ -34,7 +23,7 @@ bfs_sudo chown "$(id -u):$(id -g)" scratch/mnt # Mount a union filesystem within it bfs_sudo mount -t unionfs -o below scratch/mnt/{lower,upper} -cleanup+=("umount scratch/mnt/upper") +defer bfs_sudo umount scratch/mnt/upper # Create a whiteout rm scratch/mnt/upper/bar @@ -53,8 +42,7 @@ munge_ls() { # So this is not the same as test 1 invoke_bfs scratch/mnt \( -type w -or -not -type w \) -ls | munge_ls 3 # Unmount the unionfs - bfs_sudo umount scratch/mnt/upper - unset 'cleanup[-1]' + pop_defer # Now repeat the same tests invoke_bfs scratch/mnt -ls | munge_ls 4 invoke_bfs scratch/mnt -type w -ls | munge_ls 5 diff --git a/tests/common/L_mount.sh b/tests/common/L_mount.sh index b04acd0..aaf9069 100644 --- a/tests/common/L_mount.sh +++ b/tests/common/L_mount.sh @@ -4,7 +4,7 @@ clean_scratch mkdir scratch/{foo,mnt} bfs_sudo mount -t tmpfs tmpfs scratch/mnt || skip -trap "bfs_sudo umount scratch/mnt" EXIT +defer bfs_sudo umount scratch/mnt ln -s ../mnt scratch/foo/bar "$XTOUCH" scratch/mnt/baz diff --git a/tests/common/inum_bind_mount.sh b/tests/common/inum_bind_mount.sh index ecb4ec3..47f7c36 100644 --- a/tests/common/inum_bind_mount.sh +++ b/tests/common/inum_bind_mount.sh @@ -4,6 +4,6 @@ clean_scratch "$XTOUCH" scratch/{foo,bar} bfs_sudo mount --bind scratch/{foo,bar} || skip -trap "bfs_sudo umount scratch/bar" EXIT +defer bfs_sudo umount scratch/bar bfs_diff scratch -inum "$(inum scratch/bar)" diff --git a/tests/common/inum_mount.sh b/tests/common/inum_mount.sh index a4832e4..1bf2d86 100644 --- a/tests/common/inum_mount.sh +++ b/tests/common/inum_mount.sh @@ -4,6 +4,6 @@ clean_scratch mkdir scratch/{foo,mnt} bfs_sudo mount -t tmpfs tmpfs scratch/mnt || skip -trap "bfs_sudo umount scratch/mnt" EXIT +defer bfs_sudo umount scratch/mnt bfs_diff scratch -inum "$(inum scratch/mnt)" diff --git a/tests/common/mount.sh b/tests/common/mount.sh index b13b43c..db8b801 100644 --- a/tests/common/mount.sh +++ b/tests/common/mount.sh @@ -4,7 +4,7 @@ clean_scratch mkdir scratch/{foo,mnt} bfs_sudo mount -t tmpfs tmpfs scratch/mnt || skip -trap "bfs_sudo umount scratch/mnt" EXIT +defer bfs_sudo umount scratch/mnt "$XTOUCH" scratch/foo/bar scratch/mnt/baz diff --git a/tests/gnu/fstype_stacked.sh b/tests/gnu/fstype_stacked.sh index 16f428f..a4b067a 100644 --- a/tests/gnu/fstype_stacked.sh +++ b/tests/gnu/fstype_stacked.sh @@ -4,9 +4,9 @@ clean_scratch mkdir scratch/mnt bfs_sudo mount -t tmpfs tmpfs scratch/mnt || skip -trap "bfs_sudo umount scratch/mnt" EXIT +defer bfs_sudo umount scratch/mnt bfs_sudo mount -t ramfs ramfs scratch/mnt || skip -trap "bfs_sudo umount scratch/mnt; bfs_sudo umount scratch/mnt" EXIT +defer bfs_sudo umount scratch/mnt bfs_diff scratch/mnt -fstype ramfs -print -o -printf '%p: %F\n' diff --git a/tests/gnu/fstype_umount.sh b/tests/gnu/fstype_umount.sh index e817831..b6da7a3 100644 --- a/tests/gnu/fstype_umount.sh +++ b/tests/gnu/fstype_umount.sh @@ -4,7 +4,7 @@ clean_scratch mkdir scratch/tmp bfs_sudo mount -t tmpfs tmpfs scratch/tmp || skip -trap "bfs_sudo umount -R scratch/tmp" EXIT +defer bfs_sudo umount -R scratch/tmp mkdir scratch/tmp/ram bfs_sudo mount -t ramfs ramfs scratch/tmp/ram || skip diff --git a/tests/gnu/inum_automount.sh b/tests/gnu/inum_automount.sh index c4450ef..261a4be 100644 --- a/tests/gnu/inum_automount.sh +++ b/tests/gnu/inum_automount.sh @@ -6,7 +6,7 @@ clean_scratch mkdir scratch/{foo,automnt} bfs_sudo systemd-mount -A -o bind basic scratch/automnt || skip -trap "bfs_sudo systemd-umount scratch/automnt" EXIT +defer bfs_sudo systemd-umount scratch/automnt before=$(inum scratch/automnt) bfs_diff scratch -inum "$before" -prune diff --git a/tests/gnu/printf_Y_error.sh b/tests/gnu/printf_Y_error.sh index 3aa816e..13d52e3 100644 --- a/tests/gnu/printf_Y_error.sh +++ b/tests/gnu/printf_Y_error.sh @@ -3,6 +3,6 @@ mkdir scratch/foo ln -s foo/bar scratch/bar chmod -x scratch/foo -trap "chmod +x scratch/foo" EXIT +defer chmod +x scratch/foo ! bfs_diff scratch -printf '(%p) (%l) %y %Y\n' diff --git a/tests/gnu/xtype_bind_mount.sh b/tests/gnu/xtype_bind_mount.sh index 99a11ab..1cc20ec 100644 --- a/tests/gnu/xtype_bind_mount.sh +++ b/tests/gnu/xtype_bind_mount.sh @@ -5,6 +5,6 @@ clean_scratch ln -s /dev/null scratch/link bfs_sudo mount --bind /dev/null scratch/null || skip -trap "bfs_sudo umount scratch/null" EXIT +defer bfs_sudo umount scratch/null bfs_diff -L scratch -type c diff --git a/tests/posix/L_xdev.sh b/tests/posix/L_xdev.sh index 172ea23..d16c211 100644 --- a/tests/posix/L_xdev.sh +++ b/tests/posix/L_xdev.sh @@ -4,7 +4,7 @@ clean_scratch mkdir scratch/{foo,mnt} bfs_sudo mount -t tmpfs tmpfs scratch/mnt || skip -trap "bfs_sudo umount scratch/mnt" EXIT +defer bfs_sudo umount scratch/mnt ln -s ../mnt scratch/foo/bar "$XTOUCH" scratch/mnt/baz diff --git a/tests/posix/depth_error.sh b/tests/posix/depth_error.sh index e91fbf6..a6429d1 100644 --- a/tests/posix/depth_error.sh +++ b/tests/posix/depth_error.sh @@ -2,6 +2,6 @@ clean_scratch "$XTOUCH" -p scratch/foo/bar chmod a-r scratch/foo -trap "chmod +r scratch/foo" EXIT +defer chmod +r scratch/foo ! bfs_diff scratch -depth diff --git a/tests/posix/overlayfs.sh b/tests/posix/overlayfs.sh index a56b5b3..4cccebf 100644 --- a/tests/posix/overlayfs.sh +++ b/tests/posix/overlayfs.sh @@ -1,7 +1,11 @@ test "$UNAME" = "Linux" || skip + clean_scratch "$XTOUCH" -p scratch/{lower/{foo,bar,baz},upper/{bar,baz/qux}} + mkdir -p scratch/{work,merged} bfs_sudo mount -t overlay overlay -olowerdir=scratch/lower,upperdir=scratch/upper,workdir=scratch/work scratch/merged || skip -trap "bfs_sudo umount scratch/merged; bfs_sudo rm -rf scratch/work" EXIT +defer bfs_sudo rm -rf scratch/work +defer bfs_sudo umount scratch/merged + bfs_diff scratch/merged diff --git a/tests/posix/readdir_error.sh b/tests/posix/readdir_error.sh index 9a002a1..fc48eb1 100644 --- a/tests/posix/readdir_error.sh +++ b/tests/posix/readdir_error.sh @@ -13,7 +13,7 @@ mkfifo scratch/{fever,pid,wait,running} ) & # Kill the parent cat on exit -trap "kill -9 %1" EXIT +defer kill -9 %1 # Read the child PID read -r pid 0)); do + pop_defer || ret=$? + done + + return $ret +} + function bfs_sudo() { if ((${#SUDO[@]})); then "${SUDO[@]}" "$@" @@ -304,7 +332,7 @@ function cleanup() { } if [ "$CLEAN" ]; then - trap cleanup EXIT + defer cleanup else echo "Test files saved to $TMP" fi -- cgit v1.2.3 From 785a3f2d777627f39bed44f4ae7a0180d5184109 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Thu, 19 Oct 2023 16:37:47 -0400 Subject: tests: Refactor implementation into separate files --- tests/bfs/deep_strict.sh | 2 - tests/color.sh | 43 +++ tests/common/execdir_ulimit.sh | 1 - tests/getopts.sh | 158 ++++++++ tests/gnu/printf_u_g_ulimit.sh | 1 - tests/ls-color.sh | 6 +- tests/posix/deep.sh | 2 - tests/posix/nogroup_ulimit.sh | 1 - tests/posix/nouser_ulimit.sh | 1 - tests/run.sh | 316 ++++++++++++++++ tests/stddirs.sh | 185 +++++++++ tests/tests.sh | 824 +---------------------------------------- tests/util.sh | 189 ++++++++++ 13 files changed, 906 insertions(+), 823 deletions(-) create mode 100644 tests/color.sh create mode 100644 tests/getopts.sh create mode 100644 tests/run.sh create mode 100644 tests/stddirs.sh create mode 100644 tests/util.sh (limited to 'tests/gnu') diff --git a/tests/bfs/deep_strict.sh b/tests/bfs/deep_strict.sh index e057310..50c8f05 100644 --- a/tests/bfs/deep_strict.sh +++ b/tests/bfs/deep_strict.sh @@ -1,5 +1,3 @@ -closefrom 4 - # Not even enough fds to keep the root open ulimit -n 7 bfs_diff deep -type f -exec bash -c 'echo "${1:0:6}/.../${1##*/} (${#1})"' bash {} \; diff --git a/tests/color.sh b/tests/color.sh new file mode 100644 index 0000000..0d6ef68 --- /dev/null +++ b/tests/color.sh @@ -0,0 +1,43 @@ +#!/hint/bash + +# Copyright © Tavian Barnes +# SPDX-License-Identifier: 0BSD + +## Colored output + +# Common escape sequences +BLD=$'\e[01m' +RED=$'\e[01;31m' +GRN=$'\e[01;32m' +YLW=$'\e[01;33m' +BLU=$'\e[01;34m' +MAG=$'\e[01;35m' +CYN=$'\e[01;36m' +RST=$'\e[0m' + +# Check if we should color output to the given fd +color_fd() { + [ -z "${NO_COLOR:-}" ] && [ -t "$1" ] +} + +# Cache the color status for std{out,err} +color_fd 1 && COLOR_STDOUT=1 || COLOR_STDOUT=0 +color_fd 2 && COLOR_STDERR=1 || COLOR_STDERR=0 + +# Save these in case the tests unset PATH +CAT=$(command -v cat) +SED=$(command -v sed) + +# Filter out escape sequences if necessary +color() { + if color_fd 1; then + "$CAT" + else + "$SED" $'s/\e\\[[^m]*m//g' + fi +} + +# printf with auto-detected color support +cprintf() { + printf "$@" | color +} diff --git a/tests/common/execdir_ulimit.sh b/tests/common/execdir_ulimit.sh index 8bd9edd..f7fc467 100644 --- a/tests/common/execdir_ulimit.sh +++ b/tests/common/execdir_ulimit.sh @@ -2,6 +2,5 @@ clean_scratch mkdir -p scratch/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z mkdir -p scratch/a/b/c/d/e/f/g/h/i/j/k/l/m/0/1/2/3/4/5/6/7/8/9/A/B/C -closefrom 4 ulimit -n 13 bfs_diff scratch -execdir echo {} \; diff --git a/tests/getopts.sh b/tests/getopts.sh new file mode 100644 index 0000000..6616a4a --- /dev/null +++ b/tests/getopts.sh @@ -0,0 +1,158 @@ +#!/hint/bash + +# Copyright © Tavian Barnes +# SPDX-License-Identifier: 0BSD + +## Argument parsing + +# Print usage information +usage() { + local pad=$(printf "%*s" ${#0} "") + color <&2 + usage >&2 + exit 1 + ;; + *) + PATTERNS+=("$arg") + ;; + esac + done + + # Try to resolve the path to $BFS before we cd, while also supporting + # --bfs="./bin/bfs -S ids" + read -a BFS <<<"${BFS:-$BIN/bfs}" + BFS[0]=$(_realpath "$(command -v "${BFS[0]}")") + + if ((${#PATTERNS[@]} == 0)); then + PATTERNS=("*") + fi + + TEST_CASES=() + ALL_TESTS=($(cd "$TESTS" && quote {posix,common,bsd,gnu,bfs}/*.sh)) + for TEST in "${ALL_TESTS[@]}"; do + TEST="${TEST%.sh}" + for PATTERN in "${PATTERNS[@]}"; do + if [[ $TEST == $PATTERN ]]; then + TEST_CASES+=("$TEST") + break + fi + done + done + + if ((${#TEST_CASES[@]} == 0)); then + cprintf "${RED}error:${RST} No tests matched" >&2 + cprintf " ${BLD}%s${RST}" "${PATTERNS[@]}" >&2 + cprintf ".\n\n" >&2 + usage >&2 + exit 1 + fi +} diff --git a/tests/gnu/printf_u_g_ulimit.sh b/tests/gnu/printf_u_g_ulimit.sh index a84ee29..390ad48 100644 --- a/tests/gnu/printf_u_g_ulimit.sh +++ b/tests/gnu/printf_u_g_ulimit.sh @@ -1,3 +1,2 @@ -closefrom 4 ulimit -n 16 [ "$(invoke_bfs deep -printf '%u %g\n' | uniq)" = "$(id -un) $(id -gn)" ] diff --git a/tests/ls-color.sh b/tests/ls-color.sh index 9fdd59c..b9a0402 100755 --- a/tests/ls-color.sh +++ b/tests/ls-color.sh @@ -7,7 +7,7 @@ set -e -function parse_ls_colors() { +parse_ls_colors() { for key; do local -n var="$key" if [[ "$LS_COLORS" =~ (^|:)$key=(([^:]|\\:)*) ]]; then @@ -18,7 +18,7 @@ function parse_ls_colors() { done } -function re_escape() { +re_escape() { # https://stackoverflow.com/a/29613573/502399 sed 's/[^^]/[&]/g; s/\^/\\^/g' <<<"$1" } @@ -34,7 +34,7 @@ parse_ls_colors rs lc rc ec no strip="(($(re_escape "$lc$no$rc"))?($(re_escape "$ec")|$(re_escape "$lc$rc")))+" -function ls_color() { +ls_color() { # Strip the leading reset sequence from the ls output ls -1d --color "$@" | sed -E "s/^$strip([a-z].*)$strip/\4/; s/^$strip//" } diff --git a/tests/posix/deep.sh b/tests/posix/deep.sh index 3d1cd60..431705e 100644 --- a/tests/posix/deep.sh +++ b/tests/posix/deep.sh @@ -1,4 +1,2 @@ -closefrom 4 - ulimit -n 16 bfs_diff deep -type f -exec bash -c 'echo "${1:0:6}/.../${1##*/} (${#1})"' bash {} \; diff --git a/tests/posix/nogroup_ulimit.sh b/tests/posix/nogroup_ulimit.sh index 8f758c4..2186321 100644 --- a/tests/posix/nogroup_ulimit.sh +++ b/tests/posix/nogroup_ulimit.sh @@ -1,4 +1,3 @@ -closefrom 4 ulimit -n 16 # -mindepth 18, but POSIX diff --git a/tests/posix/nouser_ulimit.sh b/tests/posix/nouser_ulimit.sh index 2777589..be0a65f 100644 --- a/tests/posix/nouser_ulimit.sh +++ b/tests/posix/nouser_ulimit.sh @@ -1,4 +1,3 @@ -closefrom 4 ulimit -n 16 # -mindepth 18, but POSIX diff --git a/tests/run.sh b/tests/run.sh new file mode 100644 index 0000000..70c9cc2 --- /dev/null +++ b/tests/run.sh @@ -0,0 +1,316 @@ +#!/hint/bash + +# Copyright © Tavian Barnes +# SPDX-License-Identifier: 0BSD + +## Running test cases + +# Beginning/end of line escape sequences +BOL=$'\n' +EOL=$'\n' + +# Update $EOL for the terminal size +update_eol() { + # Bash gets $COLUMNS from stderr, so if it's redirected use tput instead + local cols="${COLUMNS-}" + if [ -z "$cols" ]; then + cols=$(tput cols) + fi + + # Put the cursor at the last column, then write a space so the next + # character will wrap + EOL=$'\e['"${cols}G " +} + +# ERR trap for tests +debug_err() { + local ret=$? line func file + callers | while read -r line func file; do + if [ "$func" = source ]; then + local cmd="$(awk "NR == $line" "$file" 2>/dev/null)" || : + debug "$file" $line "${RED}error $ret${RST}" "$cmd" >&4 + break + fi + done +} + +# Run a single test +run_test() ( + set -eE + trap debug_err ERR + cd "$TMP" + source "$@" +) + +# Run all the tests +run_tests() { + if ((VERBOSE_TESTS)); then + BOL='' + elif ((COLOR_STDOUT)); then + # Carriage return + clear line + BOL=$'\r\e[K' + + # Workaround for bash 4: checkwinsize is off by default. We can turn it + # on, but we also have to explicitly trigger a foreground job to finish + # so that it will update the window size before we use $COLUMNS + shopt -s checkwinsize + (:) + + update_eol + trap update_eol WINCH + fi + + passed=0 + failed=0 + skipped=0 + + if ((COLOR_STDOUT || VERBOSE_TESTS)); then + TEST_FMT="${BOL}${YLW}%s${RST}${EOL}" + else + TEST_FMT="." + fi + + # Turn off set -e (but turn it back on in run_test) + set +e + + for TEST in "${TEST_CASES[@]}"; do + printf "$TEST_FMT" "$TEST" + + OUT="$TMP/$TEST.out" + mkdir -p "${OUT%/*}" + + if ((VERBOSE_ERRORS)); then + run_test "$TESTS/$TEST.sh" + else + run_test "$TESTS/$TEST.sh" 2>"$TMP/$TEST.err" + fi + status=$? + + if ((status == 0)); then + ((++passed)) + elif ((status == EX_SKIP)); then + ((++skipped)) + else + ((++failed)) + ((VERBOSE_ERRORS)) || cat "$TMP/$TEST.err" >&2 + cprintf "${BOL}${RED}%s failed!${RST}\n" "$TEST" + ((STOP)) && break + fi + done + + printf "${BOL}" + + if ((passed > 0)); then + cprintf "${GRN}tests passed: %d${RST}\n" "$passed" + fi + if ((skipped > 0)); then + cprintf "${CYN}tests skipped: %s${RST}\n" "$skipped" + fi + if ((failed > 0)); then + cprintf "${RED}tests failed: %s${RST}\n" "$failed" + exit 1 + fi +} + +## Utilities for the tests themselves + +# Return value when a test is skipped +EX_SKIP=77 + +# Skip the current test +skip() { + if ((VERBOSE_SKIPPED)); then + caller | { + read -r line file + printf "${BOL}" + debug "$file" $line "${CYN}$TEST skipped!${RST}" "$(awk "NR == $line" "$file")" >&3 + } + elif ((VERBOSE_TESTS)); then + cprintf "${BOL}${CYN}%s skipped!${RST}\n" "$TEST" + fi + + exit $EX_SKIP +} + +# Run a command and check its exit status +check_exit() { + local expected="$1" + local actual="0" + shift + "$@" || actual="$?" + ((actual == expected)) +} + +# Run a command with sudo +bfs_sudo() { + if ((${#SUDO[@]})); then + "${SUDO[@]}" "$@" + else + return 1 + fi +} + +# Get the inode number of a file +inum() { + ls -id "$@" | awk '{ print $1 }' +} + +# Set an ACL on a file +set_acl() { + case "$UNAME" in + Darwin) + chmod +a "$(id -un) allow read,write" "$1" + ;; + FreeBSD) + if (($(getconf ACL_NFS4 "$1") > 0)); then + setfacl -m "u:$(id -un):rw::allow" "$1" + else + setfacl -m "u:$(id -un):rw" "$1" + fi + ;; + *) + setfacl -m "u:$(id -un):rw" "$1" + ;; + esac +} + +# Print a bfs invocation for --verbose=commands +bfs_verbose() ( + if ((!VERBOSE_COMMANDS)); then + return + fi + + # Free up an fd for the pipe + exec 4>&- + + { + printf "${GRN}%q${RST} " "${BFS[@]}" + + local expr_started= + for arg; do + if [[ $arg == -[A-Z]* ]]; then + printf "${CYN}%q${RST} " "$arg" + elif [[ $arg == [\(!] || $arg == -[ao] || $arg == -and || $arg == -or || $arg == -not ]]; then + expr_started=yes + printf "${RED}%q${RST} " "$arg" + elif [[ $expr_started && $arg == [\),] ]]; then + printf "${RED}%q${RST} " "$arg" + elif [[ $arg == -?* ]]; then + expr_started=yes + printf "${BLU}%q${RST} " "$arg" + elif [ "$expr_started" ]; then + printf "${BLD}%q${RST} " "$arg" + else + printf "${MAG}%q${RST} " "$arg" + fi + done + + printf '\n' + } | color >&3 +) + +# Run the bfs we're testing +invoke_bfs() { + bfs_verbose "$@" + + local ret=0 + # Close the logging fds + "${BFS[@]}" "$@" 3>&- 4>&- || ret=$? + + # Allow bfs to fail, but not crash + if ((ret > 125)); then + exit "$ret" + else + return "$ret" + fi +} + +if command -v unbuffer &>/dev/null; then + UNBUFFER=unbuffer +elif command -v expect_unbuffer &>/dev/null; then + UNBUFFER=expect_unbuffer +fi + +# Run bfs with a pseudo-terminal attached +bfs_pty() { + test -n "${UNBUFFER:-}" || skip + + bfs_verbose "$@" + + local ret=0 + "$UNBUFFER" bash -c 'stty cols 80 rows 24 && "$@"' bash "${BFS[@]}" "$@" || ret=$? + + if ((ret > 125)); then + exit "$ret" + else + return "$ret" + fi +} + +# Create a directory tree with xattrs in scratch +make_xattrs() { + clean_scratch + + "$XTOUCH" scratch/{normal,xattr,xattr_2} + ln -s xattr scratch/link + ln -s normal scratch/xattr_link + + case "$UNAME" in + Darwin) + xattr -w bfs_test true scratch/xattr \ + && xattr -w bfs_test_2 true scratch/xattr_2 \ + && xattr -s -w bfs_test true scratch/xattr_link + ;; + FreeBSD) + setextattr user bfs_test true scratch/xattr \ + && setextattr user bfs_test_2 true scratch/xattr_2 \ + && setextattr -h user bfs_test true scratch/xattr_link + ;; + *) + # Linux tmpfs doesn't support the user.* namespace, so we use the security.* + # namespace, which is writable by root and readable by others + bfs_sudo setfattr -n security.bfs_test scratch/xattr \ + && bfs_sudo setfattr -n security.bfs_test_2 scratch/xattr_2 \ + && bfs_sudo setfattr -h -n security.bfs_test scratch/xattr_link + ;; + esac +} + +## Snapshot testing + +# Return value when a difference is detected +EX_DIFF=20 + +# Detect colored diff support +if ((COLOR_STDERR)) && diff --color=always /dev/null /dev/null 2>/dev/null; then + DIFF="diff --color=always" +else + DIFF="diff" +fi + +# Sort the output file +sort_output() { + sort -o "$OUT" "$OUT" +} + +# Diff against the expected output +diff_output() { + local GOLD="$TESTS/$TEST.out" + + if ((UPDATE)); then + cp "$OUT" "$GOLD" + else + $DIFF -u "$GOLD" "$OUT" >&2 + fi +} + +# Run bfs, and diff it against the expected output +bfs_diff() { + local ret=0 + invoke_bfs "$@" >"$OUT" || ret=$? + + sort_output + diff_output || exit $EX_DIFF + + return $ret +} diff --git a/tests/stddirs.sh b/tests/stddirs.sh new file mode 100644 index 0000000..e7f7246 --- /dev/null +++ b/tests/stddirs.sh @@ -0,0 +1,185 @@ +#!/hint/bash + +# Copyright © Tavian Barnes +# SPDX-License-Identifier: 0BSD + +## Standard directory trees for tests + +# Creates a simple file+directory structure for tests +make_basic() { + "$XTOUCH" -p "$1"/{a,b,c/d,e/f,g/h/,i/} + "$XTOUCH" -p "$1"/{j/foo,k/foo/bar,l/foo/bar/baz} + echo baz >"$1/l/foo/bar/baz" +} + +# Creates a file+directory structure with various permissions for tests +make_perms() { + "$XTOUCH" -p -M000 "$1/0" + "$XTOUCH" -p -M444 "$1/r" + "$XTOUCH" -p -M222 "$1/w" + "$XTOUCH" -p -M644 "$1/rw" + "$XTOUCH" -p -M555 "$1/rx" + "$XTOUCH" -p -M311 "$1/wx" + "$XTOUCH" -p -M755 "$1/rwx" +} + +# Creates a file+directory structure with various symbolic and hard links +make_links() { + "$XTOUCH" -p "$1/file" + ln -s file "$1/symlink" + ln "$1/file" "$1/hardlink" + ln -s nowhere "$1/broken" + ln -s symlink/file "$1/notdir" + "$XTOUCH" -p "$1/deeply/nested"/{dir/,file} + ln -s file "$1/deeply/nested/link" + ln -s nowhere "$1/deeply/nested/broken" + ln -s deeply/nested "$1/skip" +} + +# Creates a file+directory structure with symbolic link loops +make_loops() { + "$XTOUCH" -p "$1/file" + ln -s file "$1/symlink" + ln -s nowhere "$1/broken" + ln -s symlink/file "$1/notdir" + ln -s loop "$1/loop" + mkdir -p "$1/deeply/nested/dir" + ln -s ../../deeply "$1/deeply/nested/loop" + ln -s deeply/nested/loop/nested "$1/skip" +} + +# Creates a file+directory structure with varying timestamps +make_times() { + "$XTOUCH" -p -t "1991-12-14 00:00" "$1/a" + "$XTOUCH" -p -t "1991-12-14 00:01" "$1/b" + "$XTOUCH" -p -t "1991-12-14 00:02" "$1/c" + ln -s a "$1/l" + "$XTOUCH" -p -h -t "1991-12-14 00:03" "$1/l" + "$XTOUCH" -p -t "1991-12-14 00:04" "$1" +} + +# Creates a file+directory structure with various weird file/directory names +make_weirdnames() { + "$XTOUCH" -p "$1/-/a" + "$XTOUCH" -p "$1/(/b" + "$XTOUCH" -p "$1/(-/c" + "$XTOUCH" -p "$1/!/d" + "$XTOUCH" -p "$1/!-/e" + "$XTOUCH" -p "$1/,/f" + "$XTOUCH" -p "$1/)/g" + "$XTOUCH" -p "$1/.../h" + "$XTOUCH" -p "$1/\\/i" + "$XTOUCH" -p "$1/ /j" + "$XTOUCH" -p "$1/[/k" +} + +# Creates a very deep directory structure for testing PATH_MAX handling +make_deep() { + mkdir -p "$1" + + # $name will be 255 characters, aka _XOPEN_NAME_MAX + local name="0123456789ABCDEF" + name="${name}${name}${name}${name}" + name="${name}${name}${name}${name}" + name="${name:0:255}" + + for i in {0..9} A B C D E F; do + "$XTOUCH" -p "$1/$i/$name" + + ( + cd "$1/$i" + + # 8 * 512 == 4096 >= PATH_MAX + for _ in {1..8}; do + mv "$name" .. + mkdir -p "$name/$name" + mv "../$name" "$name/$name/" + done + ) + done +} + +# Creates a directory structure with many different types, and therefore colors +make_rainbow() { + "$XTOUCH" -p "$1/file.txt" + "$XTOUCH" -p "$1/file.dat" + "$XTOUCH" -p "$1/lower".{gz,tar,tar.gz} + "$XTOUCH" -p "$1/upper".{GZ,TAR,TAR.GZ} + "$XTOUCH" -p "$1/lu.tar.GZ" "$1/ul.TAR.gz" + ln -s file.txt "$1/link.txt" + "$XTOUCH" -p "$1/mh1" + ln "$1/mh1" "$1/mh2" + mkfifo "$1/pipe" + # TODO: block + ln -s /dev/null "$1/chardev_link" + ln -s nowhere "$1/broken" + "$MKSOCK" "$1/socket" + "$XTOUCH" -p "$1"/s{u,g,ug}id + chmod u+s "$1"/su{,g}id + chmod g+s "$1"/s{u,}gid + mkdir "$1/ow" "$1"/sticky{,_ow} + chmod o+w "$1"/*ow + chmod +t "$1"/sticky* + "$XTOUCH" -p "$1"/exec.sh + chmod +x "$1"/exec.sh + "$XTOUCH" -p "$1/"$'\e[1m/\e[0m' +} + +# Create all standard directory trees +make_stddirs() { + TMP=$(mktemp -d "${TMPDIR:-/tmp}"/bfs.XXXXXXXXXX) + + if ((CLEAN)); then + defer clean_stddirs + else + printf "Test files saved to ${BLD}%s${RST}\n" "$TMP" + fi + + chown "$(id -u):$(id -g)" "$TMP" + + make_basic "$TMP/basic" + make_perms "$TMP/perms" + make_links "$TMP/links" + make_loops "$TMP/loops" + make_times "$TMP/times" + make_weirdnames "$TMP/weirdnames" + make_deep "$TMP/deep" + make_rainbow "$TMP/rainbow" + mkdir "$TMP/scratch" +} + +# Clean whatever was left in the scratch directory +clean_scratch() { + if [ -e "$TMP/scratch" ]; then + # Try to unmount anything left behind + if ((${#SUDO[@]})) && command -v mountpoint &>/dev/null; then + for path in "$TMP/scratch"/*; do + if mountpoint -q "$path"; then + sudo umount "$path" + fi + done + fi + + # Reset any modified permissions + chmod -R +rX "$TMP/scratch" + + rm -rf "$TMP/scratch" + fi + + mkdir "$TMP/scratch" +} + +# Clean up temporary directories on exit +clean_stddirs() { + # Don't force rm to deal with long paths + for dir in "$TMP"/deep/*/*; do + if [ -d "$dir" ]; then + (cd "$dir" && rm -rf *) + fi + done + + # In case a test left anything weird in scratch/ + clean_scratch + + rm -rf "$TMP" +} diff --git a/tests/tests.sh b/tests/tests.sh index dcef28e..3890243 100755 --- a/tests/tests.sh +++ b/tests/tests.sh @@ -6,815 +6,15 @@ set -euP umask 022 -export LC_ALL=C -export TZ=UTC0 - -SAN_OPTIONS="halt_on_error=1:log_to_syslog=0" -export ASAN_OPTIONS="$SAN_OPTIONS" -export LSAN_OPTIONS="$SAN_OPTIONS" -export MSAN_OPTIONS="$SAN_OPTIONS" -export TSAN_OPTIONS="$SAN_OPTIONS" -export UBSAN_OPTIONS="$SAN_OPTIONS" - -export LS_COLORS="" -unset BFS_COLORS - -BLD=$'\e[01m' -RED=$'\e[01;31m' -GRN=$'\e[01;32m' -YLW=$'\e[01;33m' -BLU=$'\e[01;34m' -MAG=$'\e[01;35m' -CYN=$'\e[01;36m' -RST=$'\e[0m' - -function color_fd() { - [ -z "${NO_COLOR:-}" ] && [ -t "$1" ] -} - -color_fd 1 && COLOR_STDOUT=1 || COLOR_STDOUT=0 -color_fd 2 && COLOR_STDERR=1 || COLOR_STDERR=0 - -# Filter out escape sequences if necessary -function color() { - if color_fd 1; then - cat - else - sed $'s/\e\\[[^m]*m//g' - fi -} - -# printf with auto-detected color support -function cprintf() { - printf "$@" | color -} - -UNAME=$(uname) - -if [ "$UNAME" = Darwin ]; then - # ASan on macOS likes to report - # - # malloc: nano zone abandoned due to inability to preallocate reserved vm space. - # - # to syslog, which as a side effect opens a socket which might take the - # place of one of the standard streams if the process is launched with it - # closed. This environment variable avoids the message. - export MallocNanoZone=0 -fi - -if command -v capsh &>/dev/null; then - if capsh --has-p=cap_dac_override &>/dev/null || capsh --has-p=cap_dac_read_search &>/dev/null; then - if [ -n "${BFS_TRIED_DROP:-}" ]; then - color >&2 <&2 <&2 <&2 - usage >&2 - exit 1 - ;; - *) - PATTERNS+=("$arg") - ;; - esac -done - -function _realpath() { - ( - cd "$(dirname -- "$1")" - echo "$PWD/$(basename -- "$1")" - ) -} - -TESTS=$(_realpath "$(dirname -- "${BASH_SOURCE[0]}")") - -if [ "${BUILDDIR-}" ]; then - BIN=$(_realpath "$BUILDDIR/bin") -else - BIN=$(_realpath "$TESTS/../bin") -fi -MKSOCK="$BIN/tests/mksock" -XTOUCH="$BIN/tests/xtouch" - -# Try to resolve the path to $BFS before we cd, while also supporting -# --bfs="./bin/bfs -S ids" -read -a BFS <<<"${BFS:-$BIN/bfs}" -BFS[0]=$(_realpath "$(command -v "${BFS[0]}")") - -# The temporary directory that will hold our test data -TMP=$(mktemp -d "${TMPDIR:-/tmp}"/bfs.XXXXXXXXXX) -chown "$(id -u):$(id -g)" "$TMP" - -cd "$TESTS" - -if ((${#PATTERNS[@]} == 0)); then - PATTERNS=("*") -fi - -TEST_CASES=() -for TEST in {posix,common,bsd,gnu,bfs}/*.sh; do - TEST="${TEST%.sh}" - for PATTERN in "${PATTERNS[@]}"; do - if [[ $TEST == $PATTERN ]]; then - TEST_CASES+=("$TEST") - break - fi - done -done - -if ((${#TEST_CASES[@]} == 0)); then - cprintf "${RED}error:${RST} No tests matched" >&2 - cprintf " ${BLD}%s${RST}" "${PATTERNS[@]}" >&2 - cprintf ".\n\n" >&2 - usage >&2 - exit 1 -fi - -function quote() { - printf '%q' "$1" - shift - if (($# > 0)); then - printf ' %q' "$@" - fi -} - -# Run a command when this (sub)shell exits -function defer() { - trap -- KILL - if ! trap -p EXIT | grep -q pop_defers; then - DEFER_CMDS=() - DEFER_LINES=() - DEFER_FILES=() - trap pop_defers EXIT - fi - - DEFER_CMDS+=("$(quote "$@")") - - local line file - read -r line file < <(caller) - DEFER_LINES+=("$line") - DEFER_FILES+=("$file") -} - -function report_err() { - local file="${1/#*\/tests\//tests\/}" - set -- "$file" "${@:2}" - - if ((COLOR_STDERR)); then - printf "${BLD}%s:%d:${RST} ${RED}error %d:${RST}\n %s\n" "$@" >&2 - else - printf "%s:%d: error %d:\n %s\n" "$@" >&2 - fi -} - -function pop_defer() { - local cmd="${DEFER_CMDS[-1]}" - local file="${DEFER_FILES[-1]}" - local line="${DEFER_LINES[-1]}" - unset "DEFER_CMDS[-1]" - unset "DEFER_FILES[-1]" - unset "DEFER_LINES[-1]" - - local ret=0 - eval "$cmd" || ret=$? - - if ((ret != 0)); then - report_err "$file" $line $ret "defer $cmd" - fi - - return $ret -} - -function pop_defers() { - local ret=0 - - while ((${#DEFER_CMDS[@]} > 0)); do - pop_defer || ret=$? - done - - return $ret -} - -function bfs_sudo() { - if ((${#SUDO[@]})); then - "${SUDO[@]}" "$@" - else - return 1 - fi -} - -function clean_scratch() { - if [ -e "$TMP/scratch" ]; then - # Try to unmount anything left behind - if ((${#SUDO[@]})) && command -v mountpoint &>/dev/null; then - for path in "$TMP"/scratch/*; do - if mountpoint -q "$path"; then - sudo umount "$path" - fi - done - fi - - # Reset any modified permissions - chmod -R +rX "$TMP/scratch" - - rm -rf "$TMP/scratch" - fi - - mkdir "$TMP/scratch" -} - -# Clean up temporary directories on exit -function cleanup() { - # Don't force rm to deal with long paths - for dir in "$TMP"/deep/*/*; do - if [ -d "$dir" ]; then - (cd "$dir" && rm -rf *) - fi - done - - # In case a test left anything weird in scratch/ - clean_scratch - - rm -rf "$TMP" -} - -if ((CLEAN)); then - defer cleanup -else - echo "Test files saved to $TMP" -fi - -# Creates a simple file+directory structure for tests -function make_basic() { - "$XTOUCH" -p "$1"/{a,b,c/d,e/f,g/h/,i/} - "$XTOUCH" -p "$1"/{j/foo,k/foo/bar,l/foo/bar/baz} - echo baz >"$1/l/foo/bar/baz" -} -make_basic "$TMP/basic" - -# Creates a file+directory structure with various permissions for tests -function make_perms() { - "$XTOUCH" -p -M000 "$1/0" - "$XTOUCH" -p -M444 "$1/r" - "$XTOUCH" -p -M222 "$1/w" - "$XTOUCH" -p -M644 "$1/rw" - "$XTOUCH" -p -M555 "$1/rx" - "$XTOUCH" -p -M311 "$1/wx" - "$XTOUCH" -p -M755 "$1/rwx" -} -make_perms "$TMP/perms" - -# Creates a file+directory structure with various symbolic and hard links -function make_links() { - "$XTOUCH" -p "$1/file" - ln -s file "$1/symlink" - ln "$1/file" "$1/hardlink" - ln -s nowhere "$1/broken" - ln -s symlink/file "$1/notdir" - "$XTOUCH" -p "$1/deeply/nested"/{dir/,file} - ln -s file "$1/deeply/nested/link" - ln -s nowhere "$1/deeply/nested/broken" - ln -s deeply/nested "$1/skip" -} -make_links "$TMP/links" - -# Creates a file+directory structure with symbolic link loops -function make_loops() { - "$XTOUCH" -p "$1/file" - ln -s file "$1/symlink" - ln -s nowhere "$1/broken" - ln -s symlink/file "$1/notdir" - ln -s loop "$1/loop" - mkdir -p "$1/deeply/nested/dir" - ln -s ../../deeply "$1/deeply/nested/loop" - ln -s deeply/nested/loop/nested "$1/skip" -} -make_loops "$TMP/loops" - -# Creates a file+directory structure with varying timestamps -function make_times() { - "$XTOUCH" -p -t "1991-12-14 00:00" "$1/a" - "$XTOUCH" -p -t "1991-12-14 00:01" "$1/b" - "$XTOUCH" -p -t "1991-12-14 00:02" "$1/c" - ln -s a "$1/l" - "$XTOUCH" -p -h -t "1991-12-14 00:03" "$1/l" - "$XTOUCH" -p -t "1991-12-14 00:04" "$1" -} -make_times "$TMP/times" - -# Creates a file+directory structure with various weird file/directory names -function make_weirdnames() { - "$XTOUCH" -p "$1/-/a" - "$XTOUCH" -p "$1/(/b" - "$XTOUCH" -p "$1/(-/c" - "$XTOUCH" -p "$1/!/d" - "$XTOUCH" -p "$1/!-/e" - "$XTOUCH" -p "$1/,/f" - "$XTOUCH" -p "$1/)/g" - "$XTOUCH" -p "$1/.../h" - "$XTOUCH" -p "$1/\\/i" - "$XTOUCH" -p "$1/ /j" - "$XTOUCH" -p "$1/[/k" -} -make_weirdnames "$TMP/weirdnames" - -# Creates a very deep directory structure for testing PATH_MAX handling -function make_deep() { - mkdir -p "$1" - - # $name will be 255 characters, aka _XOPEN_NAME_MAX - local name="0123456789ABCDEF" - name="${name}${name}${name}${name}" - name="${name}${name}${name}${name}" - name="${name:0:255}" - - for i in {0..9} A B C D E F; do - "$XTOUCH" -p "$1/$i/$name" - - ( - cd "$1/$i" - - # 8 * 512 == 4096 >= PATH_MAX - for _ in {1..8}; do - mv "$name" .. - mkdir -p "$name/$name" - mv "../$name" "$name/$name/" - done - ) - done -} -make_deep "$TMP/deep" - -# Creates a directory structure with many different types, and therefore colors -function make_rainbow() { - "$XTOUCH" -p "$1/file.txt" - "$XTOUCH" -p "$1/file.dat" - "$XTOUCH" -p "$1/lower".{gz,tar,tar.gz} - "$XTOUCH" -p "$1/upper".{GZ,TAR,TAR.GZ} - "$XTOUCH" -p "$1/lu.tar.GZ" "$1/ul.TAR.gz" - ln -s file.txt "$1/link.txt" - "$XTOUCH" -p "$1/mh1" - ln "$1/mh1" "$1/mh2" - mkfifo "$1/pipe" - # TODO: block - ln -s /dev/null "$1/chardev_link" - ln -s nowhere "$1/broken" - "$MKSOCK" "$1/socket" - "$XTOUCH" -p "$1"/s{u,g,ug}id - chmod u+s "$1"/su{,g}id - chmod g+s "$1"/s{u,}gid - mkdir "$1/ow" "$1"/sticky{,_ow} - chmod o+w "$1"/*ow - chmod +t "$1"/sticky* - "$XTOUCH" -p "$1"/exec.sh - chmod +x "$1"/exec.sh - "$XTOUCH" -p "$1/"$'\e[1m/\e[0m' -} -make_rainbow "$TMP/rainbow" - -mkdir "$TMP/scratch" - -# Close stdin so bfs doesn't think we're interactive -exec &1 -fi - -function bfs_verbose() { - if ((!VERBOSE_COMMANDS)); then - return - fi - - { - printf "${GRN}%q${RST} " "${BFS[@]}" - - local expr_started= - for arg; do - if [[ $arg == -[A-Z]* ]]; then - printf "${CYN}%q${RST} " "$arg" - elif [[ $arg == [\(!] || $arg == -[ao] || $arg == -and || $arg == -or || $arg == -not ]]; then - expr_started=yes - printf "${RED}%q${RST} " "$arg" - elif [[ $expr_started && $arg == [\),] ]]; then - printf "${RED}%q${RST} " "$arg" - elif [[ $arg == -?* ]]; then - expr_started=yes - printf "${BLU}%q${RST} " "$arg" - elif [ "$expr_started" ]; then - printf "${BLD}%q${RST} " "$arg" - else - printf "${MAG}%q${RST} " "$arg" - fi - done - - printf '\n' - } | color >&3 -} - -function invoke_bfs() { - bfs_verbose "$@" - - local ret=0 - "${BFS[@]}" "$@" || ret=$? - - # Allow bfs to fail, but not crash - if ((ret > 125)); then - exit "$ret" - else - return "$ret" - fi -} - -if command -v unbuffer &>/dev/null; then - UNBUFFER=unbuffer -elif command -v expect_unbuffer &>/dev/null; then - UNBUFFER=expect_unbuffer -fi - -function bfs_pty() { - test -n "${UNBUFFER:-}" || skip - - bfs_verbose "$@" - - local ret=0 - "$UNBUFFER" bash -c 'stty cols 80 rows 24 && "$@"' bash "${BFS[@]}" "$@" || ret=$? - - if ((ret > 125)); then - exit "$ret" - else - return "$ret" - fi -} - -function check_exit() { - local expected="$1" - local actual="0" - shift - "$@" || actual="$?" - ((actual == expected)) -} - -# Detect colored diff support -if ((COLOR_STDERR)) && diff --color=always /dev/null /dev/null 2>/dev/null; then - DIFF="diff --color=always" -else - DIFF="diff" -fi - -# Return value when a difference is detected -EX_DIFF=20 -# Return value when a test is skipped -EX_SKIP=77 - -function sort_output() { - sort -o "$OUT" "$OUT" -} - -function diff_output() { - local GOLD="$TESTS/$TEST.out" - - if ((UPDATE)); then - cp "$OUT" "$GOLD" - else - $DIFF -u "$GOLD" "$OUT" >&2 - fi -} - -function bfs_diff() ( - bfs_verbose "$@" - - # Close the dup()'d stdout to make sure we have enough fd's for the process - # substitution, even with low ulimit -n - exec 3>&- - - "${BFS[@]}" "$@" | sort >"$OUT" - local status="${PIPESTATUS[0]}" - - diff_output || exit $EX_DIFF - return "$status" -) - -function skip() { - if ((VERBOSE_SKIPPED)); then - caller | { - read -r line file - cprintf "${BOL}${CYN}%s skipped!${RST} (%s)\n" "$TEST" "$(awk "NR == $line" "$file")" - } - elif ((VERBOSE_TESTS)); then - cprintf "${BOL}${CYN}%s skipped!${RST}\n" "$TEST" - fi - - exit $EX_SKIP -} - -function closefrom() { - if [ -d /proc/self/fd ]; then - local fds=/proc/self/fd - else - local fds=/dev/fd - fi - - for fd in "$fds"/*; do - if [ ! -e "$fd" ]; then - continue - fi - - local fd="${fd##*/}" - if ((fd >= $1)); then - eval "exec ${fd}<&-" - fi - done -} - -function inum() { - ls -id "$@" | awk '{ print $1 }' -} - -function set_acl() { - case "$UNAME" in - Darwin) - chmod +a "$(id -un) allow read,write" "$1" - ;; - FreeBSD) - if (($(getconf ACL_NFS4 "$1") > 0)); then - setfacl -m "u:$(id -un):rw::allow" "$1" - else - setfacl -m "u:$(id -un):rw" "$1" - fi - ;; - *) - setfacl -m "u:$(id -un):rw" "$1" - ;; - esac -} - -function make_xattrs() { - clean_scratch - - "$XTOUCH" scratch/{normal,xattr,xattr_2} - ln -s xattr scratch/link - ln -s normal scratch/xattr_link - - case "$UNAME" in - Darwin) - xattr -w bfs_test true scratch/xattr \ - && xattr -w bfs_test_2 true scratch/xattr_2 \ - && xattr -s -w bfs_test true scratch/xattr_link - ;; - FreeBSD) - setextattr user bfs_test true scratch/xattr \ - && setextattr user bfs_test_2 true scratch/xattr_2 \ - && setextattr -h user bfs_test true scratch/xattr_link - ;; - *) - # Linux tmpfs doesn't support the user.* namespace, so we use the security.* - # namespace, which is writable by root and readable by others - bfs_sudo setfattr -n security.bfs_test scratch/xattr \ - && bfs_sudo setfattr -n security.bfs_test_2 scratch/xattr_2 \ - && bfs_sudo setfattr -h -n security.bfs_test scratch/xattr_link - ;; - esac -} - -cd "$TMP" -set +e - -BOL='\n' -EOL='\n' - -function update_eol() { - # Bash gets $COLUMNS from stderr, so if it's redirected use tput instead - local cols="${COLUMNS-}" - if [ -z "$cols" ]; then - cols=$(tput cols) - fi - - # Put the cursor at the last column, then write a space so the next - # character will wrap - EOL="\\033[${cols}G " -} - -if ((VERBOSE_TESTS)); then - BOL='' -elif ((COLOR_STDOUT)); then - BOL='\r\033[K' - - # Workaround for bash 4: checkwinsize is off by default. We can turn it on, - # but we also have to explicitly trigger a foreground job to finish so that - # it will update the window size before we use $COLUMNS - shopt -s checkwinsize - (:) - - update_eol - trap update_eol WINCH -fi - -function callers() { - local frame=0 - while caller $frame; do - ((++frame)) - done -} - -function debug_err() { - local ret=$? line func file - callers | while read -r line func file; do - if [ "$func" = source ]; then - local cmd="$(awk "NR == $line" "$file" 2>/dev/null)" || : - report_err "$file" $line $ret "$cmd" - break - fi - done -} - -function run_test() ( - set -eE - trap debug_err ERR - source "$@" -) - -passed=0 -failed=0 -skipped=0 - -if ((COLOR_STDOUT || VERBOSE_TESTS)); then - TEST_FMT="${BOL}${YLW}%s${RST}${EOL}" -else - TEST_FMT="." -fi - -for TEST in "${TEST_CASES[@]}"; do - printf "$TEST_FMT" "$TEST" - - OUT="$TMP/$TEST.out" - mkdir -p "${OUT%/*}" - - if ((VERBOSE_ERRORS)); then - run_test "$TESTS/$TEST.sh" - else - run_test "$TESTS/$TEST.sh" 2>"$TMP/$TEST.err" - fi - status=$? - - if ((status == 0)); then - ((++passed)) - elif ((status == EX_SKIP)); then - ((++skipped)) - else - ((++failed)) - ((VERBOSE_ERRORS)) || cat "$TMP/$TEST.err" >&2 - cprintf "${BOL}${RED}%s failed!${RST}\n" "$TEST" - ((STOP)) && break - fi -done - -printf "${BOL}" - -if ((passed > 0)); then - cprintf "${GRN}tests passed: %d${RST}\n" "$passed" -fi -if ((skipped > 0)); then - cprintf "${CYN}tests skipped: %s${RST}\n" "$skipped" -fi -if ((failed > 0)); then - cprintf "${RED}tests failed: %s${RST}\n" "$failed" - exit 1 -fi +TESTS="$(dirname -- "${BASH_SOURCE[0]}")" +. "$TESTS/util.sh" +. "$TESTS/color.sh" +. "$TESTS/stddirs.sh" +. "$TESTS/getopts.sh" +. "$TESTS/run.sh" + +stdenv +drop_root "$@" +parse_args "$@" +make_stddirs +run_tests diff --git a/tests/util.sh b/tests/util.sh new file mode 100644 index 0000000..5131522 --- /dev/null +++ b/tests/util.sh @@ -0,0 +1,189 @@ +#!/hint/bash + +# Copyright © Tavian Barnes +# SPDX-License-Identifier: 0BSD + +## Utility functions + +# Portable realpath(1) +_realpath() ( + cd "$(dirname -- "$1")" + echo "$PWD/$(basename -- "$1")" +) + +# Globals +TESTS=$(_realpath "$TESTS") +if [ "${BUILDDIR-}" ]; then + BIN=$(_realpath "$BUILDDIR/bin") +else + BIN=$(_realpath "$TESTS/../bin") +fi +MKSOCK="$BIN/tests/mksock" +XTOUCH="$BIN/tests/xtouch" +UNAME=$(uname) + +# Standardize the environment +stdenv() { + export LC_ALL=C + export TZ=UTC0 + + local SAN_OPTIONS="halt_on_error=1:log_to_syslog=0" + export ASAN_OPTIONS="$SAN_OPTIONS" + export LSAN_OPTIONS="$SAN_OPTIONS" + export MSAN_OPTIONS="$SAN_OPTIONS" + export TSAN_OPTIONS="$SAN_OPTIONS" + export UBSAN_OPTIONS="$SAN_OPTIONS" + + export LS_COLORS="" + unset BFS_COLORS + + if [ "$UNAME" = Darwin ]; then + # ASan on macOS likes to report + # + # malloc: nano zone abandoned due to inability to preallocate reserved vm space. + # + # to syslog, which as a side effect opens a socket which might take the + # place of one of the standard streams if the process is launched with + # it closed. This environment variable avoids the message. + export MallocNanoZone=0 + fi + + # Close non-standard inherited fds + if [ -d /proc/self/fd ]; then + local fds=/proc/self/fd + else + local fds=/dev/fd + fi + + for fd in "$fds"/*; do + if [ ! -e "$fd" ]; then + continue + fi + + local fd="${fd##*/}" + if ((fd > 2)); then + eval "exec ${fd}<&-" + fi + done + + # Close stdin so bfs doesn't think we're interactive + # dup() the standard fds for logging even when redirected + exec &1 4>&2 +} + +# Drop root priviliges or bail +drop_root() { + if command -v capsh &>/dev/null; then + if capsh --has-p=cap_dac_override &>/dev/null || capsh --has-p=cap_dac_read_search &>/dev/null; then + if [ -n "${BFS_TRIED_DROP:-}" ]; then + color >&2 <&2 <&2 < 0)); then + printf ' %q' "$@" + fi +} + +# Run a command when this (sub)shell exits +defer() { + # Refresh trap state before trap -p + # See https://unix.stackexchange.com/a/556888/56202 + trap -- KILL + + # Check if the EXIT trap is already set + if ! trap -p EXIT | grep -q pop_defers; then + DEFER_CMDS=() + DEFER_LINES=() + DEFER_FILES=() + trap pop_defers EXIT + fi + + DEFER_CMDS+=("$(quote "$@")") + + local line file + read -r line file < <(caller) + DEFER_LINES+=("$line") + DEFER_FILES+=("$file") +} + +# Pop a single command from the defer stack and run it +pop_defer() { + local cmd="${DEFER_CMDS[-1]}" + local file="${DEFER_FILES[-1]}" + local line="${DEFER_LINES[-1]}" + unset "DEFER_CMDS[-1]" + unset "DEFER_FILES[-1]" + unset "DEFER_LINES[-1]" + + local ret=0 + eval "$cmd" || ret=$? + + if ((ret != 0)); then + debug "$file" $line "${RED}error $ret${RST}" "defer $cmd" >&4 + fi + + return $ret +} + +# Run all deferred commands +pop_defers() { + local ret=0 + + while ((${#DEFER_CMDS[@]} > 0)); do + pop_defer || ret=$? + done + + return $ret +} -- cgit v1.2.3 From a2af2746c4686201e2e0796fbdfa115d08727b86 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Sun, 22 Oct 2023 16:41:41 -0400 Subject: tests: Use test-specific scratch directories --- tests/bfs/L_capable.out | 4 +- tests/bfs/L_capable.sh | 13 +++--- tests/bfs/capable.out | 2 +- tests/bfs/capable.sh | 13 +++--- tests/bfs/color_ls.sh | 2 +- tests/bfs/exec_flush_fprint.sh | 3 +- tests/bsd/L_acl.out | 4 +- tests/bsd/L_acl.sh | 12 +++--- tests/bsd/L_xattr.out | 6 +-- tests/bsd/L_xattr.sh | 4 +- tests/bsd/L_xattrname.out | 4 +- tests/bsd/L_xattrname.sh | 6 +-- tests/bsd/acl.out | 2 +- tests/bsd/acl.sh | 12 +++--- tests/bsd/flags.out | 2 +- tests/bsd/flags.sh | 10 ++--- tests/bsd/rm.out | 2 +- tests/bsd/rm.sh | 10 ++--- tests/bsd/type_w.out | 72 ++++++++++++++++----------------- tests/bsd/type_w.sh | 36 ++++++++--------- tests/bsd/xattr.out | 6 +-- tests/bsd/xattr.sh | 4 +- tests/bsd/xattrname.out | 4 +- tests/bsd/xattrname.sh | 6 +-- tests/common/L_ls.sh | 3 +- tests/common/L_mount.out | 10 ++--- tests/common/L_mount.sh | 16 ++++---- tests/common/delete.out | 2 +- tests/common/delete.sh | 11 ++--- tests/common/delete_many.out | 2 +- tests/common/delete_many.sh | 10 ++--- tests/common/execdir_ulimit.out | 2 +- tests/common/execdir_ulimit.sh | 8 ++-- tests/common/inum_bind_mount.out | 4 +- tests/common/inum_bind_mount.sh | 10 ++--- tests/common/inum_mount.out | 2 +- tests/common/inum_mount.sh | 10 ++--- tests/common/ls.sh | 3 +- tests/common/mount.out | 8 ++-- tests/common/mount.sh | 12 +++--- tests/gnu/L_delete.out | 4 +- tests/gnu/L_delete.sh | 11 +++-- tests/gnu/files0_from_file.sh | 6 +-- tests/gnu/fls.sh | 3 +- tests/gnu/fls_nonexistent.sh | 2 +- tests/gnu/fprint0_nonexistent.sh | 2 +- tests/gnu/fprint_duplicate.sh | 10 ++--- tests/gnu/fprint_nonexistent.sh | 2 +- tests/gnu/fprintf_nonexistent.sh | 2 +- tests/gnu/fstype_stacked.out | 2 +- tests/gnu/fstype_stacked.sh | 14 +++---- tests/gnu/fstype_umount.sh | 14 +++---- tests/gnu/ignore_readdir_race.sh | 6 +-- tests/gnu/ignore_readdir_race_notdir.sh | 6 +-- tests/gnu/inum_automount.out | 2 +- tests/gnu/inum_automount.sh | 14 +++---- tests/gnu/printf_Y_error.out | 6 +-- tests/gnu/printf_Y_error.sh | 12 +++--- tests/gnu/regex_invalid_utf8.out | 2 +- tests/gnu/regex_invalid_utf8.sh | 10 ++--- tests/gnu/xtype_bind_mount.out | 4 +- tests/gnu/xtype_bind_mount.sh | 12 +++--- tests/posix/L_xdev.out | 10 ++--- tests/posix/L_xdev.sh | 16 ++++---- tests/posix/depth_error.out | 4 +- tests/posix/depth_error.sh | 10 ++--- tests/posix/overlayfs.out | 10 ++--- tests/posix/overlayfs.sh | 14 +++---- tests/posix/readdir_error.sh | 18 ++++----- tests/posix/type_bind_mount.out | 2 +- tests/posix/type_bind_mount.sh | 10 ++--- tests/posix/unionfs.out | 20 ++++----- tests/posix/unionfs.sh | 13 +++--- tests/posix/xdev.out | 8 ++-- tests/posix/xdev.sh | 12 +++--- tests/run.sh | 28 ++++++------- tests/stddirs.sh | 25 ------------ 77 files changed, 330 insertions(+), 368 deletions(-) (limited to 'tests/gnu') diff --git a/tests/bfs/L_capable.out b/tests/bfs/L_capable.out index e5ba3c7..0810d4a 100644 --- a/tests/bfs/L_capable.out +++ b/tests/bfs/L_capable.out @@ -1,2 +1,2 @@ -scratch/capable -scratch/link +./capable +./link diff --git a/tests/bfs/L_capable.sh b/tests/bfs/L_capable.sh index 232d6ac..97c404f 100644 --- a/tests/bfs/L_capable.sh +++ b/tests/bfs/L_capable.sh @@ -1,11 +1,10 @@ test "$UNAME" = "Linux" || skip +invoke_bfs . -quit -capable || skip -clean_scratch +cd "$TEST" -invoke_bfs scratch -quit -capable || skip +"$XTOUCH" normal capable +bfs_sudo setcap all+ep capable || skip +ln -s capable link -"$XTOUCH" scratch/{normal,capable} -bfs_sudo setcap all+ep scratch/capable || skip -ln -s capable scratch/link - -bfs_diff -L scratch -capable +bfs_diff -L . -capable diff --git a/tests/bfs/capable.out b/tests/bfs/capable.out index 78b5bd9..ac7b5ce 100644 --- a/tests/bfs/capable.out +++ b/tests/bfs/capable.out @@ -1 +1 @@ -scratch/capable +./capable diff --git a/tests/bfs/capable.sh b/tests/bfs/capable.sh index e5cad63..35bb0b4 100644 --- a/tests/bfs/capable.sh +++ b/tests/bfs/capable.sh @@ -1,11 +1,10 @@ test "$UNAME" = "Linux" || skip +invoke_bfs . -quit -capable || skip -clean_scratch +cd "$TEST" -invoke_bfs scratch -quit -capable || skip +"$XTOUCH" normal capable +bfs_sudo setcap all+ep capable || skip +ln -s capable link -"$XTOUCH" scratch/{normal,capable} -bfs_sudo setcap all+ep scratch/capable || skip -ln -s capable scratch/link - -bfs_diff scratch -capable +bfs_diff . -capable diff --git a/tests/bfs/color_ls.sh b/tests/bfs/color_ls.sh index f2d3c72..f1cc216 100644 --- a/tests/bfs/color_ls.sh +++ b/tests/bfs/color_ls.sh @@ -1,4 +1,4 @@ -clean_scratch +cd "$TEST" "$XTOUCH" -p scratch/foo/bar/baz ln -s foo/bar/baz scratch/link ln -s foo/bar/nowhere scratch/broken diff --git a/tests/bfs/exec_flush_fprint.sh b/tests/bfs/exec_flush_fprint.sh index bf6b62f..a862773 100644 --- a/tests/bfs/exec_flush_fprint.sh +++ b/tests/bfs/exec_flush_fprint.sh @@ -1,3 +1,2 @@ # Even non-stdstreams should be flushed -clean_scratch -bfs_diff basic/a -fprint scratch/foo -exec cat scratch/foo \; +bfs_diff basic/a -fprint "$OUT.f" -exec cat "$OUT.f" \; diff --git a/tests/bsd/L_acl.out b/tests/bsd/L_acl.out index 1dae00a..dd89800 100644 --- a/tests/bsd/L_acl.out +++ b/tests/bsd/L_acl.out @@ -1,2 +1,2 @@ -scratch/acl -scratch/link +./acl +./link diff --git a/tests/bsd/L_acl.sh b/tests/bsd/L_acl.sh index db97013..a3fcbc8 100644 --- a/tests/bsd/L_acl.sh +++ b/tests/bsd/L_acl.sh @@ -1,9 +1,9 @@ -clean_scratch +cd "$TEST" -invoke_bfs scratch -quit -acl || skip +invoke_bfs . -quit -acl || skip -"$XTOUCH" scratch/{normal,acl} -set_acl scratch/acl || skip -ln -s acl scratch/link +"$XTOUCH" normal acl +set_acl acl || skip +ln -s acl link -bfs_diff -L scratch -acl +bfs_diff -L . -acl diff --git a/tests/bsd/L_xattr.out b/tests/bsd/L_xattr.out index 12fac95..21eb50f 100644 --- a/tests/bsd/L_xattr.out +++ b/tests/bsd/L_xattr.out @@ -1,3 +1,3 @@ -scratch/link -scratch/xattr -scratch/xattr_2 +./link +./xattr +./xattr_2 diff --git a/tests/bsd/L_xattr.sh b/tests/bsd/L_xattr.sh index 1f61c78..f8b56d8 100644 --- a/tests/bsd/L_xattr.sh +++ b/tests/bsd/L_xattr.sh @@ -1,3 +1,3 @@ -invoke_bfs scratch -quit -xattr || skip +invoke_bfs . -quit -xattr || skip make_xattrs || skip -bfs_diff -L scratch -xattr +bfs_diff -L . -xattr diff --git a/tests/bsd/L_xattrname.out b/tests/bsd/L_xattrname.out index 4dc4836..9e4c172 100644 --- a/tests/bsd/L_xattrname.out +++ b/tests/bsd/L_xattrname.out @@ -1,2 +1,2 @@ -scratch/link -scratch/xattr +./link +./xattr diff --git a/tests/bsd/L_xattrname.sh b/tests/bsd/L_xattrname.sh index 3b2006b..8108d57 100644 --- a/tests/bsd/L_xattrname.sh +++ b/tests/bsd/L_xattrname.sh @@ -1,11 +1,11 @@ -invoke_bfs scratch -quit -xattr || skip +invoke_bfs . -quit -xattr || skip make_xattrs || skip case "$UNAME" in Darwin|FreeBSD) - bfs_diff -L scratch -xattrname bfs_test + bfs_diff -L . -xattrname bfs_test ;; *) - bfs_diff -L scratch -xattrname security.bfs_test + bfs_diff -L . -xattrname security.bfs_test ;; esac diff --git a/tests/bsd/acl.out b/tests/bsd/acl.out index ddf8446..92e2f67 100644 --- a/tests/bsd/acl.out +++ b/tests/bsd/acl.out @@ -1 +1 @@ -scratch/acl +./acl diff --git a/tests/bsd/acl.sh b/tests/bsd/acl.sh index c044398..a13c75f 100644 --- a/tests/bsd/acl.sh +++ b/tests/bsd/acl.sh @@ -1,9 +1,9 @@ -clean_scratch +cd "$TEST" -invoke_bfs scratch -quit -acl || skip +invoke_bfs . -quit -acl || skip -"$XTOUCH" scratch/{normal,acl} -set_acl scratch/acl || skip -ln -s acl scratch/link +"$XTOUCH" normal acl +set_acl acl || skip +ln -s acl link -bfs_diff scratch -acl +bfs_diff . -acl diff --git a/tests/bsd/flags.out b/tests/bsd/flags.out index 11998ed..3216ff5 100644 --- a/tests/bsd/flags.out +++ b/tests/bsd/flags.out @@ -1 +1 @@ -scratch/bar +./bar diff --git a/tests/bsd/flags.sh b/tests/bsd/flags.sh index 949a7d3..eb9bc22 100644 --- a/tests/bsd/flags.sh +++ b/tests/bsd/flags.sh @@ -1,8 +1,8 @@ -invoke_bfs scratch -quit -flags offline || skip +invoke_bfs . -quit -flags offline || skip -clean_scratch +cd "$TEST" -"$XTOUCH" scratch/{foo,bar} -chflags offline scratch/bar || skip +"$XTOUCH" foo bar +chflags offline bar || skip -bfs_diff scratch -flags -offline,nohidden +bfs_diff . -flags -offline,nohidden diff --git a/tests/bsd/rm.out b/tests/bsd/rm.out index fb188b9..9c558e3 100644 --- a/tests/bsd/rm.out +++ b/tests/bsd/rm.out @@ -1 +1 @@ -scratch +. diff --git a/tests/bsd/rm.sh b/tests/bsd/rm.sh index 9ee2b0a..595d514 100644 --- a/tests/bsd/rm.sh +++ b/tests/bsd/rm.sh @@ -1,6 +1,4 @@ -clean_scratch -"$XTOUCH" -p scratch/foo/bar/baz - -(cd scratch && invoke_bfs . -rm) - -bfs_diff scratch +cd "$TEST" +"$XTOUCH" -p foo/bar/baz +invoke_bfs . -rm +bfs_diff . diff --git a/tests/bsd/type_w.out b/tests/bsd/type_w.out index d383f69..a20a4f3 100644 --- a/tests/bsd/type_w.out +++ b/tests/bsd/type_w.out @@ -1,38 +1,34 @@ -1: -rw-r--r-- scratch/mnt/lower/bar -1: -rw-r--r-- scratch/mnt/lower/baz -1: -rw-r--r-- scratch/mnt/lower/foo -1: -rw-r--r-- scratch/mnt/upper/baz/qux -1: -rw-r--r-- scratch/mnt/upper/foo -1: drwxr-xr-x scratch/mnt -1: drwxr-xr-x scratch/mnt/lower -1: drwxr-xr-x scratch/mnt/upper -1: drwxr-xr-x scratch/mnt/upper/baz -2: w--------- scratch/mnt/upper/bar -3: -rw-r--r-- scratch/mnt/lower/bar -3: -rw-r--r-- scratch/mnt/lower/baz -3: -rw-r--r-- scratch/mnt/lower/foo -3: -rw-r--r-- scratch/mnt/upper/baz/qux -3: -rw-r--r-- scratch/mnt/upper/foo -3: drwxr-xr-x scratch/mnt -3: drwxr-xr-x scratch/mnt/lower -3: drwxr-xr-x scratch/mnt/upper -3: drwxr-xr-x scratch/mnt/upper/baz -3: w--------- scratch/mnt/upper/bar -4: -rw-r--r-- scratch/mnt/lower/bar -4: -rw-r--r-- scratch/mnt/lower/baz -4: -rw-r--r-- scratch/mnt/lower/foo -4: -rw-r--r-- scratch/mnt/upper/baz/qux -4: drwxr-xr-x scratch/mnt -4: drwxr-xr-x scratch/mnt/lower -4: drwxr-xr-x scratch/mnt/upper -4: drwxr-xr-x scratch/mnt/upper/baz -5: w--------- scratch/mnt/upper/bar -6: -rw-r--r-- scratch/mnt/lower/bar -6: -rw-r--r-- scratch/mnt/lower/baz -6: -rw-r--r-- scratch/mnt/lower/foo -6: -rw-r--r-- scratch/mnt/upper/baz/qux -6: drwxr-xr-x scratch/mnt -6: drwxr-xr-x scratch/mnt/lower -6: drwxr-xr-x scratch/mnt/upper -6: drwxr-xr-x scratch/mnt/upper/baz -6: w--------- scratch/mnt/upper/bar +1: -rw-r--r-- mnt/lower/bar +1: -rw-r--r-- mnt/lower/baz +1: -rw-r--r-- mnt/lower/foo +1: -rw-r--r-- mnt/upper/baz/qux +1: -rw-r--r-- mnt/upper/foo +1: drwxr-xr-x mnt/lower +1: drwxr-xr-x mnt/upper +1: drwxr-xr-x mnt/upper/baz +2: w--------- mnt/upper/bar +3: -rw-r--r-- mnt/lower/bar +3: -rw-r--r-- mnt/lower/baz +3: -rw-r--r-- mnt/lower/foo +3: -rw-r--r-- mnt/upper/baz/qux +3: -rw-r--r-- mnt/upper/foo +3: drwxr-xr-x mnt/lower +3: drwxr-xr-x mnt/upper +3: drwxr-xr-x mnt/upper/baz +3: w--------- mnt/upper/bar +4: -rw-r--r-- mnt/lower/bar +4: -rw-r--r-- mnt/lower/baz +4: -rw-r--r-- mnt/lower/foo +4: -rw-r--r-- mnt/upper/baz/qux +4: drwxr-xr-x mnt/lower +4: drwxr-xr-x mnt/upper +4: drwxr-xr-x mnt/upper/baz +5: w--------- mnt/upper/bar +6: -rw-r--r-- mnt/lower/bar +6: -rw-r--r-- mnt/lower/baz +6: -rw-r--r-- mnt/lower/foo +6: -rw-r--r-- mnt/upper/baz/qux +6: drwxr-xr-x mnt/lower +6: drwxr-xr-x mnt/upper +6: drwxr-xr-x mnt/upper/baz +6: w--------- mnt/upper/bar diff --git a/tests/bsd/type_w.sh b/tests/bsd/type_w.sh index 15b4e68..aec9cb1 100644 --- a/tests/bsd/type_w.sh +++ b/tests/bsd/type_w.sh @@ -2,51 +2,51 @@ command -v mdconfig &>/dev/null || skip command -v newfs &>/dev/null || skip -clean_scratch +cd "$TEST" # Create a ramdisk -truncate -s1M scratch/img -md=$(bfs_sudo mdconfig scratch/img) || skip +truncate -s1M img +md=$(bfs_sudo mdconfig img) || skip defer bfs_sudo mdconfig -du "$md" # Make an ffs filesystem bfs_sudo newfs -n "/dev/$md" >&2 || skip -mkdir scratch/mnt +mkdir mnt # Mount it -bfs_sudo mount "/dev/$md" scratch/mnt || skip -defer bfs_sudo umount scratch/mnt +bfs_sudo mount "/dev/$md" mnt || skip +defer bfs_sudo umount mnt # Make it owned by us -bfs_sudo chown "$(id -u):$(id -g)" scratch/mnt -"$XTOUCH" -p scratch/mnt/{lower/{foo,bar,baz},upper/{bar,baz/qux}} +bfs_sudo chown "$(id -u):$(id -g)" mnt +"$XTOUCH" -p mnt/{lower/{foo,bar,baz},upper/{bar,baz/qux}} # Mount a union filesystem within it -bfs_sudo mount -t unionfs -o below scratch/mnt/{lower,upper} -defer bfs_sudo umount scratch/mnt/upper +bfs_sudo mount -t unionfs -o below mnt/{lower,upper} +defer bfs_sudo umount mnt/upper # Create a whiteout -rm scratch/mnt/upper/bar +rm mnt/upper/bar # FreeBSD find doesn't have -printf, so munge -ls output munge_ls() { - sed -En 's|.*([-drwx]{10}).*(scratch/.*)|'"$1"': \1 \2|p' + sed -En 's|.*([-drwx]{10}).*(mnt/.*)|'"$1"': \1 \2|p' } # Do a few tests in one { # Normally, we shouldn't see the whiteouts - invoke_bfs scratch/mnt -ls | munge_ls 1 + invoke_bfs mnt -ls | munge_ls 1 # -type w adds whiteouts to the output - invoke_bfs scratch/mnt -type w -ls | munge_ls 2 + invoke_bfs mnt -type w -ls | munge_ls 2 # So this is not the same as test 1 - invoke_bfs scratch/mnt \( -type w -or -not -type w \) -ls | munge_ls 3 + invoke_bfs mnt \( -type w -or -not -type w \) -ls | munge_ls 3 # Unmount the unionfs pop_defer # Now repeat the same tests - invoke_bfs scratch/mnt -ls | munge_ls 4 - invoke_bfs scratch/mnt -type w -ls | munge_ls 5 - invoke_bfs scratch/mnt \( -type w -or -not -type w \) -ls | munge_ls 6 + invoke_bfs mnt -ls | munge_ls 4 + invoke_bfs mnt -type w -ls | munge_ls 5 + invoke_bfs mnt \( -type w -or -not -type w \) -ls | munge_ls 6 } >"$OUT" sort_output diff_output diff --git a/tests/bsd/xattr.out b/tests/bsd/xattr.out index 109e7c9..0afed35 100644 --- a/tests/bsd/xattr.out +++ b/tests/bsd/xattr.out @@ -1,3 +1,3 @@ -scratch/xattr -scratch/xattr_2 -scratch/xattr_link +./xattr +./xattr_2 +./xattr_link diff --git a/tests/bsd/xattr.sh b/tests/bsd/xattr.sh index 4a4658c..68f729a 100644 --- a/tests/bsd/xattr.sh +++ b/tests/bsd/xattr.sh @@ -1,3 +1,3 @@ -invoke_bfs scratch -quit -xattr || skip +invoke_bfs . -quit -xattr || skip make_xattrs || skip -bfs_diff scratch -xattr +bfs_diff . -xattr diff --git a/tests/bsd/xattrname.out b/tests/bsd/xattrname.out index 0285ac1..ef732bd 100644 --- a/tests/bsd/xattrname.out +++ b/tests/bsd/xattrname.out @@ -1,2 +1,2 @@ -scratch/xattr -scratch/xattr_link +./xattr +./xattr_link diff --git a/tests/bsd/xattrname.sh b/tests/bsd/xattrname.sh index 655bd74..38b111a 100644 --- a/tests/bsd/xattrname.sh +++ b/tests/bsd/xattrname.sh @@ -1,11 +1,11 @@ -invoke_bfs scratch -quit -xattr || skip +invoke_bfs . -quit -xattr || skip make_xattrs || skip case "$UNAME" in Darwin|FreeBSD) - bfs_diff scratch -xattrname bfs_test + bfs_diff . -xattrname bfs_test ;; *) - bfs_diff scratch -xattrname security.bfs_test + bfs_diff . -xattrname security.bfs_test ;; esac diff --git a/tests/common/L_ls.sh b/tests/common/L_ls.sh index ced16c6..7ee2b44 100644 --- a/tests/common/L_ls.sh +++ b/tests/common/L_ls.sh @@ -1,2 +1 @@ -clean_scratch -invoke_bfs -L rainbow -ls >scratch/L_ls.out +invoke_bfs -L rainbow -ls >"$OUT" diff --git a/tests/common/L_mount.out b/tests/common/L_mount.out index 2e80082..788579d 100644 --- a/tests/common/L_mount.out +++ b/tests/common/L_mount.out @@ -1,5 +1,5 @@ -scratch -scratch/foo -scratch/foo/bar -scratch/foo/qux -scratch/mnt +. +./foo +./foo/bar +./foo/qux +./mnt diff --git a/tests/common/L_mount.sh b/tests/common/L_mount.sh index aaf9069..fd8042a 100644 --- a/tests/common/L_mount.sh +++ b/tests/common/L_mount.sh @@ -1,13 +1,13 @@ test "$UNAME" = "Darwin" && skip -clean_scratch -mkdir scratch/{foo,mnt} +cd "$TEST" +mkdir foo mnt -bfs_sudo mount -t tmpfs tmpfs scratch/mnt || skip -defer bfs_sudo umount scratch/mnt +bfs_sudo mount -t tmpfs tmpfs mnt || skip +defer bfs_sudo umount mnt -ln -s ../mnt scratch/foo/bar -"$XTOUCH" scratch/mnt/baz -ln -s ../mnt/baz scratch/foo/qux +ln -s ../mnt foo/bar +"$XTOUCH" mnt/baz +ln -s ../mnt/baz foo/qux -bfs_diff -L scratch -mount +bfs_diff -L . -mount diff --git a/tests/common/delete.out b/tests/common/delete.out index fb188b9..9c558e3 100644 --- a/tests/common/delete.out +++ b/tests/common/delete.out @@ -1 +1 @@ -scratch +. diff --git a/tests/common/delete.sh b/tests/common/delete.sh index 89cf2a2..638f307 100644 --- a/tests/common/delete.sh +++ b/tests/common/delete.sh @@ -1,7 +1,4 @@ -clean_scratch -"$XTOUCH" -p scratch/foo/bar/baz - -# Don't try to delete '.' -(cd scratch && invoke_bfs . -delete) - -bfs_diff scratch +cd "$TEST" +"$XTOUCH" -p foo/bar/baz +invoke_bfs . -delete +bfs_diff . diff --git a/tests/common/delete_many.out b/tests/common/delete_many.out index fb188b9..9c558e3 100644 --- a/tests/common/delete_many.out +++ b/tests/common/delete_many.out @@ -1 +1 @@ -scratch +. diff --git a/tests/common/delete_many.sh b/tests/common/delete_many.sh index 6274319..48fe4c2 100644 --- a/tests/common/delete_many.sh +++ b/tests/common/delete_many.sh @@ -1,8 +1,8 @@ # Test for https://github.com/tavianator/bfs/issues/67 -clean_scratch -mkdir scratch/foo -"$XTOUCH" scratch/foo/{1..256} +cd "$TEST" +mkdir foo +"$XTOUCH" foo/{1..256} -invoke_bfs scratch/foo -delete -bfs_diff scratch +invoke_bfs foo -delete +bfs_diff . diff --git a/tests/common/execdir_ulimit.out b/tests/common/execdir_ulimit.out index 7f53982..bf52c09 100644 --- a/tests/common/execdir_ulimit.out +++ b/tests/common/execdir_ulimit.out @@ -1,3 +1,4 @@ +./. ./0 ./1 ./2 @@ -30,7 +31,6 @@ ./q ./r ./s -./scratch ./t ./u ./v diff --git a/tests/common/execdir_ulimit.sh b/tests/common/execdir_ulimit.sh index f7fc467..90c93c1 100644 --- a/tests/common/execdir_ulimit.sh +++ b/tests/common/execdir_ulimit.sh @@ -1,6 +1,6 @@ -clean_scratch -mkdir -p scratch/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z -mkdir -p scratch/a/b/c/d/e/f/g/h/i/j/k/l/m/0/1/2/3/4/5/6/7/8/9/A/B/C +cd "$TEST" +mkdir -p a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z +mkdir -p a/b/c/d/e/f/g/h/i/j/k/l/m/0/1/2/3/4/5/6/7/8/9/A/B/C ulimit -n 13 -bfs_diff scratch -execdir echo {} \; +bfs_diff . -execdir echo {} \; diff --git a/tests/common/inum_bind_mount.out b/tests/common/inum_bind_mount.out index a520de3..ede8749 100644 --- a/tests/common/inum_bind_mount.out +++ b/tests/common/inum_bind_mount.out @@ -1,2 +1,2 @@ -scratch/bar -scratch/foo +./bar +./foo diff --git a/tests/common/inum_bind_mount.sh b/tests/common/inum_bind_mount.sh index 47f7c36..892713e 100644 --- a/tests/common/inum_bind_mount.sh +++ b/tests/common/inum_bind_mount.sh @@ -1,9 +1,9 @@ test "$UNAME" = "Linux" || skip -clean_scratch -"$XTOUCH" scratch/{foo,bar} +cd "$TEST" +"$XTOUCH" foo bar baz -bfs_sudo mount --bind scratch/{foo,bar} || skip -defer bfs_sudo umount scratch/bar +bfs_sudo mount --bind foo bar || skip +defer bfs_sudo umount bar -bfs_diff scratch -inum "$(inum scratch/bar)" +bfs_diff . -inum "$(inum bar)" diff --git a/tests/common/inum_mount.out b/tests/common/inum_mount.out index 99c7511..99fa01e 100644 --- a/tests/common/inum_mount.out +++ b/tests/common/inum_mount.out @@ -1 +1 @@ -scratch/mnt +./mnt diff --git a/tests/common/inum_mount.sh b/tests/common/inum_mount.sh index 1bf2d86..7facf57 100644 --- a/tests/common/inum_mount.sh +++ b/tests/common/inum_mount.sh @@ -1,9 +1,9 @@ test "$UNAME" = "Darwin" && skip -clean_scratch -mkdir scratch/{foo,mnt} +cd "$TEST" +mkdir foo mnt -bfs_sudo mount -t tmpfs tmpfs scratch/mnt || skip -defer bfs_sudo umount scratch/mnt +bfs_sudo mount -t tmpfs tmpfs mnt || skip +defer bfs_sudo umount mnt -bfs_diff scratch -inum "$(inum scratch/mnt)" +bfs_diff . -inum "$(inum mnt)" diff --git a/tests/common/ls.sh b/tests/common/ls.sh index 85ca39c..bc50d90 100644 --- a/tests/common/ls.sh +++ b/tests/common/ls.sh @@ -1,2 +1 @@ -clean_scratch -invoke_bfs rainbow -ls >scratch/ls.out +invoke_bfs rainbow -ls >"$OUT" diff --git a/tests/common/mount.out b/tests/common/mount.out index f7839fb..6253434 100644 --- a/tests/common/mount.out +++ b/tests/common/mount.out @@ -1,4 +1,4 @@ -scratch -scratch/foo -scratch/foo/bar -scratch/mnt +. +./foo +./foo/bar +./mnt diff --git a/tests/common/mount.sh b/tests/common/mount.sh index db8b801..c9abde5 100644 --- a/tests/common/mount.sh +++ b/tests/common/mount.sh @@ -1,11 +1,11 @@ test "$UNAME" = "Darwin" && skip -clean_scratch -mkdir scratch/{foo,mnt} +cd "$TEST" +mkdir foo mnt -bfs_sudo mount -t tmpfs tmpfs scratch/mnt || skip -defer bfs_sudo umount scratch/mnt +bfs_sudo mount -t tmpfs tmpfs mnt || skip +defer bfs_sudo umount mnt -"$XTOUCH" scratch/foo/bar scratch/mnt/baz +"$XTOUCH" foo/bar mnt/baz -bfs_diff scratch -mount +bfs_diff . -mount diff --git a/tests/gnu/L_delete.out b/tests/gnu/L_delete.out index ed0e9a1..7ed5f0d 100644 --- a/tests/gnu/L_delete.out +++ b/tests/gnu/L_delete.out @@ -1,2 +1,2 @@ -scratch -scratch/foo +. +./foo diff --git a/tests/gnu/L_delete.sh b/tests/gnu/L_delete.sh index 8fdb12a..0559c49 100644 --- a/tests/gnu/L_delete.sh +++ b/tests/gnu/L_delete.sh @@ -1,9 +1,8 @@ -clean_scratch -mkdir scratch/foo -mkdir scratch/bar -ln -s ../foo scratch/bar/baz +cd "$TEST" +mkdir foo bar +ln -s ../foo bar/baz # Don't try to rmdir() a symlink -invoke_bfs -L scratch/bar -delete +invoke_bfs -L bar -delete -bfs_diff scratch +bfs_diff . diff --git a/tests/gnu/files0_from_file.sh b/tests/gnu/files0_from_file.sh index 089a20e..81435a0 100644 --- a/tests/gnu/files0_from_file.sh +++ b/tests/gnu/files0_from_file.sh @@ -1,4 +1,4 @@ -clean_scratch +FILE="$TMP/$TEST.in" cd weirdnames -invoke_bfs -mindepth 1 -fprintf ../scratch/files0.in "%P\0" -bfs_diff -files0-from ../scratch/files0.in +invoke_bfs -mindepth 1 -fprintf "$FILE" "%P\0" +bfs_diff -files0-from "$FILE" diff --git a/tests/gnu/fls.sh b/tests/gnu/fls.sh index a86fa20..d2ff794 100644 --- a/tests/gnu/fls.sh +++ b/tests/gnu/fls.sh @@ -1,2 +1 @@ -clean_scratch -invoke_bfs rainbow -fls scratch/fls.out +invoke_bfs rainbow -fls "$OUT" diff --git a/tests/gnu/fls_nonexistent.sh b/tests/gnu/fls_nonexistent.sh index ff86763..2854569 100644 --- a/tests/gnu/fls_nonexistent.sh +++ b/tests/gnu/fls_nonexistent.sh @@ -1 +1 @@ -! invoke_bfs rainbow -fls scratch/nonexistent/path +! invoke_bfs rainbow -fls nonexistent/path diff --git a/tests/gnu/fprint0_nonexistent.sh b/tests/gnu/fprint0_nonexistent.sh index ec14c2d..4906081 100644 --- a/tests/gnu/fprint0_nonexistent.sh +++ b/tests/gnu/fprint0_nonexistent.sh @@ -1 +1 @@ -! invoke_bfs basic -fprint0 scratch/nonexistent/path +! invoke_bfs basic -fprint0 nonexistent/path diff --git a/tests/gnu/fprint_duplicate.sh b/tests/gnu/fprint_duplicate.sh index 5275502..8533b05 100644 --- a/tests/gnu/fprint_duplicate.sh +++ b/tests/gnu/fprint_duplicate.sh @@ -1,7 +1,7 @@ -"$XTOUCH" -p scratch/foo.out -ln scratch/foo.out scratch/foo.hard -ln -s foo.out scratch/foo.soft +"$XTOUCH" -p "$TEST/foo.out" +ln "$TEST/foo.out" "$TEST/foo.hard" +ln -s foo.out "$TEST/foo.soft" -invoke_bfs basic -fprint scratch/foo.out -fprint scratch/foo.hard -fprint scratch/foo.soft -sort scratch/foo.out >"$OUT" +invoke_bfs basic -fprint "$TEST/foo.out" -fprint "$TEST/foo.hard" -fprint "$TEST/foo.soft" +sort "$TEST/foo.out" >"$OUT" diff_output diff --git a/tests/gnu/fprint_nonexistent.sh b/tests/gnu/fprint_nonexistent.sh index 4409162..2a403a2 100644 --- a/tests/gnu/fprint_nonexistent.sh +++ b/tests/gnu/fprint_nonexistent.sh @@ -1 +1 @@ -! invoke_bfs basic -fprint scratch/nonexistent/path +! invoke_bfs basic -fprint nonexistent/path diff --git a/tests/gnu/fprintf_nonexistent.sh b/tests/gnu/fprintf_nonexistent.sh index 160e739..b1eea10 100644 --- a/tests/gnu/fprintf_nonexistent.sh +++ b/tests/gnu/fprintf_nonexistent.sh @@ -1 +1 @@ -! invoke_bfs basic -fprintf scratch/nonexistent/path '%p\n' +! invoke_bfs basic -fprintf nonexistent/path '%p\n' diff --git a/tests/gnu/fstype_stacked.out b/tests/gnu/fstype_stacked.out index 99c7511..c1e0e6c 100644 --- a/tests/gnu/fstype_stacked.out +++ b/tests/gnu/fstype_stacked.out @@ -1 +1 @@ -scratch/mnt +mnt diff --git a/tests/gnu/fstype_stacked.sh b/tests/gnu/fstype_stacked.sh index a4b067a..a9739bb 100644 --- a/tests/gnu/fstype_stacked.sh +++ b/tests/gnu/fstype_stacked.sh @@ -1,12 +1,12 @@ test "$UNAME" = "Linux" || skip -clean_scratch -mkdir scratch/mnt +cd "$TEST" +mkdir mnt -bfs_sudo mount -t tmpfs tmpfs scratch/mnt || skip -defer bfs_sudo umount scratch/mnt +bfs_sudo mount -t tmpfs tmpfs mnt || skip +defer bfs_sudo umount mnt -bfs_sudo mount -t ramfs ramfs scratch/mnt || skip -defer bfs_sudo umount scratch/mnt +bfs_sudo mount -t ramfs ramfs mnt || skip +defer bfs_sudo umount mnt -bfs_diff scratch/mnt -fstype ramfs -print -o -printf '%p: %F\n' +bfs_diff mnt -fstype ramfs -print -o -printf '%p: %F\n' diff --git a/tests/gnu/fstype_umount.sh b/tests/gnu/fstype_umount.sh index b6da7a3..81c195f 100644 --- a/tests/gnu/fstype_umount.sh +++ b/tests/gnu/fstype_umount.sh @@ -1,12 +1,12 @@ test "$UNAME" = "Linux" || skip -clean_scratch +cd "$TEST" -mkdir scratch/tmp -bfs_sudo mount -t tmpfs tmpfs scratch/tmp || skip -defer bfs_sudo umount -R scratch/tmp +mkdir tmp +bfs_sudo mount -t tmpfs tmpfs tmp || skip +defer bfs_sudo umount -R tmp -mkdir scratch/tmp/ram -bfs_sudo mount -t ramfs ramfs scratch/tmp/ram || skip +mkdir tmp/ram +bfs_sudo mount -t ramfs ramfs tmp/ram || skip -bfs_diff scratch/tmp -path scratch/tmp -exec "${SUDO[@]}" umount scratch/tmp/ram \; , -fstype ramfs -print +bfs_diff tmp -path tmp -exec "${SUDO[@]}" umount tmp/ram \; , -fstype ramfs -print diff --git a/tests/gnu/ignore_readdir_race.sh b/tests/gnu/ignore_readdir_race.sh index 6586bcc..75165f6 100644 --- a/tests/gnu/ignore_readdir_race.sh +++ b/tests/gnu/ignore_readdir_race.sh @@ -1,5 +1,5 @@ -clean_scratch -"$XTOUCH" scratch/{foo,bar} +cd "$TEST" +"$XTOUCH" foo bar # -links 1 forces a stat() call, which will fail for the second file -invoke_bfs scratch -mindepth 1 -ignore_readdir_race -links 1 -exec "$TESTS/remove-sibling.sh" {} \; +invoke_bfs . -mindepth 1 -ignore_readdir_race -links 1 -exec "$TESTS/remove-sibling.sh" {} \; diff --git a/tests/gnu/ignore_readdir_race_notdir.sh b/tests/gnu/ignore_readdir_race_notdir.sh index 5b8b56d..8b03164 100644 --- a/tests/gnu/ignore_readdir_race_notdir.sh +++ b/tests/gnu/ignore_readdir_race_notdir.sh @@ -1,5 +1,5 @@ # Check -ignore_readdir_race handling when a directory is replaced with a file -clean_scratch -"$XTOUCH" -p scratch/foo/bar +cd "$TEST" +"$XTOUCH" -p foo/bar -invoke_bfs scratch -mindepth 1 -ignore_readdir_race -execdir rm -r {} \; -execdir "$XTOUCH" {} \; +invoke_bfs . -mindepth 1 -ignore_readdir_race -execdir rm -r {} \; -execdir "$XTOUCH" {} \; diff --git a/tests/gnu/inum_automount.out b/tests/gnu/inum_automount.out index 7b53ae3..3378e2d 100644 --- a/tests/gnu/inum_automount.out +++ b/tests/gnu/inum_automount.out @@ -1 +1 @@ -scratch/automnt +./automnt diff --git a/tests/gnu/inum_automount.sh b/tests/gnu/inum_automount.sh index 261a4be..86b23e1 100644 --- a/tests/gnu/inum_automount.sh +++ b/tests/gnu/inum_automount.sh @@ -2,13 +2,13 @@ command -v systemd-mount &>/dev/null || skip -clean_scratch -mkdir scratch/{foo,automnt} +cd "$TEST" +mkdir foo automnt -bfs_sudo systemd-mount -A -o bind basic scratch/automnt || skip -defer bfs_sudo systemd-umount scratch/automnt +bfs_sudo systemd-mount -A -o bind "$TMP/basic" automnt || skip +defer bfs_sudo systemd-umount automnt -before=$(inum scratch/automnt) -bfs_diff scratch -inum "$before" -prune -after=$(inum scratch/automnt) +before=$(inum automnt) +bfs_diff . -inum "$before" -prune +after=$(inum automnt) ((before == after)) diff --git a/tests/gnu/printf_Y_error.out b/tests/gnu/printf_Y_error.out index 410a9b5..1dd554e 100644 --- a/tests/gnu/printf_Y_error.out +++ b/tests/gnu/printf_Y_error.out @@ -1,3 +1,3 @@ -(scratch) () d d -(scratch/bar) (foo/bar) l ? -(scratch/foo) () d d +(.) () d d +(./bar) (foo/bar) l ? +(./foo) () d d diff --git a/tests/gnu/printf_Y_error.sh b/tests/gnu/printf_Y_error.sh index 13d52e3..d3130ce 100644 --- a/tests/gnu/printf_Y_error.sh +++ b/tests/gnu/printf_Y_error.sh @@ -1,8 +1,8 @@ -clean_scratch -mkdir scratch/foo -ln -s foo/bar scratch/bar +cd "$TEST" +mkdir foo +ln -s foo/bar bar -chmod -x scratch/foo -defer chmod +x scratch/foo +chmod -x foo +defer chmod +x foo -! bfs_diff scratch -printf '(%p) (%l) %y %Y\n' +! bfs_diff . -printf '(%p) (%l) %y %Y\n' diff --git a/tests/gnu/regex_invalid_utf8.out b/tests/gnu/regex_invalid_utf8.out index 03f3f58..a133b1a 100644 --- a/tests/gnu/regex_invalid_utf8.out +++ b/tests/gnu/regex_invalid_utf8.out @@ -1 +1 @@ -scratch/℠+./℠diff --git a/tests/gnu/regex_invalid_utf8.sh b/tests/gnu/regex_invalid_utf8.sh index 603d688..7006dcd 100644 --- a/tests/gnu/regex_invalid_utf8.sh +++ b/tests/gnu/regex_invalid_utf8.sh @@ -1,8 +1,8 @@ -clean_scratch +cd "$TEST" # Incomplete UTF-8 sequences -touch scratch/$'\xC3' || skip -touch scratch/$'\xE2\x84' || skip -touch scratch/$'\xF0\x9F\x92' || skip +touch $'\xC3' || skip +touch $'\xE2\x84' || skip +touch $'\xF0\x9F\x92' || skip -bfs_diff scratch -regex 'scratch/..' +bfs_diff . -regex '\./..' diff --git a/tests/gnu/xtype_bind_mount.out b/tests/gnu/xtype_bind_mount.out index 16804ea..d18d706 100644 --- a/tests/gnu/xtype_bind_mount.out +++ b/tests/gnu/xtype_bind_mount.out @@ -1,2 +1,2 @@ -scratch/link -scratch/null +./link +./null diff --git a/tests/gnu/xtype_bind_mount.sh b/tests/gnu/xtype_bind_mount.sh index 1cc20ec..35fb3f5 100644 --- a/tests/gnu/xtype_bind_mount.sh +++ b/tests/gnu/xtype_bind_mount.sh @@ -1,10 +1,10 @@ test "$UNAME" = "Linux" || skip -clean_scratch -"$XTOUCH" scratch/{file,null} -ln -s /dev/null scratch/link +cd "$TEST" +"$XTOUCH" file null +ln -s /dev/null link -bfs_sudo mount --bind /dev/null scratch/null || skip -defer bfs_sudo umount scratch/null +bfs_sudo mount --bind /dev/null null || skip +defer bfs_sudo umount null -bfs_diff -L scratch -type c +bfs_diff . -xtype c diff --git a/tests/posix/L_xdev.out b/tests/posix/L_xdev.out index 2e80082..788579d 100644 --- a/tests/posix/L_xdev.out +++ b/tests/posix/L_xdev.out @@ -1,5 +1,5 @@ -scratch -scratch/foo -scratch/foo/bar -scratch/foo/qux -scratch/mnt +. +./foo +./foo/bar +./foo/qux +./mnt diff --git a/tests/posix/L_xdev.sh b/tests/posix/L_xdev.sh index d16c211..82d8605 100644 --- a/tests/posix/L_xdev.sh +++ b/tests/posix/L_xdev.sh @@ -1,13 +1,13 @@ test "$UNAME" = "Darwin" && skip -clean_scratch -mkdir scratch/{foo,mnt} +cd "$TEST" +mkdir foo mnt -bfs_sudo mount -t tmpfs tmpfs scratch/mnt || skip -defer bfs_sudo umount scratch/mnt +bfs_sudo mount -t tmpfs tmpfs mnt || skip +defer bfs_sudo umount mnt -ln -s ../mnt scratch/foo/bar -"$XTOUCH" scratch/mnt/baz -ln -s ../mnt/baz scratch/foo/qux +ln -s ../mnt foo/bar +"$XTOUCH" mnt/baz +ln -s ../mnt/baz foo/qux -bfs_diff -L scratch -xdev +bfs_diff -L . -xdev diff --git a/tests/posix/depth_error.out b/tests/posix/depth_error.out index ed0e9a1..7ed5f0d 100644 --- a/tests/posix/depth_error.out +++ b/tests/posix/depth_error.out @@ -1,2 +1,2 @@ -scratch -scratch/foo +. +./foo diff --git a/tests/posix/depth_error.sh b/tests/posix/depth_error.sh index a6429d1..db414ba 100644 --- a/tests/posix/depth_error.sh +++ b/tests/posix/depth_error.sh @@ -1,7 +1,7 @@ -clean_scratch -"$XTOUCH" -p scratch/foo/bar +cd "$TEST" +"$XTOUCH" -p foo/bar -chmod a-r scratch/foo -defer chmod +r scratch/foo +chmod a-r foo +defer chmod +r foo -! bfs_diff scratch -depth +! bfs_diff . -depth diff --git a/tests/posix/overlayfs.out b/tests/posix/overlayfs.out index 754d01d..b472b56 100644 --- a/tests/posix/overlayfs.out +++ b/tests/posix/overlayfs.out @@ -1,5 +1,5 @@ -scratch/merged -scratch/merged/bar -scratch/merged/baz -scratch/merged/baz/qux -scratch/merged/foo +merged +merged/bar +merged/baz +merged/baz/qux +merged/foo diff --git a/tests/posix/overlayfs.sh b/tests/posix/overlayfs.sh index 4cccebf..21ef22f 100644 --- a/tests/posix/overlayfs.sh +++ b/tests/posix/overlayfs.sh @@ -1,11 +1,11 @@ test "$UNAME" = "Linux" || skip -clean_scratch -"$XTOUCH" -p scratch/{lower/{foo,bar,baz},upper/{bar,baz/qux}} +cd "$TEST" +"$XTOUCH" -p lower/{foo,bar,baz} upper/{bar,baz/qux} -mkdir -p scratch/{work,merged} -bfs_sudo mount -t overlay overlay -olowerdir=scratch/lower,upperdir=scratch/upper,workdir=scratch/work scratch/merged || skip -defer bfs_sudo rm -rf scratch/work -defer bfs_sudo umount scratch/merged +mkdir -p work merged +bfs_sudo mount -t overlay overlay -olowerdir=lower,upperdir=upper,workdir=work merged || skip +defer bfs_sudo rm -rf work +defer bfs_sudo umount merged -bfs_diff scratch/merged +bfs_diff merged diff --git a/tests/posix/readdir_error.sh b/tests/posix/readdir_error.sh index fc48eb1..82fcd17 100644 --- a/tests/posix/readdir_error.sh +++ b/tests/posix/readdir_error.sh @@ -1,27 +1,27 @@ test "$UNAME" = "Linux" || skip -clean_scratch -mkfifo scratch/{fever,pid,wait,running} +cd "$TEST" +mkfifo hang pid wait running ( # Create a zombie process - cat scratch/fever >/dev/null & - # Write the PID to scratch/pid - echo $! >scratch/pid + cat hang >/dev/null & + # Write the PID to pid + echo $! >pid # Don't wait on the zombie process - exec cat scratch/wait scratch/fever >scratch/running + exec cat wait hang >running ) & # Kill the parent cat on exit defer kill -9 %1 # Read the child PID -read -r pid scratch/wait & -read -r _ wait & +read -r _ /dev/null; then - for path in "$TMP/scratch"/*; do - if mountpoint -q "$path"; then - sudo umount "$path" - fi - done - fi - - # Reset any modified permissions - chmod -R +rX "$TMP/scratch" - - rm -rf "$TMP/scratch" - fi - - mkdir "$TMP/scratch" } # Clean up temporary directories on exit @@ -169,8 +147,5 @@ clean_stddirs() { fi done - # In case a test left anything weird in scratch/ - clean_scratch - rm -rf "$TMP" } -- cgit v1.2.3 From 1cfa66a4268a4eefea29f207baaefd76d7792027 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Thu, 2 Nov 2023 11:29:28 -0400 Subject: tests: Add tests for ulimit -n after -exec --- tests/gnu/execdir_ulimit.out | 16 ++++++++++++++++ tests/gnu/execdir_ulimit.sh | 2 ++ tests/posix/exec_ulimit.out | 16 ++++++++++++++++ tests/posix/exec_ulimit.sh | 2 ++ 4 files changed, 36 insertions(+) create mode 100644 tests/gnu/execdir_ulimit.out create mode 100644 tests/gnu/execdir_ulimit.sh create mode 100644 tests/posix/exec_ulimit.out create mode 100644 tests/posix/exec_ulimit.sh (limited to 'tests/gnu') diff --git a/tests/gnu/execdir_ulimit.out b/tests/gnu/execdir_ulimit.out new file mode 100644 index 0000000..7931f9a --- /dev/null +++ b/tests/gnu/execdir_ulimit.out @@ -0,0 +1,16 @@ +16 ./0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +16 ./0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +16 ./0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +16 ./0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +16 ./0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +16 ./0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +16 ./0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +16 ./0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +16 ./0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +16 ./0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +16 ./0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +16 ./0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +16 ./0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +16 ./0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +16 ./0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +16 ./0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE diff --git a/tests/gnu/execdir_ulimit.sh b/tests/gnu/execdir_ulimit.sh new file mode 100644 index 0000000..3245dad --- /dev/null +++ b/tests/gnu/execdir_ulimit.sh @@ -0,0 +1,2 @@ +ulimit -Sn 16 +bfs_diff deep -type f -execdir bash -c 'printf "%d %s\n" $(ulimit -Sn) "$1"' bash {} \; diff --git a/tests/posix/exec_ulimit.out b/tests/posix/exec_ulimit.out new file mode 100644 index 0000000..587ece2 --- /dev/null +++ b/tests/posix/exec_ulimit.out @@ -0,0 +1,16 @@ +16 deep/0/.../0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +16 deep/1/.../0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +16 deep/2/.../0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +16 deep/3/.../0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +16 deep/4/.../0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +16 deep/5/.../0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +16 deep/6/.../0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +16 deep/7/.../0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +16 deep/8/.../0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +16 deep/9/.../0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +16 deep/A/.../0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +16 deep/B/.../0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +16 deep/C/.../0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +16 deep/D/.../0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +16 deep/E/.../0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +16 deep/F/.../0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE diff --git a/tests/posix/exec_ulimit.sh b/tests/posix/exec_ulimit.sh new file mode 100644 index 0000000..8ac8ff1 --- /dev/null +++ b/tests/posix/exec_ulimit.sh @@ -0,0 +1,2 @@ +ulimit -Sn 16 +bfs_diff deep -type f -exec bash -c 'printf "%d %s\n" $(ulimit -Sn) "${1:0:6}/.../${1##*/}"' bash {} \; -- cgit v1.2.3 From 163baf1c9af13be0ce705b133e41e0c3d6427398 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Tue, 7 Nov 2023 13:10:44 -0500 Subject: parse: Reject -{exec,ok}dir if $PATH contains a relative path This matches the behaviour of GNU find. --- src/parse.c | 26 ++++++++++++++++++++++++++ tests/gnu/execdir_path_dot.sh | 1 + tests/gnu/execdir_path_empty.sh | 1 + tests/gnu/execdir_path_relative.sh | 1 + tests/gnu/okdir_path_dot.sh | 1 + tests/gnu/okdir_path_empty.sh | 1 + tests/gnu/okdir_path_relative.sh | 1 + 7 files changed, 32 insertions(+) create mode 100644 tests/gnu/execdir_path_dot.sh create mode 100644 tests/gnu/execdir_path_empty.sh create mode 100644 tests/gnu/execdir_path_relative.sh create mode 100644 tests/gnu/okdir_path_dot.sh create mode 100644 tests/gnu/okdir_path_empty.sh create mode 100644 tests/gnu/okdir_path_relative.sh (limited to 'tests/gnu') diff --git a/src/parse.c b/src/parse.c index 09cfdd3..d21ab40 100644 --- a/src/parse.c +++ b/src/parse.c @@ -1263,6 +1263,28 @@ static struct bfs_expr *parse_exec(struct parser_state *state, int flags, int ar expr->ephemeral_fds = 2; if (execbuf->flags & BFS_EXEC_CHDIR) { + // Check for relative paths in $PATH + const char *path = getenv("PATH"); + while (path) { + if (*path != '/') { + size_t len = strcspn(path, ":"); + char *comp = strndup(path, len); + if (comp) { + parse_expr_error(state, expr, + "This action would be unsafe, since ${bld}$$PATH${rs} contains the relative path ${bld}%pq${rs}\n", comp); + free(comp); + } else { + parse_perror(state, "strndup()"); + } + goto fail; + } + + path = strchr(path, ':'); + if (path) { + ++path; + } + } + // To dup() the parent directory if (execbuf->flags & BFS_EXEC_MULTI) { ++expr->persistent_fds; @@ -1276,6 +1298,10 @@ static struct bfs_expr *parse_exec(struct parser_state *state, int flags, int ar } return expr; + +fail: + bfs_expr_free(expr); + return NULL; } /** diff --git a/tests/gnu/execdir_path_dot.sh b/tests/gnu/execdir_path_dot.sh new file mode 100644 index 0000000..632dbb4 --- /dev/null +++ b/tests/gnu/execdir_path_dot.sh @@ -0,0 +1 @@ +! PATH=".:$PATH" invoke_bfs basic -execdir echo {} + diff --git a/tests/gnu/execdir_path_empty.sh b/tests/gnu/execdir_path_empty.sh new file mode 100644 index 0000000..eda6b1c --- /dev/null +++ b/tests/gnu/execdir_path_empty.sh @@ -0,0 +1 @@ +! PATH=":$PATH" invoke_bfs basic -execdir echo {} + diff --git a/tests/gnu/execdir_path_relative.sh b/tests/gnu/execdir_path_relative.sh new file mode 100644 index 0000000..69899ad --- /dev/null +++ b/tests/gnu/execdir_path_relative.sh @@ -0,0 +1 @@ +! PATH="foo:$PATH" invoke_bfs basic -execdir echo {} + diff --git a/tests/gnu/okdir_path_dot.sh b/tests/gnu/okdir_path_dot.sh new file mode 100644 index 0000000..5b40e27 --- /dev/null +++ b/tests/gnu/okdir_path_dot.sh @@ -0,0 +1 @@ +! PATH=".:$PATH" invoke_bfs basic -okdir echo {} \; diff --git a/tests/gnu/okdir_path_empty.sh b/tests/gnu/okdir_path_empty.sh new file mode 100644 index 0000000..2669ee8 --- /dev/null +++ b/tests/gnu/okdir_path_empty.sh @@ -0,0 +1 @@ +! PATH=":$PATH" invoke_bfs basic -okdir echo {} \; diff --git a/tests/gnu/okdir_path_relative.sh b/tests/gnu/okdir_path_relative.sh new file mode 100644 index 0000000..05100a1 --- /dev/null +++ b/tests/gnu/okdir_path_relative.sh @@ -0,0 +1 @@ +! PATH="foo:$PATH" invoke_bfs basic -okdir echo {} \; -- cgit v1.2.3 From fb4760db85c552b0f538f7af2ad40fa631c20540 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Wed, 15 Nov 2023 09:45:49 -0500 Subject: tests: Fix a possible infinite loop The POSIX spec for readdir() [1] says: > If a file is removed from or added to the directory after the most > recent call to opendir() or rewinddir(), whether a subsequent call > to readdir() returns an entry for that file is unspecified. which implies that a loop of readdir()/unlink()/creat() may continue to return new files unendingly. This was even observed on a Linux 6.6 tmpfs mount [2]. It's not clear whether find(1) is also permitted to loop endlessly in this case, but in case it is, let's avoid the whole problem by limiting the -exec to happen at most once. [1]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/readdir.html [2]: https://lore.kernel.org/linux-fsdevel/20231113180616.2831430-1-tavianator@tavianator.com/ --- tests/gnu/ignore_readdir_race_notdir.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'tests/gnu') diff --git a/tests/gnu/ignore_readdir_race_notdir.sh b/tests/gnu/ignore_readdir_race_notdir.sh index 8b03164..12e9fe6 100644 --- a/tests/gnu/ignore_readdir_race_notdir.sh +++ b/tests/gnu/ignore_readdir_race_notdir.sh @@ -1,5 +1,7 @@ # Check -ignore_readdir_race handling when a directory is replaced with a file cd "$TEST" -"$XTOUCH" -p foo/bar +mkdir foo -invoke_bfs . -mindepth 1 -ignore_readdir_race -execdir rm -r {} \; -execdir "$XTOUCH" {} \; +invoke_bfs . -mindepth 1 -ignore_readdir_race \ + -type d -execdir rmdir {} \; \ + -execdir "$XTOUCH" {} \; -- cgit v1.2.3 From c4334184502c25a41b5cab060681229b2b570c0a Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Thu, 1 Feb 2024 16:14:19 -0500 Subject: tests: Don't clobber inherited FDs Rather than attempting to close any unexpected FDs, just count them and adjust our ulimit -n calls to account for them. --- .github/workflows/ci.yml | 1 + tests/bfs/deep_strict.sh | 2 +- tests/common/execdir_ulimit.sh | 2 +- tests/gnu/execdir_ulimit.out | 32 ++++++++++++++++---------------- tests/gnu/execdir_ulimit.sh | 2 +- tests/gnu/printf_u_g_ulimit.sh | 2 +- tests/posix/deep.sh | 2 +- tests/posix/exec_ulimit.out | 32 ++++++++++++++++---------------- tests/posix/exec_ulimit.sh | 2 +- tests/posix/nogroup_ulimit.sh | 2 +- tests/posix/nouser_ulimit.sh | 2 +- tests/util.sh | 17 +++++------------ 12 files changed, 46 insertions(+), 52 deletions(-) (limited to 'tests/gnu') diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ff0ff6f..8e96526 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -86,6 +86,7 @@ jobs: tcl-wrapper pw useradd -n action -m -G wheel -s /usr/local/bin/bash echo "%wheel ALL=(ALL) NOPASSWD: ALL" >>/usr/local/etc/sudoers + mount -t fdescfs none /dev/fd run: | chown -R action:action . diff --git a/tests/bfs/deep_strict.sh b/tests/bfs/deep_strict.sh index 50c8f05..22453c0 100644 --- a/tests/bfs/deep_strict.sh +++ b/tests/bfs/deep_strict.sh @@ -1,3 +1,3 @@ # Not even enough fds to keep the root open -ulimit -n 7 +ulimit -n $((NOPENFD + 4)) bfs_diff deep -type f -exec bash -c 'echo "${1:0:6}/.../${1##*/} (${#1})"' bash {} \; diff --git a/tests/common/execdir_ulimit.sh b/tests/common/execdir_ulimit.sh index 90c93c1..122c282 100644 --- a/tests/common/execdir_ulimit.sh +++ b/tests/common/execdir_ulimit.sh @@ -2,5 +2,5 @@ cd "$TEST" mkdir -p a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z mkdir -p a/b/c/d/e/f/g/h/i/j/k/l/m/0/1/2/3/4/5/6/7/8/9/A/B/C -ulimit -n 13 +ulimit -n $((NOPENFD + 10)) bfs_diff . -execdir echo {} \; diff --git a/tests/gnu/execdir_ulimit.out b/tests/gnu/execdir_ulimit.out index 7931f9a..6749f7d 100644 --- a/tests/gnu/execdir_ulimit.out +++ b/tests/gnu/execdir_ulimit.out @@ -1,16 +1,16 @@ -16 ./0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE -16 ./0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE -16 ./0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE -16 ./0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE -16 ./0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE -16 ./0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE -16 ./0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE -16 ./0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE -16 ./0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE -16 ./0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE -16 ./0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE -16 ./0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE -16 ./0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE -16 ./0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE -16 ./0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE -16 ./0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +64 ./0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +64 ./0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +64 ./0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +64 ./0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +64 ./0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +64 ./0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +64 ./0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +64 ./0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +64 ./0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +64 ./0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +64 ./0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +64 ./0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +64 ./0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +64 ./0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +64 ./0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +64 ./0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE diff --git a/tests/gnu/execdir_ulimit.sh b/tests/gnu/execdir_ulimit.sh index 3245dad..e14e716 100644 --- a/tests/gnu/execdir_ulimit.sh +++ b/tests/gnu/execdir_ulimit.sh @@ -1,2 +1,2 @@ -ulimit -Sn 16 +ulimit -Sn 64 bfs_diff deep -type f -execdir bash -c 'printf "%d %s\n" $(ulimit -Sn) "$1"' bash {} \; diff --git a/tests/gnu/printf_u_g_ulimit.sh b/tests/gnu/printf_u_g_ulimit.sh index 390ad48..c621b9b 100644 --- a/tests/gnu/printf_u_g_ulimit.sh +++ b/tests/gnu/printf_u_g_ulimit.sh @@ -1,2 +1,2 @@ -ulimit -n 16 +ulimit -n $((NOPENFD + 13)) [ "$(invoke_bfs deep -printf '%u %g\n' | uniq)" = "$(id -un) $(id -gn)" ] diff --git a/tests/posix/deep.sh b/tests/posix/deep.sh index 431705e..36a88c0 100644 --- a/tests/posix/deep.sh +++ b/tests/posix/deep.sh @@ -1,2 +1,2 @@ -ulimit -n 16 +ulimit -n $((NOPENFD + 13)) bfs_diff deep -type f -exec bash -c 'echo "${1:0:6}/.../${1##*/} (${#1})"' bash {} \; diff --git a/tests/posix/exec_ulimit.out b/tests/posix/exec_ulimit.out index 587ece2..144169e 100644 --- a/tests/posix/exec_ulimit.out +++ b/tests/posix/exec_ulimit.out @@ -1,16 +1,16 @@ -16 deep/0/.../0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE -16 deep/1/.../0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE -16 deep/2/.../0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE -16 deep/3/.../0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE -16 deep/4/.../0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE -16 deep/5/.../0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE -16 deep/6/.../0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE -16 deep/7/.../0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE -16 deep/8/.../0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE -16 deep/9/.../0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE -16 deep/A/.../0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE -16 deep/B/.../0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE -16 deep/C/.../0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE -16 deep/D/.../0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE -16 deep/E/.../0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE -16 deep/F/.../0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +64 deep/0/.../0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +64 deep/1/.../0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +64 deep/2/.../0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +64 deep/3/.../0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +64 deep/4/.../0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +64 deep/5/.../0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +64 deep/6/.../0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +64 deep/7/.../0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +64 deep/8/.../0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +64 deep/9/.../0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +64 deep/A/.../0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +64 deep/B/.../0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +64 deep/C/.../0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +64 deep/D/.../0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +64 deep/E/.../0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE +64 deep/F/.../0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE diff --git a/tests/posix/exec_ulimit.sh b/tests/posix/exec_ulimit.sh index 8ac8ff1..655fbec 100644 --- a/tests/posix/exec_ulimit.sh +++ b/tests/posix/exec_ulimit.sh @@ -1,2 +1,2 @@ -ulimit -Sn 16 +ulimit -Sn 64 bfs_diff deep -type f -exec bash -c 'printf "%d %s\n" $(ulimit -Sn) "${1:0:6}/.../${1##*/}"' bash {} \; diff --git a/tests/posix/nogroup_ulimit.sh b/tests/posix/nogroup_ulimit.sh index 5b4c440..a39dd1f 100644 --- a/tests/posix/nogroup_ulimit.sh +++ b/tests/posix/nogroup_ulimit.sh @@ -1,2 +1,2 @@ -ulimit -n 16 +ulimit -n $((NOPENFD + 13)) bfs_diff deep -type f -nogroup diff --git a/tests/posix/nouser_ulimit.sh b/tests/posix/nouser_ulimit.sh index e1400f0..a94b8c5 100644 --- a/tests/posix/nouser_ulimit.sh +++ b/tests/posix/nouser_ulimit.sh @@ -1,2 +1,2 @@ -ulimit -n 16 +ulimit -n $((NOPENFD + 13)) bfs_diff deep -type f -nouser diff --git a/tests/util.sh b/tests/util.sh index 686cc77..ec24958 100644 --- a/tests/util.sh +++ b/tests/util.sh @@ -48,23 +48,16 @@ stdenv() { export MallocNanoZone=0 fi - # Close non-standard inherited fds + # Count the inherited FDs if [ -d /proc/self/fd ]; then local fds=/proc/self/fd else local fds=/dev/fd fi - - for fd in "$fds"/*; do - if [ ! -e "$fd" ]; then - continue - fi - - local fd="${fd##*/}" - if ((fd > 2)); then - eval "exec ${fd}<&-" - fi - done + # We use ls $fds on purpose, rather than e.g. ($fds/*), to avoid counting + # internal bash fds that are not exposed to spawned processes + NOPENFD=$(ls -1q "$fds/" 2>/dev/null | wc -l) + NOPENFD=$((NOPENFD > 3 ? NOPENFD - 1 : 3)) # Close stdin so bfs doesn't think we're interactive # dup() the standard fds for logging even when redirected -- cgit v1.2.3 From 416ca3b557055efa5746a4d40d927391c59a9292 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Thu, 7 Mar 2024 16:01:46 -0500 Subject: tests: Change the timezone for -daystart tests Otherwise, if the test files are created just before midnight, and the test runs just after midnight, -daystart will consider them one day old. Fixes #132 --- tests/gnu/daystart.sh | 2 +- tests/gnu/daystart_twice.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/gnu') diff --git a/tests/gnu/daystart.sh b/tests/gnu/daystart.sh index 9799bca..9c3be1a 100644 --- a/tests/gnu/daystart.sh +++ b/tests/gnu/daystart.sh @@ -1 +1 @@ -bfs_diff basic -daystart -mtime 0 +TZ=WAT-1 bfs_diff basic -daystart -mtime 0 diff --git a/tests/gnu/daystart_twice.sh b/tests/gnu/daystart_twice.sh index 21b2c0f..edbf18d 100644 --- a/tests/gnu/daystart_twice.sh +++ b/tests/gnu/daystart_twice.sh @@ -1 +1 @@ -bfs_diff basic -daystart -daystart -mtime 0 +TZ=WAT-1 bfs_diff basic -daystart -daystart -mtime 0 -- cgit v1.2.3 From 2fc0b4425197099ba5575d3b50ac77b51c0e0a95 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Thu, 28 Mar 2024 11:38:33 -0400 Subject: tests/gnu: Add a -used test --- tests/gnu/used.out | 4 ++++ tests/gnu/used.sh | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 tests/gnu/used.out create mode 100644 tests/gnu/used.sh (limited to 'tests/gnu') diff --git a/tests/gnu/used.out b/tests/gnu/used.out new file mode 100644 index 0000000..647621b --- /dev/null +++ b/tests/gnu/used.out @@ -0,0 +1,4 @@ +-used +7: ./nextyear +-used 1: ./tomorrow +-used 2: ./dayafter +-used 7: ./nextweek diff --git a/tests/gnu/used.sh b/tests/gnu/used.sh new file mode 100644 index 0000000..5e5d4e9 --- /dev/null +++ b/tests/gnu/used.sh @@ -0,0 +1,40 @@ +iso8601() { + printf '%04d-%02d-%02dT%02d:%02d:%02d\n' "$@" +} + +cd "$TEST" + +now=$(date '+%Y-%m-%dT%H:%M:%S') + +# Parse the current date +[[ "$now" =~ ^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})$ ]] || fail +# Treat leading zeros as decimal, not octal +YYYY=$((10#${BASH_REMATCH[1]})) +MM=$((10#${BASH_REMATCH[2]})) +DD=$((10#${BASH_REMATCH[3]})) +hh=$((10#${BASH_REMATCH[4]})) +mm=$((10#${BASH_REMATCH[5]})) +ss=$((10#${BASH_REMATCH[6]})) + +# -used is always false if atime < ctime +yesterday=$(iso8601 $YYYY $MM $((DD - 1)) $hh $mm $ss) +"$XTOUCH" -at "$yesterday" yesterday + +# -used rounds up +tomorrow=$(iso8601 $YYYY $MM $DD $((hh + 1)) $mm $ss) +"$XTOUCH" -at "$tomorrow" tomorrow + +dayafter=$(iso8601 $YYYY $MM $((DD + 1)) $((hh + 1)) $mm $ss) +"$XTOUCH" -at "$dayafter" dayafter + +nextweek=$(iso8601 $YYYY $MM $((DD + 6)) $((hh + 1)) $mm $ss) +"$XTOUCH" -at "$nextweek" nextweek + +nextyear=$(iso8601 $((YYYY + 1)) $MM $DD $hh $mm $ss) +"$XTOUCH" -at "$nextyear" nextyear + +bfs_diff -mindepth 1 \ + -a -used 1 -printf '-used 1: %p\n' \ + -o -used 2 -printf '-used 2: %p\n' \ + -o -used 7 -printf '-used 7: %p\n' \ + -o -used +7 -printf '-used +7: %p\n' -- cgit v1.2.3 From d0804fcf6b690de364c35d8354b21f72422df079 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Tue, 9 Apr 2024 20:47:11 -0400 Subject: tests: Move newer_link out of posix/ POSIX has clarified that it's unspecified whether -newer uses times from stat() or lstat(), because implementations vary. It does specify that it must fall back to lstat() for broken links, so test that. Link: https://austingroupbugs.net/view.php?id=1776 --- tests/gnu/newer_link.out | 1 + tests/gnu/newer_link.sh | 1 + tests/posix/newer_broken.out | 1 + tests/posix/newer_broken.sh | 4 ++++ tests/posix/newer_link.out | 1 - tests/posix/newer_link.sh | 1 - 6 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 tests/gnu/newer_link.out create mode 100644 tests/gnu/newer_link.sh create mode 100644 tests/posix/newer_broken.out create mode 100644 tests/posix/newer_broken.sh delete mode 100644 tests/posix/newer_link.out delete mode 100644 tests/posix/newer_link.sh (limited to 'tests/gnu') diff --git a/tests/gnu/newer_link.out b/tests/gnu/newer_link.out new file mode 100644 index 0000000..d2dcdd1 --- /dev/null +++ b/tests/gnu/newer_link.out @@ -0,0 +1 @@ +times diff --git a/tests/gnu/newer_link.sh b/tests/gnu/newer_link.sh new file mode 100644 index 0000000..685ac78 --- /dev/null +++ b/tests/gnu/newer_link.sh @@ -0,0 +1 @@ +bfs_diff times -newer times/l diff --git a/tests/posix/newer_broken.out b/tests/posix/newer_broken.out new file mode 100644 index 0000000..d2dcdd1 --- /dev/null +++ b/tests/posix/newer_broken.out @@ -0,0 +1 @@ +times diff --git a/tests/posix/newer_broken.sh b/tests/posix/newer_broken.sh new file mode 100644 index 0000000..dccaa73 --- /dev/null +++ b/tests/posix/newer_broken.sh @@ -0,0 +1,4 @@ +ln -s nowhere "$TEST/broken" +"$XTOUCH" -h -t "1991-12-14 00:03" "$TEST/broken" + +bfs_diff times -newer "$TEST/broken" diff --git a/tests/posix/newer_link.out b/tests/posix/newer_link.out deleted file mode 100644 index d2dcdd1..0000000 --- a/tests/posix/newer_link.out +++ /dev/null @@ -1 +0,0 @@ -times diff --git a/tests/posix/newer_link.sh b/tests/posix/newer_link.sh deleted file mode 100644 index 685ac78..0000000 --- a/tests/posix/newer_link.sh +++ /dev/null @@ -1 +0,0 @@ -bfs_diff times -newer times/l -- cgit v1.2.3 From d597be5bc1ee0e76117037b7d9a52c52fd4531ad Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Wed, 24 Apr 2024 11:07:33 -0400 Subject: eval: Plug memory leak if bfs_opendir() fails --- src/eval.c | 40 ++++++++++++++++++++++------------------ tests/common/empty.out | 8 ++++++++ tests/common/empty.sh | 1 + tests/common/empty_error.out | 3 +++ tests/common/empty_error.sh | 7 +++++++ tests/common/empty_special.out | 20 ++++++++++++++++++++ tests/common/empty_special.sh | 1 + tests/gnu/empty.out | 8 -------- tests/gnu/empty.sh | 1 - tests/gnu/empty_special.out | 20 -------------------- tests/gnu/empty_special.sh | 1 - 11 files changed, 62 insertions(+), 48 deletions(-) create mode 100644 tests/common/empty.out create mode 100644 tests/common/empty.sh create mode 100644 tests/common/empty_error.out create mode 100644 tests/common/empty_error.sh create mode 100644 tests/common/empty_special.out create mode 100644 tests/common/empty_special.sh delete mode 100644 tests/gnu/empty.out delete mode 100644 tests/gnu/empty.sh delete mode 100644 tests/gnu/empty_special.out delete mode 100644 tests/gnu/empty_special.sh (limited to 'tests/gnu') diff --git a/src/eval.c b/src/eval.c index b103912..49028b7 100644 --- a/src/eval.c +++ b/src/eval.c @@ -445,38 +445,42 @@ bool eval_depth(const struct bfs_expr *expr, struct bfs_eval *state) { * -empty test. */ bool eval_empty(const struct bfs_expr *expr, struct bfs_eval *state) { - bool ret = false; const struct BFTW *ftwbuf = state->ftwbuf; + const struct bfs_stat *statbuf; + struct bfs_dir *dir; + + switch (ftwbuf->type) { + case BFS_REG: + statbuf = eval_stat(state); + return statbuf && statbuf->size == 0; - if (ftwbuf->type == BFS_DIR) { - struct bfs_dir *dir = bfs_allocdir(); + case BFS_DIR: + dir = bfs_allocdir(); if (!dir) { - eval_report_error(state); - return ret; + goto error; } if (bfs_opendir(dir, ftwbuf->at_fd, ftwbuf->at_path, 0) != 0) { - eval_report_error(state); - return ret; + goto error; } int did_read = bfs_readdir(dir, NULL); + bfs_closedir(dir); + if (did_read < 0) { - eval_report_error(state); - } else { - ret = !did_read; + goto error; } - bfs_closedir(dir); free(dir); - } else if (ftwbuf->type == BFS_REG) { - const struct bfs_stat *statbuf = eval_stat(state); - if (statbuf) { - ret = statbuf->size == 0; - } - } + return did_read == 0; + error: + eval_report_error(state); + free(dir); + return false; - return ret; + default: + return false; + } } /** diff --git a/tests/common/empty.out b/tests/common/empty.out new file mode 100644 index 0000000..a0f4b76 --- /dev/null +++ b/tests/common/empty.out @@ -0,0 +1,8 @@ +basic/a +basic/b +basic/c/d +basic/e/f +basic/g/h +basic/i +basic/j/foo +basic/k/foo/bar diff --git a/tests/common/empty.sh b/tests/common/empty.sh new file mode 100644 index 0000000..95ee988 --- /dev/null +++ b/tests/common/empty.sh @@ -0,0 +1 @@ +bfs_diff basic -empty diff --git a/tests/common/empty_error.out b/tests/common/empty_error.out new file mode 100644 index 0000000..da45e23 --- /dev/null +++ b/tests/common/empty_error.out @@ -0,0 +1,3 @@ +./bar +./baz +./qux diff --git a/tests/common/empty_error.sh b/tests/common/empty_error.sh new file mode 100644 index 0000000..7c8049c --- /dev/null +++ b/tests/common/empty_error.sh @@ -0,0 +1,7 @@ +cd "$TEST" + +"$XTOUCH" -p foo/ bar/ baz qux +chmod -r foo baz +defer chmod +r foo baz + +! bfs_diff . -empty diff --git a/tests/common/empty_special.out b/tests/common/empty_special.out new file mode 100644 index 0000000..fa35478 --- /dev/null +++ b/tests/common/empty_special.out @@ -0,0 +1,20 @@ +rainbow// +rainbow/exec.sh +rainbow/file.dat +rainbow/file.txt +rainbow/lower.gz +rainbow/lower.tar +rainbow/lower.tar.gz +rainbow/lu.tar.GZ +rainbow/mh1 +rainbow/mh2 +rainbow/ow +rainbow/sgid +rainbow/sticky +rainbow/sticky_ow +rainbow/sugid +rainbow/suid +rainbow/ul.TAR.gz +rainbow/upper.GZ +rainbow/upper.TAR +rainbow/upper.TAR.GZ diff --git a/tests/common/empty_special.sh b/tests/common/empty_special.sh new file mode 100644 index 0000000..31e9d2e --- /dev/null +++ b/tests/common/empty_special.sh @@ -0,0 +1 @@ +bfs_diff rainbow -empty diff --git a/tests/gnu/empty.out b/tests/gnu/empty.out deleted file mode 100644 index a0f4b76..0000000 --- a/tests/gnu/empty.out +++ /dev/null @@ -1,8 +0,0 @@ -basic/a -basic/b -basic/c/d -basic/e/f -basic/g/h -basic/i -basic/j/foo -basic/k/foo/bar diff --git a/tests/gnu/empty.sh b/tests/gnu/empty.sh deleted file mode 100644 index 95ee988..0000000 --- a/tests/gnu/empty.sh +++ /dev/null @@ -1 +0,0 @@ -bfs_diff basic -empty diff --git a/tests/gnu/empty_special.out b/tests/gnu/empty_special.out deleted file mode 100644 index fa35478..0000000 --- a/tests/gnu/empty_special.out +++ /dev/null @@ -1,20 +0,0 @@ -rainbow// -rainbow/exec.sh -rainbow/file.dat -rainbow/file.txt -rainbow/lower.gz -rainbow/lower.tar -rainbow/lower.tar.gz -rainbow/lu.tar.GZ -rainbow/mh1 -rainbow/mh2 -rainbow/ow -rainbow/sgid -rainbow/sticky -rainbow/sticky_ow -rainbow/sugid -rainbow/suid -rainbow/ul.TAR.gz -rainbow/upper.GZ -rainbow/upper.TAR -rainbow/upper.TAR.GZ diff --git a/tests/gnu/empty_special.sh b/tests/gnu/empty_special.sh deleted file mode 100644 index 31e9d2e..0000000 --- a/tests/gnu/empty_special.sh +++ /dev/null @@ -1 +0,0 @@ -bfs_diff rainbow -empty -- cgit v1.2.3