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/common/L_ilname.sh | 2 +- tests/common/L_mount.sh | 4 ++-- tests/common/ilname.sh | 2 +- tests/common/iname.sh | 2 +- tests/common/inum_bind_mount.sh | 4 ++-- tests/common/inum_mount.sh | 4 ++-- tests/common/ipath.sh | 2 +- tests/common/mount.sh | 4 ++-- 8 files changed, 12 insertions(+), 12 deletions(-) (limited to 'tests/common') diff --git a/tests/common/L_ilname.sh b/tests/common/L_ilname.sh index cfb15a8..e0495ed 100644 --- a/tests/common/L_ilname.sh +++ b/tests/common/L_ilname.sh @@ -1,2 +1,2 @@ -skip_unless invoke_bfs -quit -ilname PATTERN +invoke_bfs -quit -ilname PATTERN || skip bfs_diff -L links -ilname '[AQ]' diff --git a/tests/common/L_mount.sh b/tests/common/L_mount.sh index dad7e00..5b56762 100644 --- a/tests/common/L_mount.sh +++ b/tests/common/L_mount.sh @@ -1,5 +1,5 @@ -skip_unless test "$SUDO" -skip_if test "$UNAME" = "Darwin" +test "$SUDO" || skip +test "$UNAME" = "Darwin" && skip clean_scratch mkdir scratch/{foo,mnt} diff --git a/tests/common/ilname.sh b/tests/common/ilname.sh index 7ab0793..fc7e9e4 100644 --- a/tests/common/ilname.sh +++ b/tests/common/ilname.sh @@ -1,2 +1,2 @@ -skip_unless invoke_bfs -quit -ilname PATTERN +invoke_bfs -quit -ilname PATTERN || skip bfs_diff links -ilname '[AQ]' diff --git a/tests/common/iname.sh b/tests/common/iname.sh index 8fcc443..c25a646 100644 --- a/tests/common/iname.sh +++ b/tests/common/iname.sh @@ -1,2 +1,2 @@ -skip_unless invoke_bfs -quit -iname PATTERN +invoke_bfs -quit -iname PATTERN || skip bfs_diff basic -iname '*F*' diff --git a/tests/common/inum_bind_mount.sh b/tests/common/inum_bind_mount.sh index e35ed4e..a9e01bf 100644 --- a/tests/common/inum_bind_mount.sh +++ b/tests/common/inum_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/{foo,bar} diff --git a/tests/common/inum_mount.sh b/tests/common/inum_mount.sh index f9f4e2b..7cc5e40 100644 --- a/tests/common/inum_mount.sh +++ b/tests/common/inum_mount.sh @@ -1,5 +1,5 @@ -skip_unless test "$SUDO" -skip_if test "$UNAME" = "Darwin" +test "$SUDO" || skip +test "$UNAME" = "Darwin" && skip clean_scratch mkdir scratch/{foo,mnt} diff --git a/tests/common/ipath.sh b/tests/common/ipath.sh index 9e6f8c5..7d05f31 100644 --- a/tests/common/ipath.sh +++ b/tests/common/ipath.sh @@ -1,2 +1,2 @@ -skip_unless invoke_bfs -quit -ipath PATTERN +invoke_bfs -quit -ipath PATTERN || skip bfs_diff basic -ipath 'basic/*F*' diff --git a/tests/common/mount.sh b/tests/common/mount.sh index 2732a68..f077ea2 100644 --- a/tests/common/mount.sh +++ b/tests/common/mount.sh @@ -1,5 +1,5 @@ -skip_unless test "$SUDO" -skip_if test "$UNAME" = "Darwin" +test "$SUDO" || skip +test "$UNAME" = "Darwin" && skip clean_scratch mkdir scratch/{foo,mnt} -- 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/common') 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/common') 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/common') 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 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/common') 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 377709664480a30fa5acdd11c7ca8c16669678ce Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Wed, 6 Sep 2023 14:59:59 -0400 Subject: bfstd: Fix an OOB string index in xmbrtowc() This bug could be reproduced with something like $ bfs -samefile $'\xFA\xFA' bfs: error: bfs: dstrnescat@src/dstring.c:252: wordesc() result truncated or worse, with -DNDEBUG, $ bfs -samefile $'.....................\xFA\xFA' bfs: error: bfs -samefile $'.....................\xFA\xFA\x00\x55\x53\x45\x52\x3D\x74\x61\x76\x69\x61\x6E\x61\x74\x6F\x72 bfs: error: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ bfs: error: No such file or directory. which prints the memory after the end of the string (in this case, the environment variable USER=tavianator). The bug was caused by the line `*i += len`, which was intended to be `*i = len`. But actually, the right behaviour seems to be `*i += 1`. Fixes: 19c96abe0a1ee56cf206fd5e87defb1fd3e0daa5 --- src/bfstd.c | 8 ++------ tests/bfstd.c | 18 ++++++++++++++++++ tests/common/samefile_wordesc.sh | 4 ++++ 3 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 tests/common/samefile_wordesc.sh (limited to 'tests/common') diff --git a/src/bfstd.c b/src/bfstd.c index e546a47..2d9f60a 100644 --- a/src/bfstd.c +++ b/src/bfstd.c @@ -546,15 +546,11 @@ int xstrtofflags(const char **str, unsigned long long *set, unsigned long long * static int xmbrtowc(wchar_t *wc, size_t *i, const char *str, size_t len, mbstate_t *mb) { size_t mblen = mbrtowc(wc, str + *i, len - *i, mb); switch (mblen) { - case -1: - // Invalid byte sequence + case -1: // Invalid byte sequence + case -2: // Incomplete byte sequence *i += 1; memset(mb, 0, sizeof(*mb)); return -1; - case -2: - // Incomplete byte sequence - *i += len; - return -1; default: *i += mblen; return 0; diff --git a/tests/bfstd.c b/tests/bfstd.c index fa854a8..2db084a 100644 --- a/tests/bfstd.c +++ b/tests/bfstd.c @@ -23,6 +23,15 @@ static void check_base_dir(const char *path, const char *dir, const char *base) free(xbase); } +/** Check the result of wordesc(). */ +static void check_wordesc(const char *str, const char *exp, enum wesc_flags flags) { + char buf[256]; + char *end = buf + sizeof(buf); + char *ret = wordesc(buf, end, str, flags); + bfs_verify(ret != end); + bfs_verify(strcmp(buf, exp) == 0, "wordesc(%s) == %s (!= %s)", str, buf, exp); +} + int main(void) { // From man 3p basename check_base_dir("usr", ".", "usr"); @@ -36,5 +45,14 @@ int main(void) { check_base_dir("//usr//lib//", "//usr", "lib"); check_base_dir("/home//dwc//test", "/home//dwc", "test"); + check_wordesc("", "\"\"", WESC_SHELL); + check_wordesc("word", "word", WESC_SHELL); + check_wordesc("two words", "\"two words\"", WESC_SHELL); + check_wordesc("word's", "\"word's\"", WESC_SHELL); + check_wordesc("\"word\"", "'\"word\"'", WESC_SHELL); + check_wordesc("\"word's\"", "'\"word'\\''s\"'", WESC_SHELL); + check_wordesc("\033[1mbold's\033[0m", "$'\\e[1mbold\\'s\\e[0m'", WESC_SHELL | WESC_TTY); + check_wordesc("\x7F", "$'\\x7F'", WESC_SHELL | WESC_TTY); + return EXIT_SUCCESS; } diff --git a/tests/common/samefile_wordesc.sh b/tests/common/samefile_wordesc.sh new file mode 100644 index 0000000..b5d158f --- /dev/null +++ b/tests/common/samefile_wordesc.sh @@ -0,0 +1,4 @@ +# Regression test: don't abort on incomplete UTF-8 sequences +export LC_ALL=$(locale -a | grep -Ei 'utf-?8$' | head -n1) +test -n "$LC_ALL" || skip +! invoke_bfs -samefile $'\xFA\xFA' -- 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/common') 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/common') 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/common') 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 de8e0fbb8c1e59b3f1af72a07477b63a8f0bbc75 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Mon, 23 Oct 2023 11:42:33 -0400 Subject: tests: Fix Bash 3 compatibility --- tests/bfs/execdir_plus_nonexistent.sh | 6 ++--- tests/common/execdir_nonexistent.sh | 6 ++--- tests/posix/L_loops.sh | 4 ++-- tests/posix/exec_nonexistent.sh | 7 ++---- tests/posix/exec_plus_nonexistent.sh | 6 ++--- tests/run.sh | 44 +++++++++++++++++++++++++---------- tests/util.sh | 11 ++++----- 7 files changed, 47 insertions(+), 37 deletions(-) (limited to 'tests/common') diff --git a/tests/bfs/execdir_plus_nonexistent.sh b/tests/bfs/execdir_plus_nonexistent.sh index e3b4d2d..ed7ed56 100644 --- a/tests/bfs/execdir_plus_nonexistent.sh +++ b/tests/bfs/execdir_plus_nonexistent.sh @@ -1,4 +1,2 @@ -! stderr=$(invoke_bfs basic -execdir "$TESTS/nonexistent" {} + 2>&1 >/dev/null) -[ -n "$stderr" ] - -! bfs_diff basic -execdir "$TESTS/nonexistent" {} + -print +bfs_diff basic -execdir "$TESTS/nonexistent" {} + -print 2>"$TEST/err" && fail +test -s "$TEST/err" diff --git a/tests/common/execdir_nonexistent.sh b/tests/common/execdir_nonexistent.sh index 4bb4fdb..0ec013c 100644 --- a/tests/common/execdir_nonexistent.sh +++ b/tests/common/execdir_nonexistent.sh @@ -1,4 +1,2 @@ -! stderr=$(invoke_bfs basic -execdir "$TESTS/nonexistent" {} \; 2>&1 >/dev/null) -[ -n "$stderr" ] - -! bfs_diff basic -print -execdir "$TESTS/nonexistent" {} \; -print +bfs_diff basic -print -execdir "$TESTS/nonexistent" {} \; -print 2>"$TEST/err" && fail +test -s "$TEST/err" diff --git a/tests/posix/L_loops.sh b/tests/posix/L_loops.sh index 1314401..01b7efc 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) -[ -n "$errors" ] +invoke_bfs -L loops >/dev/null 2>"$OUT" && fail +test -s "$OUT" diff --git a/tests/posix/exec_nonexistent.sh b/tests/posix/exec_nonexistent.sh index 901be86..a9ff052 100644 --- a/tests/posix/exec_nonexistent.sh +++ b/tests/posix/exec_nonexistent.sh @@ -1,7 +1,4 @@ # 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" ] - -! bfs_diff basic -print -exec "$TESTS/nonexistent" {} \; -print +bfs_diff basic -print -exec "$TESTS/nonexistent" {} \; -print 2>"$TEST/err" && fail +test -s "$TEST/err" diff --git a/tests/posix/exec_plus_nonexistent.sh b/tests/posix/exec_plus_nonexistent.sh index 6bddc67..24582a3 100644 --- a/tests/posix/exec_plus_nonexistent.sh +++ b/tests/posix/exec_plus_nonexistent.sh @@ -1,4 +1,2 @@ -! stderr=$(invoke_bfs basic -exec "$TESTS/nonexistent" {} + 2>&1 >/dev/null) -[ -n "$stderr" ] - -! bfs_diff basic -exec "$TESTS/nonexistent" {} + -print +bfs_diff basic -exec "$TESTS/nonexistent" {} + -print 2>"$TEST/err" && fail +test -s "$TEST/err" diff --git a/tests/run.sh b/tests/run.sh index b46fde6..d581476 100644 --- a/tests/run.sh +++ b/tests/run.sh @@ -47,7 +47,7 @@ bg_test() { if ((VERBOSE_ERRORS)); then run_test "$1" else - run_test "$1" 2>"$TMP/TEST.err" + run_test "$1" 2>"$TMP/$TEST.err" fi ret=$? @@ -59,9 +59,21 @@ bg_test() { return $ret } -# Reap a background job -reap() { - wait -n +# Wait for any background job to complete +if ((BASH_VERSINFO[0] > 4 || (BASH_VERSINFO[0] == 4 && BASH_VERSINFO[1] >= 3))); then + wait_any() { + wait -n + } +else + wait_any() { + read -ra jobs < <(jobs -p) + wait ${jobs[0]} + } +fi + +# Wait for a background test to finish +wait_test() { + wait_any ret=$? ((BG--)) @@ -118,7 +130,7 @@ run_tests() { OUT="$TMP/$TEST.out" if ((BG >= JOBS)); then - reap + wait_test fi ((++BG)) @@ -126,7 +138,7 @@ run_tests() { done while ((BG > 0)); do - reap + wait_test done printf "${BOL}" @@ -145,6 +157,14 @@ run_tests() { ## Utilities for the tests themselves +# Default return value for failed tests +EX_FAIL=1 + +# Fail the current test +fail() { + exit $EX_FAIL +} + # Return value when a test is skipped EX_SKIP=77 @@ -166,9 +186,9 @@ skip() { # Run a command and check its exit status check_exit() { local expected="$1" - local actual="0" + local actual=0 shift - "$@" || actual="$?" + "$@" || actual=$? ((actual == expected)) } @@ -253,9 +273,9 @@ invoke_bfs() { # Allow bfs to fail, but not crash if ((ret > 125)); then - exit "$ret" + exit $ret else - return "$ret" + return $ret fi } @@ -275,9 +295,9 @@ bfs_pty() { "$UNBUFFER" bash -c 'stty cols 80 rows 24 && "$@"' bash "${BFS[@]}" "$@" || ret=$? if ((ret > 125)); then - exit "$ret" + exit $ret else - return "$ret" + return $ret fi } diff --git a/tests/util.sh b/tests/util.sh index 31a7b6c..bfa5d16 100644 --- a/tests/util.sh +++ b/tests/util.sh @@ -120,7 +120,7 @@ callers() { # Print a message including path, line number, and command debug() { - local file="${1/#*\/tests\//tests\/}" + local file="${1/#*\/tests\//tests/}" set -- "$file" "${@:2}" color printf "${BLD}%s:%d:${RST} %s\n %s\n" "$@" } @@ -136,14 +136,13 @@ quote() { fi } +DEFER_LEVEL=-1 + # 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 + if ((DEFER_LEVEL != BASH_SUBSHELL)); then + DEFER_LEVEL=$BASH_SUBSHELL DEFER_CMDS=() DEFER_LINES=() DEFER_FILES=() -- 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/common') 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 e6d80d04d6928c452b48eae717373bf6a943e355 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Thu, 29 Feb 2024 10:12:43 -0500 Subject: tests: Add more datetime parsing integration tests --- tests/common/newermt.sh | 4 +++- tests/xtime.c | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'tests/common') diff --git a/tests/common/newermt.sh b/tests/common/newermt.sh index 3c5be68..e816b29 100644 --- a/tests/common/newermt.sh +++ b/tests/common/newermt.sh @@ -1 +1,3 @@ -bfs_diff times -newermt 1991-12-14T00:01 +bfs_diff times -newermt 1991-12-14T00:01 \ + -newermt "1991-12-14 01:01+01:00" \ + -newermt "19911213 20:31:00-0330" diff --git a/tests/xtime.c b/tests/xtime.c index c2ee8f3..4a7d55c 100644 --- a/tests/xtime.c +++ b/tests/xtime.c @@ -94,10 +94,10 @@ static bool check_xgetdate(void) { & compare_xgetdate("1991-12-14T10:11Z", 0, 692705460) & compare_xgetdate("1991-12-14T10:11:12Z", 0, 692705472) & compare_xgetdate("1991-12-14T10:11:12?", EINVAL, 0) - & compare_xgetdate("1991-12-14T02-08", 0, 692704800) + & compare_xgetdate("1991-12-14T03-07", 0, 692704800) & compare_xgetdate("1991-12-14T06:41-03:30", 0, 692705460) - & compare_xgetdate("1991-12-14T02:11:12-08:00", 0, 692705472) - & compare_xgetdate("19911214 021112-0800", 0, 692705472); + & compare_xgetdate("1991-12-14T03:11:12-07:00", 0, 692705472) + & compare_xgetdate("19911214 031112-0700", 0, 692705472); } /** xmktime() tests. */ -- cgit v1.2.3 From 99a362d04b507c7c0436c06f087f3d0d3abdc665 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Thu, 28 Mar 2024 10:16:03 -0400 Subject: tests/common: Add a -delete error handling test --- tests/common/delete_error.out | 8 ++++++++ tests/common/delete_error.sh | 9 +++++++++ 2 files changed, 17 insertions(+) create mode 100644 tests/common/delete_error.out create mode 100644 tests/common/delete_error.sh (limited to 'tests/common') diff --git a/tests/common/delete_error.out b/tests/common/delete_error.out new file mode 100644 index 0000000..b6b6505 --- /dev/null +++ b/tests/common/delete_error.out @@ -0,0 +1,8 @@ +. +. +./baz +./baz +./baz/qux +./baz/qux +./foo +./foo/bar diff --git a/tests/common/delete_error.sh b/tests/common/delete_error.sh new file mode 100644 index 0000000..e6327f3 --- /dev/null +++ b/tests/common/delete_error.sh @@ -0,0 +1,9 @@ +cd "$TEST" + +"$XTOUCH" -p foo/bar baz/qux +chmod -w foo +defer chmod +w foo + +! invoke_bfs . -print -delete -print >"$OUT" || fail +sort_output +diff_output -- 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/common') 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