]> 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>
Mon, 14 Nov 2016 01:09:57 +0000 (17:09 -0800)
The previous "returns_"-using change failed to convert many
uses of "$?".  Convert all but two of the remaining ones.
* tests/ls/stat-vs-dirent.sh: Likewise.
* tests/misc/head-write-error.sh: Likewise.
* tests/misc/nice.sh: Likewise.
* tests/misc/nohup.sh: Likewise.
* tests/misc/stdbuf.sh: Likewise.
* tests/misc/sync.sh: Likewise.
* tests/tail-2/pid.sh: Likewise.
* tests/tail-2/wait.sh: Likewise.
Thanks to Bernhard Volker for spotting this.

tests/ls/stat-vs-dirent.sh
tests/misc/head-write-error.sh
tests/misc/nice.sh
tests/misc/nohup.sh
tests/misc/stdbuf.sh
tests/misc/sync.sh
tests/tail-2/pid.sh
tests/tail-2/wait.sh

index b9f3cd1c9a7686fbd9bbb670174207a66f05792a..fa2087f53616820ffa8d788d2b024429763e6bb9 100755 (executable)
@@ -23,8 +23,7 @@ print_ver_ ls
 root_dev_ino=$(stat --format=%d-%i /)
 t=$(pwd)
 while :; do
-  ls -i1 "$t" > tmp
-  if test $? = 0; then
+  if ls -i1 "$t" > tmp; then
     # Extract the inode number from the first line of output from ls -i1.
     # This value comes from dirent.d_ino, on systems with d_ino support.
     d_ino=$(sed -n '1s/^ *\([0-9][0-9]*\) .*/\1/p;q' tmp)
index 4c021f520557de7be4e47f9da7f6a993c108bb60..1e8e566c3f11e6a7625d464baa866252f4e83731 100755 (executable)
@@ -36,14 +36,13 @@ printf '%s\n' "head: error writing 'standard output'" > exp
 for item in lines bytes; do
   for N in 0 1; do
     # pipe case
-    yes | timeout 10s head --$item=-$N > /dev/full 2> errt && fail=1
-    test $? = 124 && fail=1
+    yes | returns_ 1 timeout 10s head --$item=-$N > /dev/full 2> errt || fail=1
     sed 's/\(head:.*\):.*/\1/' errt > err
     compare exp err || fail=1
 
     # seekable case
-    timeout 10s head --$item=-$N bigseek > /dev/full 2> errt && fail=1
-    test $? = 124 && fail=1
+    returns_ 1 timeout 10s head --$item=-$N bigseek > /dev/full 2> errt \
+        || fail=1
     sed 's/\(head:.*\):.*/\1/' errt > err
     compare exp err || fail=1
   done
index 85523eb4dffb5b9a7595831a587d6d22724d1a86..36d6f9189f5719ede77f0b1acfe3b018504fed1f 100755 (executable)
@@ -79,8 +79,7 @@ if test x$(nice -n -1 nice 2> /dev/null) = x0 ; then
   compare exp err || fail=1
   # Failure to write advisory message is fatal.  Buggy through coreutils 8.0.
   if test -w /dev/full && test -c /dev/full; then
-    nice -n -1 nice > out 2> /dev/full
-    test $? = 125 || fail=1
+    returns_ 125 nice -n -1 nice > out 2> /dev/full || fail=1
     compare /dev/null out || fail=1
   fi
 else
index ad60185b1f9c55da2e49af3e4a7e6d55d407fa40..e9c8c389aed674283744039cdc180b28f455c8bd 100755 (executable)
@@ -70,8 +70,7 @@ if test -w /dev/full && test -c /dev/full; then
 
   exec >/dev/tty
   test -t 1 || exit 0
-  nohup echo hi 2> /dev/full
-  test $? = 125 || fail=1
+  returns_ 125 nohup echo hi 2> /dev/full || fail=1
   test -f nohup.out || fail=1
   compare /dev/null nohup.out || fail=1
   rm -f nohup.out
@@ -118,9 +117,7 @@ EOF
 
 # Make sure it fails with exit status of 125 when given too few arguments,
 # except that POSIX requires 127 in this case.
-nohup >/dev/null 2>&1
-test $? = 125 || fail=1
-POSIXLY_CORRECT=1 nohup >/dev/null 2>&1
-test $? = 127 || fail=1
+returns_ 125 nohup >/dev/null 2>&1 || fail=1
+POSIXLY_CORRECT=1 returns_ 127 nohup >/dev/null 2>&1 || fail=1
 
 Exit $fail
index 7b9aed5036975dc8049f5077da97ce714d433efd..31f02b7cca028bc48345017125392701cf00aad1 100755 (executable)
@@ -43,19 +43,17 @@ stdbuf -o1 true || fail=1 # verify size syntax
 stdbuf -oK true || fail=1 # verify size syntax
 stdbuf -o0 true || fail=1 # verify unbuffered syntax
 stdbuf -oL true || fail=1 # verify line buffered syntax
-stdbuf -ol true # Capital 'L' required
-test $? = 125 || fail=1 # Internal error is a particular status
-stdbuf -o$SIZE_OFLOW true # size too large
-test $? = 125 || fail=1
-stdbuf -iL true # line buffering stdin disallowed
-test $? = 125 || fail=1
-stdbuf true # a buffering mode must be specified
-test $? = 125 || fail=1
+
+# Capital 'L' required
+# Internal error is a particular status
+returns_ 125 stdbuf -ol true || fail=1
+
+returns_ 125 stdbuf -o$SIZE_OFLOW true || fail=1 # size too large
+returns_ 125 stdbuf -iL true || fail=1 # line buffering stdin disallowed
+returns_ 125 stdbuf true || fail=1 # a buffering mode must be specified
 stdbuf -i0 -o0 -e0 true || fail=1 #check all files
-stdbuf -o1 . # invalid command
-test $? = 126 || fail=1
-stdbuf -o1 no_such # no such command
-test $? = 127 || fail=1
+returns_ 126 stdbuf -o1 . || fail=1 # invalid command
+returns_ 127 stdbuf -o1 no_such || fail=1 # no such command
 
 # Terminate any background processes
 cleanup_() { kill $pid 2>/dev/null && wait $pid; }
index 5bf569c5f5bf34a1dac4b9b28dc6460a31a67da8..cd89c5bb9ad9c8cf64240680e8e0e8a9992345b1 100755 (executable)
@@ -45,8 +45,7 @@ fi
 if test "$fail" != '1'; then
   # Ensure a fifo doesn't block
   mkfifo_or_skip_ fifo
-  timeout 10 sync fifo
-  test $? = 124 && fail=1
+  returns_ 124 timeout 10 sync fifo && fail=1
 fi
 
 Exit $fail
index 9e73b8448a5e49c905d20dfdb6879c1ce0bf4d67..ba67b46a62a8bdd70f8cb5f12a5e612826e19b19 100755 (executable)
@@ -31,8 +31,7 @@ for mode in '' '---disable-inotify'; do
   tail -f $mode here & pid=$!
 
   # Ensure that tail --pid=PID does not exit when PID is alive.
-  timeout 1 tail -f -s.1 --pid=$pid $mode here
-  test $? = 124 || fail=1
+  returns_ 124 timeout 1 tail -f -s.1 --pid=$pid $mode here || fail=1
 
   cleanup_
 
@@ -44,8 +43,7 @@ for mode in '' '---disable-inotify'; do
   test $ret = 0 || fail=1
 
   # Ensure tail doesn't wait for data when PID is dead
-  timeout 10 tail -f -s10 --pid=$PID_T_MAX $mode empty
-  test $? = 124 && fail=1
+  returns_ 124 timeout 10 tail -f -s10 --pid=$PID_T_MAX $mode empty && fail=1
 done
 
 Exit $fail
index 59f796abea138b38d4391d92d1a2491dd024f74b..1b5432754e711a24ec540b033e56ef6d93b9e26d 100755 (executable)
@@ -35,29 +35,23 @@ cleanup_() { kill $pid 2>/dev/null && wait $pid; }
 fastpoll='-s.1 --max-unchanged-stats=1'
 
 for mode in '' '---disable-inotify'; do
-  timeout 10 tail $fastpoll -f $mode not_here
-  test $? = 124 && fail=1
+  returns_ 124 timeout 10 tail $fastpoll -f $mode not_here && fail=1
 
   if test ! -r unreadable; then # can't test this when root
-    timeout 10 tail $fastpoll -f $mode unreadable
-    test $? = 124 && fail=1
+    returns_ 124 timeout 10 tail $fastpoll -f $mode unreadable && fail=1
   fi
 
-  timeout .1 tail $fastpoll -f $mode here 2>tail.err
-  test $? = 124 || fail=1
+  returns_ 124 timeout .1 tail $fastpoll -f $mode here 2>tail.err || fail=1
 
   # 'tail -F' must wait in any case.
 
-  timeout .1 tail $fastpoll -F $mode here 2>>tail.err
-  test $? = 124 || fail=1
+  returns_ 124 timeout .1 tail $fastpoll -F $mode here 2>>tail.err || fail=1
 
   if test ! -r unreadable; then # can't test this when root
-    timeout .1 tail $fastpoll -F $mode unreadable
-    test $? = 124 || fail=1
+    returns_ 124 timeout .1 tail $fastpoll -F $mode unreadable || fail=1
   fi
 
-  timeout .1 tail $fastpoll -F $mode not_here
-  test $? = 124 || fail=1
+  returns_ 124 timeout .1 tail $fastpoll -F $mode not_here || fail=1
 
   grep -Ev "$inotify_failed_re" tail.err > x
   mv x tail.err