summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2022-12-16 15:32:04 -0500
committerTavian Barnes <tavianator@tavianator.com>2022-12-16 15:32:04 -0500
commite50c19f284dad6b4b7b79f91cc8576a97626be8a (patch)
tree3fc7b15a412d4123d403bca6fdbf3225389926e1 /tests
parent7d87b96b421b76e387cee903b7b7c1bc16c54310 (diff)
downloadbfs-e50c19f284dad6b4b7b79f91cc8576a97626be8a.tar.xz
tests: Turn on set -e
Diffstat (limited to 'tests')
-rw-r--r--tests/bfs/D_unknown.sh2
-rw-r--r--tests/bfs/O9.sh2
-rw-r--r--tests/bfs/execdir_plus_nonexistent.sh7
-rw-r--r--tests/bfs/help.sh10
-rw-r--r--tests/bsd/X.sh3
-rw-r--r--tests/bsd/exit.sh10
-rw-r--r--tests/common/L_mount.sh7
-rw-r--r--tests/common/execdir_nonexistent.sh7
-rw-r--r--tests/common/inum_bind_mount.sh6
-rw-r--r--tests/common/inum_mount.sh6
-rw-r--r--tests/common/mount.sh7
-rw-r--r--tests/gnu/L_delete.sh2
-rw-r--r--tests/gnu/L_loops_continue.sh3
-rw-r--r--tests/gnu/inum_automount.sh8
-rw-r--r--tests/gnu/printf_Y_error.sh10
-rw-r--r--tests/gnu/xtype_bind_mount.sh8
-rw-r--r--tests/posix/L_loops.sh2
-rw-r--r--tests/posix/L_xdev.sh7
-rw-r--r--tests/posix/depth_error.sh10
-rw-r--r--tests/posix/exec_nonexistent.sh7
-rw-r--r--tests/posix/exec_plus_nonexistent.sh7
-rw-r--r--tests/posix/exec_plus_status.sh3
-rw-r--r--tests/posix/readdir_error.sh2
-rw-r--r--tests/posix/type_bind_mount.sh6
-rw-r--r--tests/posix/xdev.sh7
-rwxr-xr-xtests/tests.sh18
26 files changed, 69 insertions, 98 deletions
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=$?