summaryrefslogtreecommitdiff
path: root/tests/misc
diff options
context:
space:
mode:
authorJim Meyering <meyering@fb.com>2016-11-08 19:57:41 -0600
committerJim Meyering <meyering@fb.com>2016-11-13 08:26:19 -0800
commit22063c8c083d2d8130efb76482e45fa1976a595a (patch)
tree18645c547557304f18702e3c07b83fb3793ea135 /tests/misc
parent4d45722d1160a04e4d26fd812da4e0140ad3550c (diff)
downloadcoreutils-22063c8c083d2d8130efb76482e45fa1976a595a.tar.xz
tests: use "returns_" rather than explicit comparison with "$?"
* tests/chmod/no-x.sh: Likewise. * tests/cp/no-deref-link1.sh: Likewise. * tests/cp/no-deref-link2.sh: Likewise. * tests/cp/no-deref-link3.sh: Likewise. * tests/du/move-dir-while-traversing.sh: Likewise. * tests/ls/infloop.sh: Likewise. * tests/ls/stat-failed.sh: Likewise. * tests/ls/time-style-diag.sh: Likewise. * tests/misc/chroot-fail.sh: Likewise. * tests/misc/env-null.sh: Likewise. * tests/misc/env.sh: Likewise. * tests/misc/nice-fail.sh: Likewise. * tests/misc/printenv.sh: Likewise. * tests/misc/timeout.sh: Likewise. * tests/tail-2/follow-name.sh: Likewise.
Diffstat (limited to 'tests/misc')
-rwxr-xr-xtests/misc/chroot-fail.sh15
-rwxr-xr-xtests/misc/env-null.sh9
-rwxr-xr-xtests/misc/env.sh18
-rwxr-xr-xtests/misc/nice-fail.sh18
-rwxr-xr-xtests/misc/printenv.sh12
-rwxr-xr-xtests/misc/timeout.sh12
6 files changed, 28 insertions, 56 deletions
diff --git a/tests/misc/chroot-fail.sh b/tests/misc/chroot-fail.sh
index bb840c731..48c6769a7 100755
--- a/tests/misc/chroot-fail.sh
+++ b/tests/misc/chroot-fail.sh
@@ -22,20 +22,15 @@ print_ver_ chroot pwd
# These tests verify exact status of internal failure; since none of
# them actually run a command, we don't need root privileges
-chroot # missing argument
-test $? = 125 || fail=1
-chroot --- / true # unknown option
-test $? = 125 || fail=1
+returns_ 125 chroot || fail=1 # missing argument
+returns_ 125 chroot --- / true || fail=1 # unknown option
# chroot("/") succeeds for non-root users on some systems, but not all.
if chroot / true ; then
can_chroot_root=1
- chroot / sh -c 'exit 2' # exit status propagation
- test $? = 2 || fail=1
- chroot / . # invalid command
- test $? = 126 || fail=1
- chroot / no_such # no such command
- test $? = 127 || fail=1
+ returns_ 2 chroot / sh -c 'exit 2' || fail=1 # exit status propagation
+ returns_ 126 chroot / . || fail=1# invalid command
+ returns_ 127 chroot / no_such || fail=1 # no such command
else
test $? = 125 || fail=1
can_chroot_root=0
diff --git a/tests/misc/env-null.sh b/tests/misc/env-null.sh
index f84ff27fb..40fafed07 100755
--- a/tests/misc/env-null.sh
+++ b/tests/misc/env-null.sh
@@ -38,8 +38,7 @@ env -i PATH="$PATH" printenv --null > out2 || fail=1
compare out1 out2 || fail=1
# env -0 does not work if a command is specified.
-env -0 echo hi > out
-test $? = 125 || fail=1
+returns_ 125 env -0 echo hi > out || fail=1
compare /dev/null out || fail=1
# Test env -0 on a one-variable environment.
@@ -51,11 +50,9 @@ compare exp out || fail=1
printf 'b\nc=\0' > exp || framework_failure_
env "$(printf 'a=b\nc=')" printenv -0 a > out || fail=1
compare exp out || fail=1
-env -u a printenv -0 a > out
-test $? = 1 || fail=1
+returns_ 1 env -u a printenv -0 a > out || fail=1
compare /dev/null out || fail=1
-env -u b "$(printf 'a=b\nc=')" printenv -0 b a > out
-test $? = 1 || fail=1
+returns_ 1 env -u b "$(printf 'a=b\nc=')" printenv -0 b a > out || fail=1
compare exp out || fail=1
Exit $fail
diff --git a/tests/misc/env.sh b/tests/misc/env.sh
index 666d77717..9f939f1de 100755
--- a/tests/misc/env.sh
+++ b/tests/misc/env.sh
@@ -43,16 +43,11 @@ echo a=b > exp || framework_failure_
compare exp out || fail=1
# These tests verify exact status of internal failure.
-env --- # unknown option
-test $? = 125 || fail=1
-env -u # missing option argument
-test $? = 125 || fail=1
-env sh -c 'exit 2' # exit status propagation
-test $? = 2 || fail=2
-env . # invalid command
-test $? = 126 || fail=1
-env no_such # no such command
-test $? = 127 || fail=1
+returns_ 125 env --- || fail=1 # unknown option
+returns_ 125 env -u || fail=1 # missing option argument
+returns_ 2 env sh -c 'exit 2' || fail=1 # exit status propagation
+returns_ 126 env . || fail=1 # invalid command
+returns_ 127 env no_such || fail=1 # no such command
# POSIX is clear that environ may, but need not be, sorted.
# Environment variable values may contain newlines, which cannot be
@@ -131,8 +126,7 @@ case $(env -- -u pass) in
esac
# After options have ended, the first argument not containing = is a program.
-env a=b -- true
-test $? = 127 || fail=1
+returns_ 127 env a=b -- true || fail=1
ln -s "simple_echo" ./-- || framework_failure_
case $(env a=b -- true || echo fail) in
*true) ;;
diff --git a/tests/misc/nice-fail.sh b/tests/misc/nice-fail.sh
index 92d00be50..86e9d6fd0 100755
--- a/tests/misc/nice-fail.sh
+++ b/tests/misc/nice-fail.sh
@@ -22,17 +22,11 @@ print_ver_ nice
# These tests verify exact status of internal failure.
-nice -n 1 # missing command
-test $? = 125 || fail=1
-nice --- # unknown option
-test $? = 125 || fail=1
-nice -n 1a # invalid adjustment
-test $? = 125 || fail=1
-nice sh -c 'exit 2' # exit status propagation
-test $? = 2 || fail=2
-nice . # invalid command
-test $? = 126 || fail=1
-nice no_such # no such command
-test $? = 127 || fail=1
+returns_ 125 nice -n 1 || fail=1 # missing command
+returns_ 125 nice --- || fail=1 # unknown option
+returns_ 125 nice -n 1a || fail=1 # invalid adjustment
+returns_ 2 nice sh -c 'exit 2' || fail=1 # exit status propagation
+returns_ 126 nice . || fail=1 # invalid command
+returns_ 127 nice no_such || fail=1 # no such command
Exit $fail
diff --git a/tests/misc/printenv.sh b/tests/misc/printenv.sh
index 5df4146c8..2017e5df6 100755
--- a/tests/misc/printenv.sh
+++ b/tests/misc/printenv.sh
@@ -39,8 +39,7 @@ if env -- printenv | grep '^ENV_TEST' >/dev/null ; then
fi
# Printing a single variable's value.
-env -- printenv ENV_TEST > out
-test $? = 1 || fail=1
+returns_ 1 env -- printenv ENV_TEST > out || fail=1
compare /dev/null out || fail=1
echo a > exp || framework_failure_
ENV_TEST=a env -- printenv ENV_TEST > out || fail=1
@@ -60,10 +59,8 @@ EOF
compare exp out || fail=1
# Exit status reflects missing variable, but remaining arguments processed.
-ENV_TEST1=a env -- printenv ENV_TEST2 ENV_TEST1 > out
-test $? = 1 || fail=1
-ENV_TEST1=a env -- printenv ENV_TEST1 ENV_TEST2 >> out
-test $? = 1 || fail=1
+ENV_TEST1=a returns_ 1 env -- printenv ENV_TEST2 ENV_TEST1 > out || fail=1
+ENV_TEST1=a returns_ 1 env -- printenv ENV_TEST1 ENV_TEST2 >> out || fail=1
cat <<EOF > exp || framework_failure_
a
a
@@ -78,8 +75,7 @@ compare exp out || fail=1
# Silently reject invalid env-var names.
# Bug present through coreutils 8.0.
-env a=b=c printenv a=b > out
-test $? = 1 || fail=1
+returns_ 1 env a=b=c printenv a=b > out || fail=1
compare /dev/null out || fail=1
Exit $fail
diff --git a/tests/misc/timeout.sh b/tests/misc/timeout.sh
index dcee6d7ce..208c954c5 100755
--- a/tests/misc/timeout.sh
+++ b/tests/misc/timeout.sh
@@ -30,23 +30,19 @@ timeout 1d true || fail=1
timeout 0 true || fail=1
# exit status propagation
-timeout 10 sh -c 'exit 2'
-test $? = 2 || fail=1
+returns_ 2 timeout 10 sh -c 'exit 2' || fail=1
# timeout
-timeout .1 sleep 10
-test $? = 124 || fail=1
+returns_ 124 timeout .1 sleep 10 || fail=1
# exit status propagation even on timeout
-timeout --preserve-status .1 sleep 10
# exit status should be 128+TERM
-test $? = 124 && fail=1
+returns_ 124 timeout --preserve-status .1 sleep 10 && fail=1
# kill delay. Note once the initial timeout triggers,
# the exit status will be 124 even if the command
# exits on its own accord.
-timeout -s0 -k1 .1 sleep 10
-test $? = 124 && fail=1
+returns_ 124 timeout -s0 -k1 .1 sleep 10 && fail=1
# Ensure 'timeout' is immune to parent's SIGCHLD handler
# Use a subshell and an exec to work around a bug in FreeBSD 5.0 /bin/sh.