coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] tests: add extra protection against unexpected exits


From: Pádraig Brady
Subject: [PATCH] tests: add extra protection against unexpected exits
Date: Tue, 13 Jan 2015 03:37:28 +0000

Many tests use `program ... && fail=1` to ensure expected
error situations are indicated.  However that would mask
an unexpected exit (like a crash).  Therefore protect such
calls with `{ program ... | test $? -ne 1; } && fail=1`.
Note where error messages are also verified, the extra
protection is not added.
---
 tests/chmod/octal.sh                         |  6 +++---
 tests/chmod/umask-x.sh                       |  2 +-
 tests/chmod/usage.sh                         |  4 ++--
 tests/chown/separator.sh                     |  3 ++-
 tests/cp/cp-HL.sh                            |  2 +-
 tests/cp/cp-a-selinux.sh                     | 15 +++++++++------
 tests/cp/cp-i.sh                             |  2 +-
 tests/cp/cp-parents.sh                       |  2 +-
 tests/cp/dir-vs-file.sh                      |  2 +-
 tests/cp/fail-perm.sh                        |  2 +-
 tests/cp/no-ctx.sh                           |  3 ++-
 tests/cp/reflink-auto.sh                     |  2 +-
 tests/cp/sparse.sh                           |  4 ++--
 tests/dd/misc.sh                             | 12 ++++++++----
 tests/dd/nocache.sh                          |  4 ++--
 tests/dd/stderr.sh                           |  4 ++--
 tests/df/no-mtab-status.sh                   | 26 +++++++++++++-------------
 tests/df/skip-rootfs.sh                      |  2 +-
 tests/du/deref.sh                            |  2 +-
 tests/id/context.sh                          |  7 +++++--
 tests/id/gnu-zero-uids.sh                    |  2 +-
 tests/id/uid.sh                              |  2 +-
 tests/id/zero.sh                             |  6 ++++--
 tests/install/install-C.sh                   |  4 ++--
 tests/install/strip-program.sh               |  2 +-
 tests/ln/misc.sh                             |  8 ++++----
 tests/ln/slash-decorated-nonexistent-dest.sh |  2 +-
 tests/ls/dangle.sh                           | 12 +++++++-----
 tests/ls/follow-slink.sh                     |  4 +++-
 tests/ls/stat-failed.sh                      |  4 +++-
 tests/misc/cat-self.sh                       |  2 +-
 tests/misc/chcon-fail.sh                     |  8 ++++----
 tests/misc/chroot-credentials.sh             |  8 ++++++--
 tests/misc/close-stdout.sh                   | 24 ++++++++++++------------
 tests/misc/env.sh                            |  2 +-
 tests/misc/false-status.sh                   |  4 ++++
 tests/misc/md5sum-bsd.sh                     |  6 +++---
 tests/misc/nproc-positive.sh                 |  2 +-
 tests/misc/pathchk1.sh                       | 10 +++++-----
 tests/misc/printf.sh                         |  9 ++++++++-
 tests/misc/realpath.sh                       | 13 +++++++------
 tests/misc/selinux.sh                        |  2 +-
 tests/misc/shred-remove.sh                   |  4 ++--
 tests/misc/sort-compress-proc.sh             |  3 +++
 tests/misc/sort-exit-early.sh                |  6 ++++--
 tests/misc/stat-hyphen.sh                    |  2 +-
 tests/misc/stat-slash.sh                     |  2 +-
 tests/misc/stty-invalid.sh                   |  2 ++
 tests/misc/stty.sh                           |  6 +++---
 tests/misc/tr-case-class.sh                  | 10 +++++-----
 tests/misc/truncate-dir-fail.sh              |  2 +-
 tests/misc/truncate-overflow.sh              |  6 +++---
 tests/misc/truncate-parameters.sh            | 12 ++++++------
 tests/misc/truncate-relative.sh              |  8 ++++----
 tests/misc/wc-parallel.sh                    |  3 ++-
 tests/mkdir/p-3.sh                           |  1 +
 tests/mkdir/parents.sh                       |  2 +-
 tests/mkdir/perm.sh                          |  2 +-
 tests/mkdir/special-1.sh                     |  2 +-
 tests/mv/childproof.sh                       |  8 ++++----
 tests/mv/dir-file.sh                         |  4 ++--
 tests/mv/hardlink-case.sh                    |  2 +-
 tests/mv/into-self-4.sh                      |  2 +-
 tests/mv/mv-n.sh                             |  2 +-
 tests/mv/no-target-dir.sh                    |  8 +++++---
 tests/mv/part-rename.sh                      |  6 +++---
 tests/readlink/can-e.sh                      | 13 +++++++++++++
 tests/readlink/multi.sh                      |  4 ++--
 tests/readlink/rl-1.sh                       |  3 +++
 tests/rm/i-no-r.sh                           |  2 +-
 tests/rm/no-give-up.sh                       |  1 +
 tests/rm/rm4.sh                              |  2 +-
 tests/rm/sunos-1.sh                          |  2 +-
 tests/rmdir/fail-perm.sh                     |  2 +-
 tests/split/additional-suffix.sh             |  3 ++-
 tests/split/fail.sh                          | 27 ++++++++++++++-------------
 tests/split/filter.sh                        |  2 +-
 tests/split/guard-input.sh                   |  8 ++++----
 tests/split/numeric.sh                       |  6 +++---
 tests/split/suffix-auto-length.sh            |  2 +-
 tests/split/suffix-length.sh                 |  2 +-
 tests/touch/no-dereference.sh                |  4 ++--
 tests/touch/trailing-slash.sh                | 20 ++++++++++----------
 83 files changed, 258 insertions(+), 192 deletions(-)

diff --git a/tests/chmod/octal.sh b/tests/chmod/octal.sh
index 6f47a07..dbfe40b 100755
--- a/tests/chmod/octal.sh
+++ b/tests/chmod/octal.sh
@@ -22,8 +22,8 @@ print_ver_ chmod
 
 # Before coreutils-5.92, this would mistakenly succeed,
 # and act like 'chmod 0 .'.
-chmod 0-followed-by-anything . 2> /dev/null && fail=1
-chmod 7-followed-by-anything . 2> /dev/null && fail=1
-chmod 8                      . 2> /dev/null && fail=1
+for mode in '0-anything' '7-anything' '8'; do
+  { chmod "$mode" . 2>/dev/null || test $? -ne 1; } && fail=1
+done
 
 Exit $fail
diff --git a/tests/chmod/umask-x.sh b/tests/chmod/umask-x.sh
index 85b087d..167dd0c 100755
--- a/tests/chmod/umask-x.sh
+++ b/tests/chmod/umask-x.sh
@@ -21,6 +21,6 @@ print_ver_ chmod
 
 touch file
 chmod 755 file
-(umask 77 && chmod -x file) 2>/dev/null && fail=1
+(umask 77 && { chmod -x file || test $? -ne 1; }) 2>/dev/null && fail=1
 
 Exit $fail
diff --git a/tests/chmod/usage.sh b/tests/chmod/usage.sh
index 1331152..4a2b06e 100755
--- a/tests/chmod/usage.sh
+++ b/tests/chmod/usage.sh
@@ -67,7 +67,7 @@ for case in $cases; do
   case $files in
   '')
     touch -- $all_files || framework_failure_
-    chmod $args 2>/dev/null && fail=1
+    { chmod $args 2>/dev/null || test $? -ne 1; } && fail=1
     ;;
   ?*)
     touch -- $files || framework_failure_
@@ -77,7 +77,7 @@ for case in $cases; do
       # chmod has a bug if it succeeds even though $file is absent.
       rm -f -- $all_files && touch -- $files && rm -- $file \
           || framework_failure_
-      chmod $args 2>/dev/null && fail=1
+      { chmod $args 2>/dev/null || test $? -ne 1; } && fail=1
     done
     ;;
   esac
diff --git a/tests/chown/separator.sh b/tests/chown/separator.sh
index 8155330..9a03619 100755
--- a/tests/chown/separator.sh
+++ b/tests/chown/separator.sh
@@ -59,7 +59,8 @@ for u in $id_u "$id_un" ''; do
     esac
     for sep in $seps; do
       case $u$sep$g in
-        [0-9]*$sep) chown "$u$sep$g" . 2> /dev/null && fail=1 ;;
+        [0-9]*$sep) { chown "$u$sep$g" . 2>/dev/null || test $? -ne 1; } \
+                      && fail=1 ;;
         *) chown "$u$sep$g" . || fail=1 ;;
       esac
     done
diff --git a/tests/cp/cp-HL.sh b/tests/cp/cp-HL.sh
index fa98325..cf25aef 100755
--- a/tests/cp/cp-HL.sh
+++ b/tests/cp/cp-HL.sh
@@ -33,7 +33,7 @@ test -d dest-dir/src-dir || fail=1
 cat dest-dir/slink > /dev/null 2>&1 || fail=1
 
 # Expect this to fail since *this* slink is a dangling symlink.
-cat dest-dir/src-dir/slink > /dev/null 2>&1 && fail=1
+{ cat dest-dir/src-dir/slink >/dev/null 2>&1 || test $? -ne 1; } && fail=1
 
 # FIXME: test -L, too.
 
diff --git a/tests/cp/cp-a-selinux.sh b/tests/cp/cp-a-selinux.sh
index 2ecbd23..3b7d584 100755
--- a/tests/cp/cp-a-selinux.sh
+++ b/tests/cp/cp-a-selinux.sh
@@ -49,14 +49,16 @@ rm -f f
 # in the destination, so SELinux contexts should be updated too.
 chmod o+rw restore/existing_dir
 mkdir -p backup/existing_dir/ || framework_failure_
-ls -Zd backup/existing_dir | grep $ctx && framework_failure_
+ls -Zd backup/existing_dir > ed_ctx || fail=1
+grep $ctx ed_ctx && framework_failure_
 touch backup/existing_dir/file || framework_failure_
 chcon $ctx backup/existing_dir/file || framework_failure_
 # Set the dir context to ensure it is reset
 mkdir -p --context="$ctx" restore/existing_dir || framework_failure_
 # Copy and ensure existing directories updated
 cp -a backup/. restore/
-ls -Zd restore/existing_dir | grep $ctx &&
+ls -Zd restore/existing_dir > ed_ctx || fail=1
+grep $ctx ed_ctx &&
   { ls -lZd restore/existing_dir; fail=1; }
 
 # Check restorecon (-Z) functionality for file and directory
@@ -175,6 +177,7 @@ for no_g_cmd in '' 'rm -f g'; do
   # restorecon equivalent.  Note even though the context
   # returned from matchpathcon() will not match $ctx
   # the resulting ENOTSUP warning will be suppressed.
+
    # With absolute path
   $no_g_cmd
   cp -Z ../f $(realpath g) || fail=1
@@ -186,7 +189,7 @@ for no_g_cmd in '' 'rm -f g'; do
   cp -Z -a ../f g || fail=1
    # -Z doesn't take an arg
   $no_g_cmd
-  cp -Z "$ctx" ../f g && fail=1
+  { cp -Z "$ctx" ../f g || test $? -ne 1; } && fail=1
 
   # Explicit context
   $no_g_cmd
@@ -198,8 +201,8 @@ for no_g_cmd in '' 'rm -f g'; do
 done
 
 # Mutually exclusive options
-cp -Z --preserve=context ../f g && fail=1
-cp --preserve=context -Z ../f g && fail=1
-cp --preserve=context --context="$ctx" ../f g && fail=1
+{ cp -Z --preserve=context ../f g || test $? -ne 1; } && fail=1
+{ cp --preserve=context -Z ../f g || test $? -ne 1; } && fail=1
+{ cp --preserve=context --context="$ctx" ../f g || test $? -ne 1; } && fail=1
 
 Exit $fail
diff --git a/tests/cp/cp-i.sh b/tests/cp/cp-i.sh
index d9d8051..1171a04 100755
--- a/tests/cp/cp-i.sh
+++ b/tests/cp/cp-i.sh
@@ -60,6 +60,6 @@ echo n | cp -vnf c d 2>/dev/null > out7 || fail=1
 compare out7 out_empty || fail=1
 
 # options --backup and --no-clobber are mutually exclusive
-cp -bn c d 2>/dev/null && fail=1
+{ cp -bn c d 2>/dev/null || test $? -ne 1; } && fail=1
 
 Exit $fail
diff --git a/tests/cp/cp-parents.sh b/tests/cp/cp-parents.sh
index 4814d65..6a5e52a 100755
--- a/tests/cp/cp-parents.sh
+++ b/tests/cp/cp-parents.sh
@@ -42,7 +42,7 @@ test -d d/a/b/c || fail=1
 
 # With 6.7 and earlier, cp --parents f/g d would mistakenly create a
 # directory d/f, even though f is a regular file.
-cp --parents f/g d 2>/dev/null && fail=1
+{ cp --parents f/g d 2>/dev/null || test $? -ne 1; } && fail=1
 test -d d/f && fail=1
 
 # Check that re_protect works.
diff --git a/tests/cp/dir-vs-file.sh b/tests/cp/dir-vs-file.sh
index 826d9bc..ba1d5d7 100755
--- a/tests/cp/dir-vs-file.sh
+++ b/tests/cp/dir-vs-file.sh
@@ -24,7 +24,7 @@ touch file || framework_failure_
 
 
 # In 4.0.35, this cp invocation silently succeeded.
-cp -R dir file 2>/dev/null && fail=1
+{ cp -R dir file 2>/dev/null || test $? -ne 1; } && fail=1
 
 # Make sure file is not replaced with a directory.
 # In 4.0.35, it was.
diff --git a/tests/cp/fail-perm.sh b/tests/cp/fail-perm.sh
index abc5e4e..80dc10b 100755
--- a/tests/cp/fail-perm.sh
+++ b/tests/cp/fail-perm.sh
@@ -27,7 +27,7 @@ chmod u=rx,go=,-st D || framework_failure_
 
 
 # This is expected to exit non-zero, because it can't read D/a.
-cp -pR D DD > /dev/null 2>&1 && fail=1
+{ cp -pR D DD > /dev/null 2>&1 || test $? -ne 1; } && fail=1
 
 # Permissions on DD must be 'dr-x------'
 
diff --git a/tests/cp/no-ctx.sh b/tests/cp/no-ctx.sh
index 3cae583..8729bb6 100755
--- a/tests/cp/no-ctx.sh
+++ b/tests/cp/no-ctx.sh
@@ -57,7 +57,8 @@ LD_PRELOAD=./k.so cp -a file_src file_dst || fail=1
 
 # ENODATA should give an immediate error when required to preserve ctx
 # This is debatable, and maybe we should not fail when no context available?
-LD_PRELOAD=./k.so cp --preserve=context file_src file_dst && fail=1
+{ LD_PRELOAD=./k.so cp --preserve=context file_src file_dst \
+  || test $? -ne 1; } && fail=1
 
 test -e preloaded || skip_ 'LD_PRELOAD interception failed'
 
diff --git a/tests/cp/reflink-auto.sh b/tests/cp/reflink-auto.sh
index 6666208..0022b75 100755
--- a/tests/cp/reflink-auto.sh
+++ b/tests/cp/reflink-auto.sh
@@ -27,7 +27,7 @@ rm -f "$a_other" || framework_failure_
 echo non_zero_size > "$a_other" || framework_failure_
 
 # we shouldn't be able to reflink() files on separate partitions
-cp --reflink      "$a_other" b && fail=1
+{ cp --reflink "$a_other" b || test $? -ne 1; } && fail=1
 
 # --reflink=auto should fall back to a normal copy
 cp --reflink=auto "$a_other" b || fail=1
diff --git a/tests/cp/sparse.sh b/tests/cp/sparse.sh
index 3d6fb58..066085d 100755
--- a/tests/cp/sparse.sh
+++ b/tests/cp/sparse.sh
@@ -34,8 +34,8 @@ cp --sparse=always sparse copy || fail=1
 test $(stat --printf %b copy) -le $(stat --printf %b sparse) || fail=1
 
 # Ensure that --sparse={always,never} with --reflink fail.
-cp --sparse=always --reflink sparse copy && fail=1
-cp --sparse=never --reflink sparse copy && fail=1
+{ cp --sparse=always --reflink sparse copy || test $? -ne 1; } && fail=1
+{ cp --sparse=never --reflink sparse copy || test $? -ne 1; } && fail=1
 
 
 # Ensure we handle sparse/non-sparse transitions correctly
diff --git a/tests/dd/misc.sh b/tests/dd/misc.sh
index 59f0f50..deaded2 100755
--- a/tests/dd/misc.sh
+++ b/tests/dd/misc.sh
@@ -61,12 +61,14 @@ case $(cat /dev/stdin <$tmp_in 2>/dev/null) in
 esac
 
 if dd iflag=nofollow if=$tmp_in count=0 2> /dev/null; then
-  dd iflag=nofollow if=$tmp_sym count=0 2> /dev/null && fail=1
+  { dd iflag=nofollow if=$tmp_sym count=0 2> /dev/null \
+    || test $? -ne 1; } && fail=1
 fi
 
 if dd iflag=directory if=. count=0 2> /dev/null; then
   dd iflag=directory count=0 <. 2> /dev/null || fail=1
-  dd iflag=directory count=0 <$tmp_in 2> /dev/null && fail=1
+  { dd iflag=directory count=0 <$tmp_in 2> /dev/null \
+    || test $? -ne 1; } && fail=1
 fi
 
 old_ls=$(ls -u --full-time $tmp_in)
@@ -87,8 +89,10 @@ EOF
 fi
 
 if dd oflag=nolinks if=$tmp_in of=$tmp_out 2> /dev/null; then
-  dd iflag=nolinks if=$tmp_in > /dev/null 2>&1 && fail=1
-  dd iflag=nolinks < $tmp_in > /dev/null 2>&1 && fail=1
+  { dd iflag=nolinks if=$tmp_in > /dev/null 2>&1 \
+    || test $? -ne 1; } && fail=1
+  { dd iflag=nolinks < $tmp_in > /dev/null 2>&1 \
+    || test $? -ne 1; } && fail=1
   dd oflag=nolinks < $tmp_in > $tmp_out 2>&1 || fail=1
 fi
 
diff --git a/tests/dd/nocache.sh b/tests/dd/nocache.sh
index 3342148..0c1c710 100755
--- a/tests/dd/nocache.sh
+++ b/tests/dd/nocache.sh
@@ -23,10 +23,10 @@ print_ver_ dd
 dd iflag=nocache oflag=nocache if=/dev/null of=/dev/null || fail=1
 
 # We should get an error for trying to process a pipe
-dd count=0 | dd iflag=nocache count=0 && fail=1
+{ dd count=0 | dd iflag=nocache count=0 || test $? -ne 1; } && fail=1
 
 # O_DIRECT is orthogonal to drop cache so mutually exclusive
-dd iflag=nocache,direct if=/dev/null && fail=1
+{ dd iflag=nocache,direct if=/dev/null || test $? -ne 1; } && fail=1
 
 # The rest ensure that the documented uses cases
 # proceed without error
diff --git a/tests/dd/stderr.sh b/tests/dd/stderr.sh
index ce67a7a..7dff0b2 100755
--- a/tests/dd/stderr.sh
+++ b/tests/dd/stderr.sh
@@ -32,12 +32,12 @@ dd --help >/dev/null 2>&- || fail=1
 # This exposes a failure present in 6.11 through 7.5.
 if "$p/src/test" -w /dev/stderr 2>/dev/null &&
    "$p/src/test" ! -w /dev/stderr 2>&-; then
-  : | dd 2>&- && fail=1
+  : | { dd 2>&- || test $? -ne 1; } && fail=1
 fi
 
 # Likewise for /dev/full, if /dev/full works.
 if test -w /dev/full && test -c /dev/full; then
-  : | dd 2>/dev/full && fail=1
+  : | { dd 2>/dev/full || test $? -ne 1; } && fail=1
 fi
 
 Exit $fail
diff --git a/tests/df/no-mtab-status.sh b/tests/df/no-mtab-status.sh
index d9899c4..84adbfa 100755
--- a/tests/df/no-mtab-status.sh
+++ b/tests/df/no-mtab-status.sh
@@ -77,22 +77,22 @@ LD_PRELOAD=./k.so df -Ti '.' || fail=1
 LD_PRELOAD=./k.so df --total '.' || fail=1
 
 # These tests are supposed to fail:
-LD_PRELOAD=./k.so df && fail=1
-LD_PRELOAD=./k.so df -i && fail=1
-LD_PRELOAD=./k.so df -T && fail=1
-LD_PRELOAD=./k.so df -Ti && fail=1
-LD_PRELOAD=./k.so df --total && fail=1
+{ LD_PRELOAD=./k.so df || test $? -ne 1; } && fail=1
+{ LD_PRELOAD=./k.so df -i || test $? -ne 1; } && fail=1
+{ LD_PRELOAD=./k.so df -T || test $? -ne 1; } && fail=1
+{ LD_PRELOAD=./k.so df -Ti || test $? -ne 1; } && fail=1
+{ LD_PRELOAD=./k.so df --total || test $? -ne 1; } && fail=1
 
-LD_PRELOAD=./k.so df -a && fail=1
-LD_PRELOAD=./k.so df -a '.' && fail=1
+{ LD_PRELOAD=./k.so df -a || test $? -ne 1; } && fail=1
+{ LD_PRELOAD=./k.so df -a '.' || test $? -ne 1; } && fail=1
 
-LD_PRELOAD=./k.so df -l && fail=1
-LD_PRELOAD=./k.so df -l '.' && fail=1
+{ LD_PRELOAD=./k.so df -l || test $? -ne 1; } && fail=1
+{ LD_PRELOAD=./k.so df -l '.' || test $? -ne 1; } && fail=1
 
-LD_PRELOAD=./k.so df -t hello && fail=1
-LD_PRELOAD=./k.so df -t hello '.' && fail=1
+{ LD_PRELOAD=./k.so df -t hello || test $? -ne 1; } && fail=1
+{ LD_PRELOAD=./k.so df -t hello '.' || test $? -ne 1; } && fail=1
 
-LD_PRELOAD=./k.so df -x hello && fail=1
-LD_PRELOAD=./k.so df -x hello '.' && fail=1
+{ LD_PRELOAD=./k.so df -x hello || test $? -ne 1; } && fail=1
+{ LD_PRELOAD=./k.so df -x hello '.' || test $? -ne 1; } && fail=1
 
 Exit $fail
diff --git a/tests/df/skip-rootfs.sh b/tests/df/skip-rootfs.sh
index ed5364e..779e2e6 100755
--- a/tests/df/skip-rootfs.sh
+++ b/tests/df/skip-rootfs.sh
@@ -34,7 +34,7 @@ grep '^rootfs' out && { fail=1; cat out; }
 # Ensure that rootfs is yet skipped when explicitly specifying "-t rootfs".
 # As df emits "no file systems processed" in this case, it would be a failure
 # if df exited with status Zero.
-df -t rootfs >out && fail=1
+{ df -t rootfs >out || test $? -ne 1; } && fail=1
 grep '^rootfs' out && { fail=1; cat out; }
 
 # Ensure that the rootfs is shown when explicitly both specifying "-t rootfs"
diff --git a/tests/du/deref.sh b/tests/du/deref.sh
index 670ee5c..b3623ed 100755
--- a/tests/du/deref.sh
+++ b/tests/du/deref.sh
@@ -34,7 +34,7 @@ ln -s nowhere dangle || framework_failure_
 du -sD slink b > /dev/null 2>&1 || fail=1
 
 # This used to fail to report the dangling symlink.
-du -L dangle > /dev/null 2>&1 && fail=1
+{ du -L dangle > /dev/null 2>&1 || test $? -ne 1; } && fail=1
 
 # du -L used to mess up, either by counting the symlink's disk space itself
 # (-L should follow symlinks, not count their space)
diff --git a/tests/id/context.sh b/tests/id/context.sh
index 754d0c3..5391496 100755
--- a/tests/id/context.sh
+++ b/tests/id/context.sh
@@ -26,7 +26,10 @@ id | grep context= >/dev/null || fail=1
 
 # Check with specified user, no context string should be present.
 # But if the current user is nameless, skip this part.
-id -nu > /dev/null \
-  && id $(id -nu) | grep context= >/dev/null && fail=1
+name=$(id -nu) || { test $? -ne 1 && fail=1; }
+if test x"$name" != x; then
+  id "$(id -nu)" > id_name || fail=1
+  grep context= >/dev/null id_name && fail=1
+fi
 
 Exit $fail
diff --git a/tests/id/gnu-zero-uids.sh b/tests/id/gnu-zero-uids.sh
index edd74f7..5e462cc 100755
--- a/tests/id/gnu-zero-uids.sh
+++ b/tests/id/gnu-zero-uids.sh
@@ -24,6 +24,6 @@ require_gnu_
 sush - true || skip_ "the 'sush' command does not work"
 
 # Run 'id' with zero UIDs.  It should exit with a non-zero status.
-sush - id > out && fail=1
+{ sush - id > out || test $? -ne 1; } && fail=1
 
 Exit $fail
diff --git a/tests/id/uid.sh b/tests/id/uid.sh
index c0766b3..446613e 100755
--- a/tests/id/uid.sh
+++ b/tests/id/uid.sh
@@ -22,7 +22,7 @@ uid=$(id -u) || fail=1
 user=$(id -nu) || fail=1
 
 # Ensure the empty user spec is discarded
-id '' && fail=1
+{ id '' || test $? -ne 1; } && fail=1
 
 for mode in '' '-G' '-g'; do
   id $mode $user > user_out || fail=1 # lookup name for comparison
diff --git a/tests/id/zero.sh b/tests/id/zero.sh
index a67a789..7bee3a6 100755
--- a/tests/id/zero.sh
+++ b/tests/id/zero.sh
@@ -51,8 +51,10 @@ while read u ; do
       printf '\n%s: ' "id -${o}${n}[z] $u" >> out || framework_failure_
       # There may be no name corresponding to an id, so don't check
       # exit status when in name lookup mode
-      id -${o}${n}  $u >> exp || { test -z "$n" && fail=1; }
-      id -${o}${n}z $u  > tmp || { test -z "$n" && fail=1; }
+      id -${o}${n}  $u >> exp ||
+        { test $? -ne 1 || test -z "$n" && fail=1; }
+      id -${o}${n}z $u  > tmp ||
+        { test $? -ne 1 || test -z "$n" && fail=1; }
       head -c-1 < tmp >> out || framework_failure_
     done
   done
diff --git a/tests/install/install-C.sh b/tests/install/install-C.sh
index 214e3ae..760053f 100755
--- a/tests/install/install-C.sh
+++ b/tests/install/install-C.sh
@@ -107,9 +107,9 @@ ginstall -Cv -m$mode2 a b > out || fail=1
 compare out out_empty || fail=1
 
 # options -C and --preserve-timestamps are mutually exclusive
-ginstall -C --preserve-timestamps a b && fail=1
+{ ginstall -C --preserve-timestamps a b || test $? -ne 1; } && fail=1
 
 # options -C and --strip are mutually exclusive
-ginstall -C --strip --strip-program=echo a b && fail=1
+{ ginstall -C --strip --strip-program=echo a b || test $? -ne 1; } && fail=1
 
 Exit $fail
diff --git a/tests/install/strip-program.sh b/tests/install/strip-program.sh
index 1350e30..0983b7e 100755
--- a/tests/install/strip-program.sh
+++ b/tests/install/strip-program.sh
@@ -34,7 +34,7 @@ ginstall src dest -s --strip-program=./b || fail=1
 compare exp dest || fail=1
 
 # Check that install cleans up properly if strip fails.
-ginstall src dest2 -s --strip-program=./FOO && fail=1
+{ ginstall src dest2 -s --strip-program=./FOO || test $? -ne 1; } && fail=1
 test -e dest2 && fail=1
 
 Exit $fail
diff --git a/tests/ln/misc.sh b/tests/ln/misc.sh
index 9b23fda..b1224cf 100755
--- a/tests/ln/misc.sh
+++ b/tests/ln/misc.sh
@@ -52,20 +52,20 @@ rm -rf $d $f
 touch $f || framework_failure_
 rm -rf $d || framework_failure_
 mkdir $d $d/$f || framework_failure_
-ln $f $d/ 2> /dev/null && fail=1
-ln -s $f $d/ 2> /dev/null && fail=1
+{ ln $f $d/ 2> /dev/null || test $? -ne 1; } && fail=1
+{ ln -s $f $d/ 2> /dev/null || test $? -ne 1; } && fail=1
 rm -rf $d $f
 
 # Make sure we get a failure with existing dest without -f option
 touch $t || framework_failure_
 # FIXME: don't ignore the error message but rather test
 # it to make sure it's the right one.
-ln -s $t $t 2> /dev/null && fail=1
+{ ln -s $t $t 2> /dev/null || test $? -ne 1; } && fail=1
 rm $t
 
 # Make sure -sf fails when src and dest are the same
 touch $t || framework_failure_
-ln -sf $t $t 2> /dev/null && fail=1
+{ ln -sf $t $t 2> /dev/null || test $? -ne 1; } && fail=1
 rm $t
 
 # Create a symlink with source file and no explicit directory
diff --git a/tests/ln/slash-decorated-nonexistent-dest.sh 
b/tests/ln/slash-decorated-nonexistent-dest.sh
index dc5b189..e398942 100755
--- a/tests/ln/slash-decorated-nonexistent-dest.sh
+++ b/tests/ln/slash-decorated-nonexistent-dest.sh
@@ -23,7 +23,7 @@ touch f || framework_failure_
 
 
 # Before coreutils-7.6, this would succeed on Solaris 10
-ln -T f no-such-file/ && fail=1
+{ ln -T f no-such-file/ || test $? -ne 1; } && fail=1
 test -e no-such-file && fail=1
 
 Exit $fail
diff --git a/tests/ls/dangle.sh b/tests/ls/dangle.sh
index 1f1849d..bac3ce6 100755
--- a/tests/ls/dangle.sh
+++ b/tests/ls/dangle.sh
@@ -19,6 +19,9 @@
 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
 print_ver_ ls
 
+LS_MINOR_PROBLEM=1
+LS_FAILURE=2
+
 ln -s no-such-file dangle || framework_failure_
 mkdir -p dir/sub || framework_failure_
 ln -s dir slink-to-dir || framework_failure_
@@ -27,11 +30,10 @@ ln -s no-such d/dangle || framework_failure_
 printf '? dangle\n' > subdir_Li_exp || framework_failure_
 printf 'total 0\n? dangle\n' > subdir_Ls_exp || framework_failure_
 
-
 # This must exit nonzero.
-ls -L dangle > /dev/null 2>&1 && fail=1
+{ ls -L dangle > /dev/null 2>&1 || test $? -ne $LS_FAILURE; } && fail=1
 # So must this.
-ls -H dangle > /dev/null 2>&1 && fail=1
+{ ls -H dangle > /dev/null 2>&1 || test $? -ne $LS_FAILURE; } && fail=1
 
 # This must exit successfully.
 ls dangle >> out || fail=1
@@ -51,12 +53,12 @@ compare exp out || fail=1
 
 # Ensure that ls -Li prints "?" as the inode of a dangling symlink.
 rm -f out
-ls -Li d > out 2>/dev/null && fail=1
+{ ls -Li d > out 2>/dev/null || test $? -ne $LS_MINOR_PROBLEM; } && fail=1
 compare subdir_Li_exp out || fail=1
 
 # Ensure that ls -Ls prints "?" as the allocation of a dangling symlink.
 rm -f out
-ls -Ls d > out 2>/dev/null && fail=1
+{ ls -Ls d > out 2>/dev/null || test $? -ne $LS_MINOR_PROBLEM; } && fail=1
 compare subdir_Ls_exp out || fail=1
 
 Exit $fail
diff --git a/tests/ls/follow-slink.sh b/tests/ls/follow-slink.sh
index 58d77fb..142f054 100755
--- a/tests/ls/follow-slink.sh
+++ b/tests/ls/follow-slink.sh
@@ -19,6 +19,8 @@
 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
 print_ver_ ls
 
+LS_FAILURE=2
+
 # Isolate output files from directory being listed
 mkdir dir dir/sub dir1 || framework_failure_
 cd dir || framework_failure_
@@ -32,7 +34,7 @@ ls -F link > /dev/null || framework_failure_
 
 
 # When explicitly listing a broken link, the command must fail.
-ls -L link 2> /dev/null && fail=1
+{ ls -L link 2> /dev/null || test $? -ne $LS_FAILURE; } && fail=1
 
 # When encountering a broken link implicitly, Solaris 9 and OpenBSD 3.4
 # list the link, provided no further information about the link needed
diff --git a/tests/ls/stat-failed.sh b/tests/ls/stat-failed.sh
index cb8b3bd..22f32e3 100755
--- a/tests/ls/stat-failed.sh
+++ b/tests/ls/stat-failed.sh
@@ -21,6 +21,8 @@
 print_ver_ ls
 skip_if_root_
 
+LS_MINOR_PROBLEM=1
+
 mkdir d || framework_failure_
 ln -s / d/s || framework_failure_
 chmod 600 d || framework_failure_
@@ -38,7 +40,7 @@ sed 's/^l/?/' out | compare exp - || fail=1
 
 # Ensure that the offsets in --dired output are accurate.
 rm -f out exp
-ls --dired -l d > out && fail=1
+{ ls --dired -l d > out || test $? -ne $LS_MINOR_PROBLEM; } && fail=1
 
 cat <<\EOF > exp || fail=1
   total 0
diff --git a/tests/misc/cat-self.sh b/tests/misc/cat-self.sh
index 555177b..ccfa4e9 100755
--- a/tests/misc/cat-self.sh
+++ b/tests/misc/cat-self.sh
@@ -21,7 +21,7 @@ print_ver_ cat
 
 echo x >out || framework_failure_
 echo x >out1 || framework_failure_
-cat out >>out && fail=1
+{ cat out >>out || test $? -ne 1; } && fail=1
 compare out out1 || fail=1
 
 # This example is taken from the POSIX spec for 'cat'.
diff --git a/tests/misc/chcon-fail.sh b/tests/misc/chcon-fail.sh
index 48c3fcd..aecd5ec 100755
--- a/tests/misc/chcon-fail.sh
+++ b/tests/misc/chcon-fail.sh
@@ -22,16 +22,16 @@ print_ver_ chcon
 
 
 # neither context nor file
-chcon 2> /dev/null && fail=1
+{ chcon 2> /dev/null || test $? -ne 1; } && fail=1
 
 # No file
-chcon CON 2> /dev/null && fail=1
+{ chcon CON 2> /dev/null || test $? -ne 1; } && fail=1
 
 # No file
 touch f
-chcon --reference=f 2> /dev/null && fail=1
+{ chcon --reference=f 2> /dev/null || test $? -ne 1; } && fail=1
 
 # No file
-chcon -u anyone 2> /dev/null && fail=1
+{ chcon -u anyone 2> /dev/null || test $? -ne 1; } && fail=1
 
 Exit $fail
diff --git a/tests/misc/chroot-credentials.sh b/tests/misc/chroot-credentials.sh
index d33fe97..f0ce81a 100755
--- a/tests/misc/chroot-credentials.sh
+++ b/tests/misc/chroot-credentials.sh
@@ -22,6 +22,8 @@ print_ver_ chroot
 
 require_root_
 
+EXIT_CANCELED=125
+
 grep '^#define HAVE_SETGROUPS 1' "$CONFIG_HEADER" >/dev/null \
   && HAVE_SETGROUPS=1
 
@@ -36,7 +38,9 @@ chroot --userspec=$NON_ROOT_UID: / true || fail=1
 
 # verify that invalid groups are diagnosed
 for g in ' ' ',' '0trail'; do
-  test "$(chroot --groups="$g" / id -G)" && fail=1
+  { chroot --groups="$g" / id -G >invalid \
+    || test $? -ne $EXIT_CANCELED; } && fail=1
+  compare /dev/null invalid || fail=1
 done
 
 # Verify that root credentials are kept.
@@ -111,7 +115,7 @@ if ! id -u +12342; then
   test "$(chroot --userspec=+12342:+5678 / id -G)" = '5678' || fail=1
 
   # Ensure we fail when we don't know what groups to set for an unknown ID
-  chroot --userspec=+12342 / true && fail=1
+  { chroot --userspec=+12342 / true || test $? -ne $EXIT_CANCELED; } && fail=1
 fi
 
 Exit $fail
diff --git a/tests/misc/close-stdout.sh b/tests/misc/close-stdout.sh
index 0210678..0a13d49 100755
--- a/tests/misc/close-stdout.sh
+++ b/tests/misc/close-stdout.sh
@@ -44,22 +44,22 @@ sleep 0 >&- || fail=1
 # This test is ineffective unless /dev/stdout also works.
 if "$p/src/test" -w /dev/stdout >/dev/null &&
    "$p/src/test" ! -w /dev/stdout >&-; then
-  "$p/src/printf" 'foo' >&- 2>/dev/null && fail=1
-  cp --verbose a b >&- 2>/dev/null && fail=1
-  rm -Rf tmpfile-?????? || fail=1
-  mktemp tmpfile-XXXXXX >&- 2>/dev/null && fail=1
-  mktemp tmpfile-XXXXXX -q >&- 2>/dev/null && fail=1
-  case $(echo tmpfile-??????) in 'tmpfile-??????') ;; *) fail=1 ;; esac
+  { "$p/src/printf" 'foo' >&- 2>/dev/null || test $? -ne 1; } && fail=1
+  { cp --verbose a b >&- 2>/dev/null || test $? -ne 1; } && fail=1
+  rm -Rf tmpfile-????? || fail=1
+  { mktemp tmpfile-XXXXX >&- 2>/dev/null || test $? -ne 1; } && fail=1
+  { mktemp tmpfile-XXXXX -q >&- 2>/dev/null || test $? -ne 1; } && fail=1
+  case $(echo tmpfile-?????) in 'tmpfile-?????') ;; *) fail=1 ;; esac
 fi
 
 # Likewise for /dev/full, if /dev/full works.
 if test -w /dev/full && test -c /dev/full; then
-  "$p/src/printf" 'foo' >/dev/full 2>/dev/null && fail=1
-  cp --verbose a b >/dev/full 2>/dev/null && fail=1
-  rm -Rf tmpdir-?????? || fail=1
-  mktemp -d tmpdir-XXXXXX >/dev/full 2>/dev/null && fail=1
-  mktemp -d -q tmpdir-XXXXXX >/dev/full 2>/dev/null && fail=1
-  case $(echo tmpfile-??????) in 'tmpfile-??????') ;; *) fail=1 ;; esac
+    { "$p/src/printf" 'foo' >/dev/full 2>/dev/null || test $? -ne 1; } && 
fail=1
+  { cp --verbose a b >/dev/full 2>/dev/null || test $? -ne 1; } && fail=1
+  rm -Rf tmpdir-????? || fail=1
+  { mktemp -d tmpdir-XXXXX >/dev/full 2>/dev/null || test $? -ne 1; } && fail=1
+  { mktemp -dq tmpdir-XXXXX >/dev/full 2>/dev/null || test $? -ne 1; } && 
fail=1
+  case $(echo tmpfile-?????) in 'tmpfile-?????') ;; *) fail=1 ;; esac
 fi
 
 Exit $fail
diff --git a/tests/misc/env.sh b/tests/misc/env.sh
index 6994738..93a5328 100755
--- a/tests/misc/env.sh
+++ b/tests/misc/env.sh
@@ -102,7 +102,7 @@ cat <<EOF > unlikely_name/also_unlikely || 
framework_failure_
 echo pass
 EOF
 chmod +x unlikely_name/also_unlikely || framework_failure_
-env also_unlikely && fail=1
+{ env also_unlikely || test $? -ne 127; } && fail=1
 test x$(PATH=$PATH:unlikely_name env also_unlikely) = xpass || fail=1
 test x$(env PATH="$PATH":unlikely_name also_unlikely) = xpass || fail=1
 
diff --git a/tests/misc/false-status.sh b/tests/misc/false-status.sh
index 0b72c6a..5f86232 100755
--- a/tests/misc/false-status.sh
+++ b/tests/misc/false-status.sh
@@ -21,11 +21,15 @@
 print_ver_ false true
 
 env false --version > /dev/null && fail=1
+test $? -ne 1 && fail=1
 env false --help > /dev/null && fail=1
+test $? -ne 1 && fail=1
 
 if test -w /dev/full && test -c /dev/full; then
   env true --version > /dev/full && fail=1
+  test $? -ne 1 && fail=1
   env true --help > /dev/full && fail=1
+  test $? -ne 1 && fail=1
 fi
 
 Exit $fail
diff --git a/tests/misc/md5sum-bsd.sh b/tests/misc/md5sum-bsd.sh
index 9031c19..4165b5f 100755
--- a/tests/misc/md5sum-bsd.sh
+++ b/tests/misc/md5sum-bsd.sh
@@ -40,20 +40,20 @@ md5sum --strict -c check.md5 || fail=1
 # then it'll be detected as standard format and error.
 # This unlikely caveat was thought better than mandating
 # an option to avoid the ambiguity.
-tail -n+2 check.md5 | md5sum --strict -c && fail=1
+{ tail -n+2 check.md5 | md5sum --strict -c || test $? -ne 1; } && fail=1
 
 
 ## BSD traditional format tests (--tag option) ##
 
 # Ensure --tag and --check are mutually exclusive
-md5sum --tag --check /dev/null && fail=1
+{ md5sum --tag --check /dev/null || test $? -ne 1; } && fail=1
 
 # Ensure --tag and --text are mutually exclusive
 # We don't support --text with BSD tradition format,
 # as that would complicate the output format,
 # while providing little benefit over --text processing
 # available with the default md5sum output format.
-md5sum --tag --text /dev/null && fail=1
+{ md5sum --tag --text /dev/null || test $? -ne 1; } && fail=1
 
 # Ensure we can --check BSD traditional format we produce
 rm check.md5
diff --git a/tests/misc/nproc-positive.sh b/tests/misc/nproc-positive.sh
index a001d80..1309230 100755
--- a/tests/misc/nproc-positive.sh
+++ b/tests/misc/nproc-positive.sh
@@ -35,7 +35,7 @@ for i in 0 ' 1' 1000; do
 done
 
 for i in -1 N; do
-    nproc --ignore=$i && fail=1
+    { nproc --ignore=$i || test $? -ne 1; } && fail=1
 done
 
 procs=$(OMP_NUM_THREADS=42 nproc --ignore=40)
diff --git a/tests/misc/pathchk1.sh b/tests/misc/pathchk1.sh
index 74a1c85..e8932c6 100755
--- a/tests/misc/pathchk1.sh
+++ b/tests/misc/pathchk1.sh
@@ -25,14 +25,14 @@ touch file || framework_failure_
 
 # This should exit nonzero.  Before 2.0.13, it gave a diagnostic,
 # but exited successfully.
-pathchk file/x > /dev/null 2>&1 && fail=1
+{ pathchk file/x > /dev/null 2>&1 || test $? -ne 1; } && fail=1
 
 # This should exit nonzero.  Through 5.3.0 it exited with status zero.
-pathchk -p '' > /dev/null 2>&1 && fail=1
+{ pathchk -p '' > /dev/null 2>&1 || test $? -ne 1; } && fail=1
 
 # This tests the new -P option.
-pathchk -P '' > /dev/null 2>&1 && fail=1
-pathchk -P -- - > /dev/null 2>&1 && fail=1
-pathchk -p -P x/- > /dev/null 2>&1 && fail=1
+{ pathchk -P '' > /dev/null 2>&1 || test $? -ne 1; } && fail=1
+{ pathchk -P -- - > /dev/null 2>&1 || test $? -ne 1; } && fail=1
+{ pathchk -p -P x/- > /dev/null 2>&1 || test $? -ne 1; } && fail=1
 
 Exit $fail
diff --git a/tests/misc/printf.sh b/tests/misc/printf.sh
index 1423285..2c06ce7 100755
--- a/tests/misc/printf.sh
+++ b/tests/misc/printf.sh
@@ -25,7 +25,9 @@ getlimits_
 
 
 # Verify the 3 methods of specifying "Escape":
-test $($prog "\x1b\n\33\n\e\n" | uniq -u) && fail=1
+printf '%s\n' . . . | tr . '\033' > exp
+$prog '\x1b\n\33\n\e\n' > out || fail=1
+compare exp out || fail=1
 
 # This would fail (by printing the '--') for printf in sh-utils
 # and in coreutils 4.5.1.
@@ -69,16 +71,21 @@ $prog '9 %*dx\n' -2 0 >>out || fail=1
 
 $prog '10 %.*dx\n' $INT_UFLOW 0 >>out || fail=1
 $prog '%.*dx\n' $INT_OFLOW 0 >>out 2> /dev/null && fail=1
+test $? -ne 1 && fail=1
 
 $prog '11 %*c\n' 2 x >>out || fail=1
 
 $prog '%#d\n' 0 >>out 2> /dev/null && fail=1
+test $? -ne 1 && fail=1
 
 $prog '%0s\n' 0 >>out 2> /dev/null && fail=1
+test $? -ne 1 && fail=1
 
 $prog '%.9c\n' 0 >>out 2> /dev/null && fail=1
+test $? -ne 1 && fail=1
 
 $prog '%'\''s\n' 0 >>out 2> /dev/null && fail=1
+test $? -ne 1 && fail=1
 
 cat <<\EOF > exp
 1 x  y
diff --git a/tests/misc/realpath.sh b/tests/misc/realpath.sh
index 1d1d3ed..9fb1991 100755
--- a/tests/misc/realpath.sh
+++ b/tests/misc/realpath.sh
@@ -42,17 +42,18 @@ ln -s /// three || framework_failure_
 # Basic operation
 realpath -Pqz . >/dev/null || fail=1
 # Operand is required
-realpath >/dev/null && fail=1
-realpath --relative-base . --relative-to . && fail=1
-realpath --relative-base . && fail=1
+{ realpath >/dev/null || test $? -ne 1; } && fail=1
+{ realpath --relative-base . --relative-to . || test $? -ne 1; } && fail=1
+{ realpath --relative-base . || test $? -ne 1; } && fail=1
 
 # -e --relative-* require directories
-realpath -e --relative-to=dir1/f --relative-base=. . && fail=1
+{ realpath -e --relative-to=dir1/f --relative-base=. . || test $? -ne 1; } \
+  && fail=1
 realpath -e --relative-to=dir1/  --relative-base=. . || fail=1
 
 # Note NUL params are unconditionally rejected by canonicalize_filename_mode
-realpath -m '' && fail=1
-realpath --relative-base= --relative-to=. . && fail=1
+{ realpath -m '' || test $? -ne 1; } && fail=1
+{ realpath --relative-base= --relative-to=. . || test $? -ne 1; } && fail=1
 
 # symlink resolution
 this=$(realpath .)
diff --git a/tests/misc/selinux.sh b/tests/misc/selinux.sh
index 0914f50..9b0a1b3 100755
--- a/tests/misc/selinux.sh
+++ b/tests/misc/selinux.sh
@@ -47,7 +47,7 @@ c=$(ls -l f|cut -c11); test "$c" = . || fail=1
 # Copy with an invalid context and ensure it fails
 # Note this may succeed when root and selinux is in permissive mode
 if test "$(getenforce)" = Enforcing; then
-  cp --context='invalid-selinux-context' f f.cp && fail=1
+    { cp --context='invalid-selinux-ctx' f f.cp || test $? -ne 1; } && fail=1
 fi
 
 # Copy each to a new directory and ensure that context is preserved.
diff --git a/tests/misc/shred-remove.sh b/tests/misc/shred-remove.sh
index 8c04c26..9e4bc75 100755
--- a/tests/misc/shred-remove.sh
+++ b/tests/misc/shred-remove.sh
@@ -30,7 +30,7 @@ chmod u-w $file || framework_failure_
 # This would take so long that it appears to infloop
 # when using version from fileutils-4.0k.
 # When the command completes, expect it to fail.
-shred -u $file > /dev/null 2>&1 && fail=1
+{ shred -u $file > /dev/null 2>&1 || test $? -ne 1; } && fail=1
 rm -f $file || framework_failure_
 
 # Ensure all --remove methods at least unlink the file
@@ -42,6 +42,6 @@ done
 
 # Ensure incorrect params are diagnosed
 touch $file || framework_failure_
-shred -n0 --remove=none $file 2>/dev/null && fail=1
+{ shred -n0 --remove=none $file 2>/dev/null || test $? -ne 1; } && fail=1
 
 Exit $fail
diff --git a/tests/misc/sort-compress-proc.sh b/tests/misc/sort-compress-proc.sh
index 719dfc6..bcbcd84 100755
--- a/tests/misc/sort-compress-proc.sh
+++ b/tests/misc/sort-compress-proc.sh
@@ -20,6 +20,8 @@
 print_ver_ sort
 expensive_
 
+SORT_FAILURE=2
+
 seq -w 2000 > exp || fail=1
 tac exp > in || fail=1
 insize=$(stat -c %s - <in) || fail=1
@@ -53,6 +55,7 @@ do
       expr $size "<" '"$insize"' / 2 || { sleep 1; exit 1; }
     }
   ' sort --compress-program=./compress -S 1k --batch-size=2 in > out && fail=1
+  test $? -ne $SORT_FAILURE && fail=1
 done
 
 # "Pre-exec child" test
diff --git a/tests/misc/sort-exit-early.sh b/tests/misc/sort-exit-early.sh
index c2bc994..05c617c 100755
--- a/tests/misc/sort-exit-early.sh
+++ b/tests/misc/sort-exit-early.sh
@@ -20,18 +20,20 @@
 print_ver_ sort
 skip_if_root_
 
+SORT_FAILURE=2
+
 # Check output is writable before starting to sort
 touch input
 chmod a-w input
 timeout 10 sort -o input && fail=1
-test $? = 124 && fail=1
+test $? -ne $SORT_FAILURE && fail=1
 
 # Check all inputs are readable before starting to sort
 # Also ensure the output isn't created in this case
 touch output
 chmod a-r output
 timeout 10 sort -o typo - output && fail=1
-test $? = 124 && fail=1
+test $? -ne $SORT_FAILURE && fail=1
 test -e typo && fail=1
 
 Exit $fail
diff --git a/tests/misc/stat-hyphen.sh b/tests/misc/stat-hyphen.sh
index 2896bcb..bbc649b 100755
--- a/tests/misc/stat-hyphen.sh
+++ b/tests/misc/stat-hyphen.sh
@@ -23,7 +23,7 @@ printf -- '-\n' > exp || framework_failure_
 touch f || framework_failure_
 
 stat --format=%n - < f > out || fail=1
-stat -f - < f && fail=1
+{ stat -f - < f || test $? -ne 1; } && fail=1
 
 compare exp out || fail=1
 
diff --git a/tests/misc/stat-slash.sh b/tests/misc/stat-slash.sh
index 39cce2d..752b31c 100755
--- a/tests/misc/stat-slash.sh
+++ b/tests/misc/stat-slash.sh
@@ -33,7 +33,7 @@ EOF
 
 # This failed on Solaris 9 for coreutils 8.0.
 stat --format=%n link1 > out || fail=1
-stat --format=%n link1/ >> out && fail=1
+{ stat --format=%n link1/ >> out || test $? -ne 1; } && fail=1
 
 stat --format=%F link2 >> out || fail=1
 stat -L --format=%F link2 >> out || fail=1
diff --git a/tests/misc/stty-invalid.sh b/tests/misc/stty-invalid.sh
index f14af84..4d47c44 100755
--- a/tests/misc/stty-invalid.sh
+++ b/tests/misc/stty-invalid.sh
@@ -35,7 +35,9 @@ stty $saved_state || fail=1
 # stty would fail to diagnose the error on at least Solaris 10.
 hex_2_64=10000000000000000
 stty $(echo $saved_state |sed 's/^[^:]*:/'$hex_2_64:/)     2>/dev/null && 
fail=1
+test $? -ne 1 && fail=1
 stty $(echo $saved_state |sed 's/:[0-9a-f]*$/:'$hex_2_64/) 2>/dev/null && 
fail=1
+test $? -ne 1 && fail=1
 
 # Just in case either of the above mistakenly succeeds (and changes
 # the state of our tty), try to restore the initial state.
diff --git a/tests/misc/stty.sh b/tests/misc/stty.sh
index 787915b..57cb8a9 100755
--- a/tests/misc/stty.sh
+++ b/tests/misc/stty.sh
@@ -34,9 +34,9 @@ stty $(cat $saved_state) || fail=1
 stty erase - || fail=1
 
 # These would improperly ignore invalid options through coreutils 5.2.1.
-stty -F 2>/dev/null && fail=1
-stty -raw -F no/such/file 2>/dev/null && fail=1
-stty -raw -a 2>/dev/null && fail=1
+{ stty -F 2>/dev/null || test $? -ne 1; } && fail=1
+{ stty -raw -F no/such/file 2>/dev/null || test $? -ne 1; } && fail=1
+{ stty -raw -a 2>/dev/null || test $? -ne 1; } && fail=1
 
 # Build a list of all boolean options stty accepts on this system.
 # Don't depend on terminal width.  Put each option on its own line,
diff --git a/tests/misc/tr-case-class.sh b/tests/misc/tr-case-class.sh
index 162b74f..002b80b 100755
--- a/tests/misc/tr-case-class.sh
+++ b/tests/misc/tr-case-class.sh
@@ -29,11 +29,11 @@ tr '[:lower:][:lower:]' '[:upper:]0-9' > out || fail=1
 compare exp out || fail=1
 
 # Validate the alignment of case classes
-tr 'A-Z[:lower:]' 'a-y[:upper:]' < /dev/null && fail=1
-tr '[:upper:][:lower:]' 'a-y[:upper:]' < /dev/null && fail=1
-tr 'A-Y[:lower:]' 'a-z[:upper:]' < /dev/null && fail=1
-tr 'A-Z[:lower:]' '[:lower:][:upper:]' < /dev/null && fail=1
-tr 'A-Z[:lower:]' '[:lower:]A-Z' < /dev/null && fail=1
+{ tr 'A-Z[:lower:]' 'a-y[:upper:]' </dev/null || test $? -ne 1; } && fail=1
+{ tr '[:upper:][:lower:]' 'a-y[:upper:]' </dev/null || test $? -ne 1; } 
&&fail=1
+{ tr 'A-Y[:lower:]' 'a-z[:upper:]' </dev/null || test $? -ne 1; } && fail=1
+{ tr 'A-Z[:lower:]' '[:lower:][:upper:]' </dev/null || test $? -ne 1; } 
&&fail=1
+{ tr 'A-Z[:lower:]' '[:lower:]A-Z' </dev/null || test $? -ne 1; } && fail=1
 tr '[:upper:][:lower:]' 'a-z[:upper:]' < /dev/null || fail=1
 tr '[:upper:][:lower:]' '[:upper:]a-z' < /dev/null || fail=1
 
diff --git a/tests/misc/truncate-dir-fail.sh b/tests/misc/truncate-dir-fail.sh
index b2e7677..ac5a855 100755
--- a/tests/misc/truncate-dir-fail.sh
+++ b/tests/misc/truncate-dir-fail.sh
@@ -20,6 +20,6 @@
 print_ver_ truncate
 
 # truncate on dir not allowed
-truncate -s+0 . && fail=1
+{ truncate -s+0 . || test $? -ne 1; } && fail=1
 
 Exit $fail
diff --git a/tests/misc/truncate-overflow.sh b/tests/misc/truncate-overflow.sh
index a4a513c..1d571c2 100755
--- a/tests/misc/truncate-overflow.sh
+++ b/tests/misc/truncate-overflow.sh
@@ -27,13 +27,13 @@ truncate -s-1 create-zero-len-file || fail=1
 echo > non-empty-file
 
 # signed overflow
-truncate -s$OFF_T_OFLOW file && fail=1
+{ truncate -s$OFF_T_OFLOW file || test $? -ne 1; } && fail=1
 
 # += signed overflow
-truncate -s+$OFF_T_MAX non-empty-file && fail=1
+{ truncate -s+$OFF_T_MAX non-empty-file || test $? -ne 1; } && fail=1
 
 # *= signed overflow
 IO_BLOCK_OFLOW=$(expr $OFF_T_MAX / $(stat -f -c%s .) + 1)
-truncate --io-blocks --size=$IO_BLOCK_OFLOW file && fail=1
+{ truncate --io-blocks --size=$IO_BLOCK_OFLOW file || test $? -ne 1; } && 
fail=1
 
 Exit $fail
diff --git a/tests/misc/truncate-parameters.sh 
b/tests/misc/truncate-parameters.sh
index 62eb2c1..9c46282 100755
--- a/tests/misc/truncate-parameters.sh
+++ b/tests/misc/truncate-parameters.sh
@@ -21,22 +21,22 @@ print_ver_ truncate
 
 
 # must specify at least 1 file
-truncate --size=0 && fail=1
+{ truncate --size=0 || test $? -ne 1; } && fail=1
 
 # must specify size. don't default to 0
-truncate file && fail=1
+{ truncate file || test $? -ne 1; } && fail=1
 
 # mixture of absolute size & reference not allowed
-truncate --size=0 --reference=file file && fail=1
+{ truncate --size=0 --reference=file file || test $? -ne 1; } && fail=1
 
 # blocks without size is not valid
-truncate --io-blocks --reference=file file && fail=1
+{ truncate --io-blocks --reference=file file || test $? -ne 1; } && fail=1
 
 # must specify valid numbers
-truncate --size="invalid" file && fail=1
+{ truncate --size="invalid" file || test $? -ne 1; } && fail=1
 
 # spaces not significant around size
-truncate --size="> -1" file && fail=1
+{ truncate --size="> -1" file || test $? -ne 1; } && fail=1
 truncate --size=" >1" file || fail=1 #file now 1
 truncate --size=" +1" file || fail=1 #file now 2
 test $(stat --format %s file) = 2 || fail=1
diff --git a/tests/misc/truncate-relative.sh b/tests/misc/truncate-relative.sh
index 933e763..b79c581 100755
--- a/tests/misc/truncate-relative.sh
+++ b/tests/misc/truncate-relative.sh
@@ -21,15 +21,15 @@ print_ver_ truncate
 
 
 # mixture of relative modifiers not allowed
-truncate --size="+>0" file && fail=1
+{ truncate --size="+>0" file || test $? -ne 1; } && fail=1
 
 # mixture of relative modifiers not allowed
-truncate --size=">+0" file && fail=1
+{ truncate --size=">+0" file || test $? -ne 1; } && fail=1
 
 # division by zero
-truncate --size="/0" file && fail=1
+{ truncate --size="/0" file || test $? -ne 1; } && fail=1
 
 # division by zero
-truncate --size="%0" file && fail=1
+{ truncate --size="%0" file || test $? -ne 1; } && fail=1
 
 Exit $fail
diff --git a/tests/misc/wc-parallel.sh b/tests/misc/wc-parallel.sh
index c522ea7..2d1e9f4 100755
--- a/tests/misc/wc-parallel.sh
+++ b/tests/misc/wc-parallel.sh
@@ -25,8 +25,9 @@ print_ver_ wc
 # This will output at least 16KiB per process
 # and start 3 processes, with 2 running concurrently,
 # which triggers often on Fedora 11 at least.
-(find tmp tmp tmp -type f | xargs -n2000 -P2 wc) |
+(find tmp tmp tmp -type f | xargs -n2000 -P2 wc 2>err) |
 sed -n '/0 0 0 /!p' |
 grep . > /dev/null && fail=1
+compare /dev/null err || fail=1
 
 Exit $fail
diff --git a/tests/mkdir/p-3.sh b/tests/mkdir/p-3.sh
index 6ffa533..4ab700f 100755
--- a/tests/mkdir/p-3.sh
+++ b/tests/mkdir/p-3.sh
@@ -28,6 +28,7 @@ mkdir -p no-acce3s/d || framework_failure_
 
 p=$(pwd)
 (cd no-access && chmod 0 . && mkdir -p "$p/a/b" u/v) 2> /dev/null && fail=1
+test $? -ne 1 && fail=1
 test -d "$p/a/b" || fail=1
 
 # Same as above, but with a following *absolute* name, it should succeed
diff --git a/tests/mkdir/parents.sh b/tests/mkdir/parents.sh
index 2bc5419..ce373e8 100755
--- a/tests/mkdir/parents.sh
+++ b/tests/mkdir/parents.sh
@@ -26,7 +26,7 @@ mkdir -m 700 e-dir || framework_failure_
 # Make sure 'mkdir -p existing-dir' succeeds
 # and that 'mkdir existing-dir' fails.
 mkdir -p e-dir || fail=1
-mkdir e-dir > /dev/null 2>&1 && fail=1
+{ mkdir e-dir > /dev/null 2>&1 || test $? -ne 1; } && fail=1
 
 # Create an existing directory.
 umask 077
diff --git a/tests/mkdir/perm.sh b/tests/mkdir/perm.sh
index ab78f1f..ff0a57d 100755
--- a/tests/mkdir/perm.sh
+++ b/tests/mkdir/perm.sh
@@ -59,7 +59,7 @@ for p in empty -p; do
 
     # If we're not using -p, then create the parent manually,
     # and adjust expectations accordingly.
-    test x$p = x && \
+    test x$p = x &&
       {
         mkdir -m =,u=rwx parent || fail=1
         parent_perms=drwx------
diff --git a/tests/mkdir/special-1.sh b/tests/mkdir/special-1.sh
index 94b6f8c..5b90af2 100755
--- a/tests/mkdir/special-1.sh
+++ b/tests/mkdir/special-1.sh
@@ -36,7 +36,7 @@ rmdir $tmp || fail=1
 tmp2=$tmp/sub
 
 # This should fail.
-mkdir -m$set_mode_string $tmp2 2> /dev/null && fail=1
+{ mkdir -m$set_mode_string $tmp2 2> /dev/null || test $? -ne 1; } && fail=1
 
 # Now test the --parents option.
 mkdir --parents -m$set_mode_string $tmp2 || fail=1
diff --git a/tests/mv/childproof.sh b/tests/mv/childproof.sh
index bb7e661..89dca5a 100755
--- a/tests/mv/childproof.sh
+++ b/tests/mv/childproof.sh
@@ -28,7 +28,7 @@ echo a > a/f || framework_failure_
 echo b > b/f || framework_failure_
 
 
-cp a/f b/f c 2> /dev/null && fail=1
+{ cp a/f b/f c 2> /dev/null || test $? -ne 1; } && fail=1
 test -f a/f || fail=1
 test -f b/f || fail=1
 test -f c/f || fail=1
@@ -43,7 +43,7 @@ test -f c/f || fail=1
 test -f c/f.~1~ || fail=1
 rm -f c/f*
 
-mv a/f b/f c 2> /dev/null && fail=1
+{ mv a/f b/f c 2> /dev/null || test $? -ne 1; } && fail=1
 test -f a/f && fail=1
 test -f b/f || fail=1
 test -f c/f || fail=1
@@ -62,7 +62,7 @@ test -f c/f || fail=1
 test -f c/g || fail=1
 
 touch a/f b/f b/g
-mv a/f b/f b/g c 2> /dev/null && fail=1
+{ mv a/f b/f b/g c 2> /dev/null || test $? -ne 1; } && fail=1
 test -f a/f && fail=1  # a/f should have been moved
 test -f b/f || fail=1  # b/f should remain
 test -f b/g && fail=1  # b/g should have been moved
@@ -74,7 +74,7 @@ test -f c/g || fail=1
 rm -f a/f b/f c/f
 echo a > a/f || fail=1
 echo b > b/f || fail=1
-ln -f a/f b/f c 2> /dev/null && fail=1
+{ ln -f a/f b/f c 2> /dev/null || test $? -ne 1; } && fail=1
 # a/f and c/f must be linked
 test $(stat --format %i a/f) = $(stat --format %i c/f) || fail=1
 # b/f and c/f must not be linked
diff --git a/tests/mv/dir-file.sh b/tests/mv/dir-file.sh
index 36b1a7d..512fb7f 100755
--- a/tests/mv/dir-file.sh
+++ b/tests/mv/dir-file.sh
@@ -24,7 +24,7 @@ mkdir -p dir/file || framework_failure_
 
 
 # These should both fail, but until fileutils-4.0q only the second one did.
-mv dir file > /dev/null 2>&1 && fail=1
-mv file dir > /dev/null 2>&1 && fail=1
+{ mv dir file > /dev/null 2>&1 || test $? -ne 1; } && fail=1
+{ mv file dir > /dev/null 2>&1 || test $? -ne 1; } && fail=1
 
 Exit $fail
diff --git a/tests/mv/hardlink-case.sh b/tests/mv/hardlink-case.sh
index 4a0b2a5..871f514 100755
--- a/tests/mv/hardlink-case.sh
+++ b/tests/mv/hardlink-case.sh
@@ -31,7 +31,7 @@ mount hfs.img mnt       || skip_ 'failed to mount hfs file 
system'
 cd mnt
 touch foo
 ln foo whatever
-mv foo Foo && fail=1
+{ mv foo Foo || test $? -ne 1; } && fail=1
 test -r foo || fail=1
 
 Exit $fail
diff --git a/tests/mv/into-self-4.sh b/tests/mv/into-self-4.sh
index fe0322e..fb94711 100755
--- a/tests/mv/into-self-4.sh
+++ b/tests/mv/into-self-4.sh
@@ -25,7 +25,7 @@ ln -s file s || framework_failure_
 
 
 # This must fail.
-mv s s 2> /dev/null && fail=1
+{ mv s s 2> /dev/null || test $? -ne 1; } && fail=1
 
 # But the symlink, s, must not be removed.
 # Before 4.0.36, 's' would have been removed.
diff --git a/tests/mv/mv-n.sh b/tests/mv/mv-n.sh
index 9713333..4ee9a90 100755
--- a/tests/mv/mv-n.sh
+++ b/tests/mv/mv-n.sh
@@ -52,6 +52,6 @@ compare out5 out_empty || fail=1
 
 # options --backup and --no-clobber are mutually exclusive
 touch a || framework_failure_
-mv -bn a b 2>/dev/null && fail=1
+{ mv -bn a b 2>/dev/null || test $? -ne 1; } && fail=1
 
 Exit $fail
diff --git a/tests/mv/no-target-dir.sh b/tests/mv/no-target-dir.sh
index 9f8ece0..962748c 100755
--- a/tests/mv/no-target-dir.sh
+++ b/tests/mv/no-target-dir.sh
@@ -20,6 +20,8 @@
 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
 print_ver_ mv
 
+LS_FAILURE=2
+
 mkdir -p d/sub empty src d2/sub e2 || framework_failure_
 touch f || framework_failure_
 
@@ -35,15 +37,15 @@ mv a b ||
 mv -fT d empty || fail=1
 
 # Ensure that the source, d, is gone.
-ls -d d > /dev/null 2>&1 && fail=1
+{ ls -d d > /dev/null 2>&1 || test $? -ne $LS_FAILURE; } && fail=1
 
 # Ensure that the dest dir now has a subdirectory.
 test -d empty/sub || fail=1
 
 # rename must fail, since the dest is non-empty.
-mv -fT src d2 2> /dev/null && fail=1
+{ mv -fT src d2 2> /dev/null || test $? -ne 1; } && fail=1
 
 # rename must fail, since the src is not a directory.
-mv -fT f e2 2> /dev/null && fail=1
+{ mv -fT f e2 2> /dev/null || test $? -ne 1; } && fail=1
 
 Exit $fail
diff --git a/tests/mv/part-rename.sh b/tests/mv/part-rename.sh
index da88260..46357bc 100755
--- a/tests/mv/part-rename.sh
+++ b/tests/mv/part-rename.sh
@@ -31,13 +31,13 @@ mv foo/ "$other_partition_tmpdir/bar" || fail=1
 
 # Moving a non directory from source shouldn't replace empty dir in dest
 touch bar || framework_failure_
-mv bar "$other_partition_tmpdir/" && fail=1
+{ mv bar "$other_partition_tmpdir/" || test $? -ne 1; } && fail=1
 
 
 # Moving a directory from source shouldn't replace non directory in dest
 mkdir bar2
 touch "$other_partition_tmpdir/bar2"
-mv bar2 "$other_partition_tmpdir/" && fail=1
+{ mv bar2 "$other_partition_tmpdir/" || test $? -ne 1; } && fail=1
 
 
 # As per POSIX moving directory from source should replace empty dir in dest
@@ -51,7 +51,7 @@ test -e "$other_partition_tmpdir/bar3/file" || fail=1
 # As per POSIX moving directory from source shouldn't update dir in dest
 mkdir bar3
 touch bar3/file2
-mv bar3 "$other_partition_tmpdir/" && fail=1
+{ mv bar3 "$other_partition_tmpdir/" || test $? -ne 1; } && fail=1
 test -e "$other_partition_tmpdir/bar3/file2" && fail=1
 
 Exit $fail
diff --git a/tests/readlink/can-e.sh b/tests/readlink/can-e.sh
index 91bea78..0a2eb37 100755
--- a/tests/readlink/can-e.sh
+++ b/tests/readlink/can-e.sh
@@ -39,6 +39,7 @@ cd "$pwd/$tmp/removed" || framework_failure_
 # Skip this test if the system doesn't let you remove the working directory.
 if rmdir ../removed 2>/dev/null; then
   v=$(readlink -e .) && fail=1
+  test $? -ne 1 && fail=1
   test -z "$v" || fail=1
 fi
 
@@ -50,6 +51,7 @@ for p in "" "$pwd/$tmp/"; do
   test "$v" = "$my_pwd/$tmp/regfile" || fail=1
 
   v=$(readlink -e "${p}./regfile/") && fail=1
+  test $? -ne 1 && fail=1
   test -z "$v" || fail=1
 
   v=$(readlink -e "${p}subdir") || fail=1
@@ -59,18 +61,22 @@ for p in "" "$pwd/$tmp/"; do
   test "$v" = "$my_pwd/$tmp/subdir" || fail=1
 
   v=$(readlink -e "${p}missing") && fail=1
+  test $? -ne 1 && fail=1
   test -z "$v" || fail=1
 
   v=$(readlink -e "${p}./missing/") && fail=1
+  test $? -ne 1 && fail=1
   test -z "$v" || fail=1
 
   v=$(readlink -e "${p}link1") || fail=1
   test "$v" = "$my_pwd/$tmp/regfile" || fail=1
 
   v=$(readlink -e "${p}./link1/") && fail=1
+  test $? -ne 1 && fail=1
   test -z "$v" || fail=1
 
   v=$(readlink -e "${p}link1/more") && fail=1
+  test $? -ne 1 && fail=1
   test -z "$v" || fail=1
 
   v=$(readlink -e "${p}link2") || fail=1
@@ -80,24 +86,31 @@ for p in "" "$pwd/$tmp/"; do
   test "$v" = "$my_pwd/$tmp/subdir" || fail=1
 
   v=$(readlink -e "${p}link2/more") && fail=1
+  test $? -ne 1 && fail=1
   test -z "$v" || fail=1
 
   v=$(readlink -e "${p}link3") && fail=1
+  test $? -ne 1 && fail=1
   test -z "$v" || fail=1
 
   v=$(readlink -e "${p}./link3/") && fail=1
+  test $? -ne 1 && fail=1
   test -z "$v" || fail=1
 
   v=$(readlink -e "${p}link3/more") && fail=1
+  test $? -ne 1 && fail=1
   test -z "$v" || fail=1
 
   v=$(readlink -e "${p}link4") && fail=1
+  test $? -ne 1 && fail=1
   test -z "$v" || fail=1
 
   v=$(readlink -e "${p}./link4/") && fail=1
+  test $? -ne 1 && fail=1
   test -z "$v" || fail=1
 
   v=$(readlink -e "${p}link4/more") && fail=1
+  test $? -ne 1 && fail=1
   test -z "$v" || fail=1
 done
 
diff --git a/tests/readlink/multi.sh b/tests/readlink/multi.sh
index 17aab40..14703b5 100755
--- a/tests/readlink/multi.sh
+++ b/tests/readlink/multi.sh
@@ -23,8 +23,8 @@ touch regfile || framework_failure_
 ln -s regfile link1 || framework_failure_
 
 readlink link1 link1 || fail=1
-readlink link1 link2 && fail=1
-readlink link1 link2 link1 && fail=1
+{ readlink link1 link2 || test $? -ne 1; } && fail=1
+{ readlink link1 link2 link1 || test $? -ne 1; } && fail=1
 readlink -m link1 link2 || fail=1
 
 printf '/1\0/1\0' > exp || framework_failure_
diff --git a/tests/readlink/rl-1.sh b/tests/readlink/rl-1.sh
index a6b92c7..de34386 100755
--- a/tests/readlink/rl-1.sh
+++ b/tests/readlink/rl-1.sh
@@ -32,12 +32,15 @@ v=$(readlink link2) || fail=1
 test "$v" = missing || fail=1
 
 v=$(readlink subdir) && fail=1
+test $? -ne 1 && fail=1
 test -z "$v" || fail=1
 
 v=$(readlink regfile) && fail=1
+test $? -ne 1 && fail=1
 test -z "$v" || fail=1
 
 v=$(readlink missing) && fail=1
+test $? -ne 1 && fail=1
 test -z "$v" || fail=1
 
 Exit $fail
diff --git a/tests/rm/i-no-r.sh b/tests/rm/i-no-r.sh
index e7f7196..f4ab3e8 100755
--- a/tests/rm/i-no-r.sh
+++ b/tests/rm/i-no-r.sh
@@ -26,7 +26,7 @@ echo y > y || framework_failure_
 
 
 # This must fail.
-rm -i dir < y > /dev/null 2>&1 && fail=1
+{ rm -i dir < y > /dev/null 2>&1 || test $? -ne 1; } && fail=1
 
 # The directory must remain.
 test -d dir || fail=1
diff --git a/tests/rm/no-give-up.sh b/tests/rm/no-give-up.sh
index b7b5b0e..669cff7 100755
--- a/tests/rm/no-give-up.sh
+++ b/tests/rm/no-give-up.sh
@@ -32,6 +32,7 @@ chmod go=x . || framework_failure_
 # This must fail, since '.' is not writable by $NON_ROOT_USERNAME.
 chroot --skip-chdir --user=$NON_ROOT_USERNAME / env PATH="$PATH" \
   rm -rf d 2>/dev/null && fail=1
+test $? -ne 1 && fail=1
 
 # d must remain.
 test -d d || fail=1
diff --git a/tests/rm/rm4.sh b/tests/rm/rm4.sh
index 28ff20b..df00dd0 100755
--- a/tests/rm/rm4.sh
+++ b/tests/rm/rm4.sh
@@ -24,7 +24,7 @@ mkdir dir || framework_failure_
 
 
 # This should fail.
-rm dir > /dev/null 2>&1 && fail=1
+{ rm dir > /dev/null 2>&1 || test $? -ne 1; } && fail=1
 
 test -d dir || fail=1
 
diff --git a/tests/rm/sunos-1.sh b/tests/rm/sunos-1.sh
index d246821..cc2b70b 100755
--- a/tests/rm/sunos-1.sh
+++ b/tests/rm/sunos-1.sh
@@ -24,6 +24,6 @@
 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
 print_ver_ rm
 
-rm -r '' > /dev/null 2>&1 && fail=1
+{ rm -r '' > /dev/null 2>&1 || test $? -ne 1; } && fail=1
 
 Exit $fail
diff --git a/tests/rmdir/fail-perm.sh b/tests/rmdir/fail-perm.sh
index 4026201..a11f6bd 100755
--- a/tests/rmdir/fail-perm.sh
+++ b/tests/rmdir/fail-perm.sh
@@ -27,6 +27,6 @@ chmod a-w d || framework_failure_
 # This rmdir command outputs two diagnostics.
 # Before coreutils-5.1.2, it would mistakenly exit successfully.
 # As of coreutils-5.1.2, it fails, as required.
-rmdir -p d d/e/f 2> /dev/null && fail=1
+{ rmdir -p d d/e/f 2> /dev/null || test $? -ne 1; } && fail=1
 
 Exit $fail
diff --git a/tests/split/additional-suffix.sh b/tests/split/additional-suffix.sh
index 9195915..77c75bc 100755
--- a/tests/split/additional-suffix.sh
+++ b/tests/split/additional-suffix.sh
@@ -39,6 +39,7 @@ compare exp-2 xab.txt || fail=1
 compare exp-3 xac.txt || fail=1
 
 # Additional suffix must not contain slash
-split --lines=2 --additional-suffix=a/b in 2>/dev/null > out && fail=1
+{ split --lines=2 --additional-suffix=a/b in 2>/dev/null > out \
+  || test $? -ne 1; } && fail=1
 
 Exit $fail
diff --git a/tests/split/fail.sh b/tests/split/fail.sh
index 6725995..7a59336 100755
--- a/tests/split/fail.sh
+++ b/tests/split/fail.sh
@@ -24,13 +24,13 @@ touch in || framework_failure_
 
 
 split -a 0 in 2> /dev/null || fail=1
-split -b 0 in 2> /dev/null && fail=1
-split -C 0 in 2> /dev/null && fail=1
-split -l 0 in 2> /dev/null && fail=1
-split -n 0 in 2> /dev/null && fail=1
-split -n 1/0 in 2> /dev/null && fail=1
-split -n 0/1 in 2> /dev/null && fail=1
-split -n 2/1 in 2> /dev/null && fail=1
+{ split -b 0 in 2> /dev/null || test $? -ne 1; } && fail=1
+{ split -C 0 in 2> /dev/null || test $? -ne 1; } && fail=1
+{ split -l 0 in 2> /dev/null || test $? -ne 1; } && fail=1
+{ split -n 0 in 2> /dev/null || test $? -ne 1; } && fail=1
+{ split -n 1/0 in 2> /dev/null || test $? -ne 1; } && fail=1
+{ split -n 0/1 in 2> /dev/null || test $? -ne 1; } && fail=1
+{ split -n 2/1 in 2> /dev/null || test $? -ne 1; } && fail=1
 
 # Make sure -C doesn't create empty files.
 rm -f x?? || fail=1
@@ -42,21 +42,22 @@ test -f xac && fail=1
 split -1 in 2> /dev/null || fail=1
 
 # Then make sure that -0 evokes a failure.
-split -0 in 2> /dev/null && fail=1
+{ split -0 in 2> /dev/null || test $? f-ne 1; } && fail=1
 
 split --lines=$UINTMAX_MAX in || fail=1
 split --bytes=$OFF_T_MAX in || fail=1
-split --line-bytes=$OFF_T_OFLOW 2> /dev/null in && fail=1
-split --line-bytes=$SIZE_OFLOW 2> /dev/null in && fail=1
+{ split --line-bytes=$OFF_T_OFLOW 2> /dev/null in || test $? -ne 1; } && fail=1
+{ split --line-bytes=$SIZE_OFLOW 2> /dev/null in || test $? -ne 1; } && fail=1
 if truncate -s$SIZE_OFLOW large; then
   # Ensure we can split chunks of a large file on 32 bit hosts
   split --number=$SIZE_OFLOW/$SIZE_OFLOW large >/dev/null || fail=1
 fi
 split --number=r/$UINTMAX_MAX/$UINTMAX_MAX </dev/null >/dev/null || fail=1
-split --number=r/$UINTMAX_OFLOW </dev/null 2>/dev/null && fail=1
+{ split --number=r/$UINTMAX_OFLOW </dev/null 2>/dev/null || test $? -ne 1; } \
+  && fail=1
 
 # Make sure that a huge obsolete option evokes the right failure.
-split -99999999999999999991 2> out && fail=1
+{ split -99999999999999999991 2> out || test $? -ne 1; } && fail=1
 
 # On losing systems (x86 Solaris 5.9 c89), we get a message like this:
 #   split: line count option -9999999999... is too large
@@ -75,7 +76,7 @@ compare exp out || fail=1
 # (the current directory in this case)
 if ! cat . >/dev/null; then
   # can't read() directories
-  split . && fail=1
+  { split . || test $? -ne 1; } && fail=1
 fi
 
 Exit $fail
diff --git a/tests/split/filter.sh b/tests/split/filter.sh
index 93a1beb..d3d2bfc 100755
--- a/tests/split/filter.sh
+++ b/tests/split/filter.sh
@@ -44,7 +44,7 @@ split -e -n 10 --filter='xz > $FILE.xz' /dev/null || fail=1
 stat x?? 2>/dev/null && fail=1
 
 # Ensure this invalid combination is flagged
-split -n 1/2 --filter='true' /dev/null 2>/dev/null && fail=1
+{ split -n 1/2 --filter='true' /dev/null 2>&1 || test $? -ne 1; } && fail=1
 
 # Ensure SIGPIPEs sent by the children don't propagate back
 # where they would result in a non zero exit from split.
diff --git a/tests/split/guard-input.sh b/tests/split/guard-input.sh
index cc41360..ccf546a 100755
--- a/tests/split/guard-input.sh
+++ b/tests/split/guard-input.sh
@@ -23,10 +23,10 @@ seq 10 | tee exp-1 > xaa
 ln -s xaa in2
 ln xaa in3
 
-split -C 6 xaa && fail=1
-split -C 6 in2 && fail=1
-split -C 6 in3 && fail=1
-split -C 6 - < xaa && fail=1
+{ split -C 6 xaa || test $? -ne 1; } && fail=1
+{ split -C 6 in2 || test $? -ne 1; } && fail=1
+{ split -C 6 in3 || test $? -ne 1; } && fail=1
+{ split -C 6 - < xaa || test $? -ne 1; } && fail=1
 
 compare exp-1 xaa || fail=1
 
diff --git a/tests/split/numeric.sh b/tests/split/numeric.sh
index e404305..1644a5a 100755
--- a/tests/split/numeric.sh
+++ b/tests/split/numeric.sh
@@ -56,10 +56,10 @@ compare exp-3 x03 || fail=1
 
 # Check that split failed when suffix length is not large enough for
 # the numerical suffix start value
-split -a 3 --numeric-suffixes=1000 in 2> /dev/null && fail=1
+{ split -a 3 --numeric-suffixes=1000 in 2>/dev/null || test $? -ne 1; } 
&&fail=1
 
 # check invalid --numeric-suffixes start values are flagged
-split --numeric-suffixes=-1 in 2> /dev/null && fail=1
-split --numeric-suffixes=one in 2> /dev/null && fail=1
+{ split --numeric-suffixes=-1 in 2> /dev/null || test $? -ne 1; } && fail=1
+{ split --numeric-suffixes=one in 2> /dev/null || test $? -ne 1; } && fail=1
 
 Exit $fail
diff --git a/tests/split/suffix-auto-length.sh 
b/tests/split/suffix-auto-length.sh
index a50bd23..6249c96 100755
--- a/tests/split/suffix-auto-length.sh
+++ b/tests/split/suffix-auto-length.sh
@@ -22,7 +22,7 @@ print_ver_ split
 
 # ensure this feature is off when start number specified
 truncate -s12 file.in
-split file.in -b1 --numeric=89 && fail=1
+{ split file.in -b1 --numeric=89 || test $? -ne 1; } && fail=1
 test "$(ls -1 x* | wc -l)" = 11 || fail=1
 rm -f x*
 
diff --git a/tests/split/suffix-length.sh b/tests/split/suffix-length.sh
index 48f83eb..d9d28f7 100755
--- a/tests/split/suffix-length.sh
+++ b/tests/split/suffix-length.sh
@@ -70,7 +70,7 @@ split -a2 -C1000 < /dev/null || fail=1
 
 # Ensure that -a fails early with a -n that is too large
 rm -f x*
-split -a2 -n1000 < /dev/null && fail=1
+{ split -a2 -n1000 < /dev/null || test $? -ne 1; } && fail=1
 test -f xaa && fail=1
 
 Exit $fail
diff --git a/tests/touch/no-dereference.sh b/tests/touch/no-dereference.sh
index a4c85c2..ef1c7af 100755
--- a/tests/touch/no-dereference.sh
+++ b/tests/touch/no-dereference.sh
@@ -26,7 +26,7 @@ ln -s file link || framework_failure_
 
 # These first tests should work on every platform.
 # -h does not create files, but it warns.  Use -c to silence warning.
-touch -h no-file 2> err && fail=1
+{ touch -h no-file 2> err || test $? -ne 1; } && fail=1
 test -s err || fail=1
 touch -h -c no-file 2> err || fail=1
 compare /dev/null err || fail=1
@@ -75,7 +75,7 @@ touch -h - > file || fail=1
 # If stdout is open, it is not a symlink.
 if env test -w /dev/stdout >/dev/null &&
    env test ! -w /dev/stdout >&-; then
-  touch -h - >&- && fail=1
+  { touch -h - >&- || test $? -ne 1; } && fail=1
   touch -h -c - >&- || fail=1
 fi
 
diff --git a/tests/touch/trailing-slash.sh b/tests/touch/trailing-slash.sh
index a6463fa..a8b11e9 100755
--- a/tests/touch/trailing-slash.sh
+++ b/tests/touch/trailing-slash.sh
@@ -29,22 +29,22 @@ ln -s dir link2 || framework_failure_
 
 # Trailing slash can only appear on directory or symlink-to-directory.
 # Up through coreutils 8.0, Solaris 9 failed these tests.
-touch no-file/ && fail=1
-touch file/ && fail=1
-touch dangling/ && fail=1
-touch loop/ && fail=1
-touch link1/ && fail=1
+{ touch no-file/ || test $? -ne 1; } && fail=1
+{ touch file/ || test $? -ne 1; } && fail=1
+{ touch dangling/ || test $? -ne 1; } && fail=1
+{ touch loop/ || test $? -ne 1; } && fail=1
+{ touch link1/ || test $? -ne 1; } && fail=1
 touch dir/ || fail=1
 
 # -c silences ENOENT, but not ENOTDIR or ELOOP
 touch -c no-file/ || fail=1
-touch -c file/ && fail=1
+{ touch -c file/ || test $? -ne 1; } && fail=1
 touch -c dangling/ || fail=1
-touch -c loop/ && fail=1
-touch -c link1/ && fail=1
+{ touch -c loop/ || test $? -ne 1; } && fail=1
+{ touch -c link1/ || test $? -ne 1; } && fail=1
 touch -c dir/ || fail=1
-test -f no-file && fail=1
-test -f nowhere && fail=1
+{ test -f no-file || test $? -ne 1; } && fail=1
+{ test -f nowhere || test $? -ne 1; } && fail=1
 
 # Trailing slash dereferences a symlink, even with -h.
 # mtime is sufficient to show pass (besides, lstat changes atime of
-- 
2.1.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]