]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tests: use "returns_" rather than explicit comparison with "$?"
authorJim Meyering <meyering@fb.com>
Wed, 9 Nov 2016 01:57:41 +0000 (19:57 -0600)
committerJim Meyering <meyering@fb.com>
Sun, 13 Nov 2016 16:26:19 +0000 (08:26 -0800)
* 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.

15 files changed:
tests/chmod/no-x.sh
tests/cp/no-deref-link1.sh
tests/cp/no-deref-link2.sh
tests/cp/no-deref-link3.sh
tests/du/move-dir-while-traversing.sh
tests/ls/infloop.sh
tests/ls/stat-failed.sh
tests/ls/time-style-diag.sh
tests/misc/chroot-fail.sh
tests/misc/env-null.sh
tests/misc/env.sh
tests/misc/nice-fail.sh
tests/misc/printenv.sh
tests/misc/timeout.sh
tests/tail-2/follow-name.sh

index 304eb8229aa07e2896bcd08759ab99f7234cb04c..499f74a52a6772a67a1c2cd7279b4bc8bd80e43a 100755 (executable)
@@ -48,10 +48,9 @@ compare exp out || fail=1
 
 cd a
 # This will fail with ''chmod: fts_read failed: Permission denied''
-chmod a-x . b 2> /dev/null && fail=1
 # chmod must exit with status 1.
 # Due to a bug in coreutils-5.93's fts.c, chmod would provoke
 # an abort (exit with status 134) on recent glibc-based systems.
-test $? = 1 || fail=1
+returns_ 1 chmod a-x . b 2> /dev/null || fail=1
 
 Exit $fail
index b1754b728c05aa7b39e840a204346206dbf54d25..4b7c057cdde38faa6352fad632dbde89718d7e1f 100755 (executable)
@@ -29,10 +29,8 @@ cd ..
 
 # It should fail with a message something like this:
 #   ./cp: 'a/foo' and 'b/foo' are the same file
-cp -d a/foo b 2>/dev/null
-
 # Fail this test if the exit status is not 1
-test $? = 1 || fail=1
+returns_ 1 cp -d a/foo b 2>/dev/null || fail=1
 
 test "$(cat a/foo)" = $msg || fail=1
 
index 25a8848fa9f33c6cff25e5f55f62edda7fb28549..7f0ca4816e3639fd6c8e16548d246eca572d061d 100755 (executable)
@@ -29,10 +29,8 @@ cd ..
 
 # It should fail with a message something like this:
 #   cp: 'a' and 'b/foo' are the same file
-cp -d a b 2>/dev/null
-
 # Fail this test if the exit status is not 1
-test $? = 1 || fail=1
+returns_ 1 cp -d a b 2>/dev/null || fail=1
 
 test "$(cat a)" = $msg || fail=1
 
index 897eb6b8d3657513232c7d411a76bb67a807f217..137a501815295d30aa3c0fb782b23c3ac89afc9b 100755 (executable)
@@ -26,10 +26,8 @@ ln -s a b
 
 # It should fail with a message something like this:
 #   cp: 'a' and 'b' are the same file
-cp -d a b 2>/dev/null
-
 # Fail this test if the exit status is not 1
-test $? = 1 || fail=1
+returns_ 1 cp -d a b 2>/dev/null || fail=1
 
 test "$(cat a)" = $msg || fail=1
 
index e80e94cb73dea29770df42c02283016ba8eb08f5..218f0c4631d75d40e919e4a9f2f7d8d5dacc9279 100755 (executable)
@@ -88,9 +88,8 @@ retry_delay_ nonempty .1 5 || fail=1
 # and when it triggers, moves the parent, $t/3/a, up one level
 # so it's directly under $t.
 
-du -a $t d2 2> err
 # Before coreutils-8.10, du would abort.
-test $? = 1 || fail=1
+returns_ 1 du -a $t d2 2> err || fail=1
 
 # check for the new diagnostic
 printf "du: fts_read failed: $t/3/a/b: No such file or directory\n" > exp \
index e06a9a4e6d7a4d088d550f8fd66a8804adf7b6e9..a724d1195166caa23dba12ddbff90c881b67a957 100755 (executable)
@@ -32,9 +32,8 @@ cat <<\EOF > exp-err || framework_failure_
 ls: loop/sub: not listing already-listed directory
 EOF
 
-timeout 10 ls -RL loop >out 2>err
 # Ensure that ls exits with status 2 upon detecting a cycle
-test $? = 2 || fail=1
+returns_ 2 timeout 10 ls -RL loop >out 2>err || fail=1
 
 compare exp-err err || fail=1
 compare exp-out out || fail=1
index b0e11e6686e040bc62fbc1215ec44dac791d8ab9..2fb376d670e8449745c0c3dc4f96d821c0903065 100755 (executable)
@@ -28,8 +28,7 @@ ln -s / d/s || framework_failure_
 chmod 600 d || framework_failure_
 
 
-ls -Log d > out
-test $? = 1 || fail=1
+returns_ 1 ls -Log d > out || fail=1
 
 # Linux 2.6.32 client with Isilon OneFS always returns d_type==DT_DIR ('d')
 # Newer Linux 3.10.0 returns the more correct DT_UNKNOWN ('?')
index 04be4dd7b3b437ec699c671e05f40b87e584427a..0630418ca11fa3ee899e48e36b155346cab14ad7 100755 (executable)
@@ -19,8 +19,7 @@
 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
 print_ver_ ls
 
-ls -l --time-style=XX > out 2> err
-test $? = 2 || fail=1
+returns_ 2 ls -l --time-style=XX > out 2> err || fail=1
 
 cat <<\EOF > exp || fail=1
 ls: invalid argument 'XX' for 'time style'
index bb840c73180f859f2e250f3e8be3620be31e7018..48c6769a7055af357e407c691b9ce3e81d907f3a 100755 (executable)
@@ -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
index f84ff27fbd51d786bac4d9430707adeac83c9372..40fafed07ee34d781f2f13f9836657c7c0cbc146 100755 (executable)
@@ -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
index 666d7771721b00ebcbfbed5692f7f9efe030883b..9f939f1decd0710c77b990e75ffbf80f2a371481 100755 (executable)
@@ -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) ;;
index 92d00be5032505aeedcfcd7eca5eb44cef314e8b..86e9d6fd087336c533be76ce8cac4c17a0ca8303 100755 (executable)
@@ -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
index 5df4146c88183681800c1ff85de6032d35b60e16..2017e5df66b49ca374f6966107d739dcf97d0399 100755 (executable)
@@ -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
index dcee6d7ce11f959cfdc7ff962536fa2eddc4bc99..208c954c5e5a733cdc35cc00c86b0acac1fcb5cc 100755 (executable)
@@ -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.
index ea5c5d9eff41f4e0d0bd8d2de040274fe180d393..f75da7acee4bf145ca803bdc020a46d1c1e260ad 100755 (executable)
@@ -24,8 +24,7 @@ tail: cannot open 'no-such' for reading: No such file or directory
 tail: no files remaining
 EOF
 
-timeout 10 tail --follow=name no-such > out 2> err
-test $? = 1 || fail=1
+returns_ 1 timeout 10 tail --follow=name no-such > out 2> err || fail=1
 
 # Remove an inconsequential inotify warning so
 # we can compare against the above error