]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tests: add extra protection against unexpected exits
authorPádraig Brady <P@draigBrady.com>
Tue, 13 Jan 2015 03:30:33 +0000 (03:30 +0000)
committerPádraig Brady <P@draigBrady.com>
Wed, 14 Jan 2015 12:20:32 +0000 (12:20 +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 explicitly
check the expected exit code.
Note where error messages are also verified, the extra
protection is not added.

* tests/init.sh (returns_): A new helper function to
check the return code of a command, and used
throughout the tests.
* cfg.mk (sc_prohibit_and_fail_1): Add a syntax check
to avoid new instances of this issue.

93 files changed:
cfg.mk
tests/chmod/octal.sh
tests/chmod/umask-x.sh
tests/chmod/usage.sh
tests/chown/basic.sh
tests/chown/separator.sh
tests/cp/cp-HL.sh
tests/cp/cp-a-selinux.sh
tests/cp/cp-i.sh
tests/cp/cp-parents.sh
tests/cp/dir-vs-file.sh
tests/cp/fail-perm.sh
tests/cp/no-ctx.sh
tests/cp/reflink-auto.sh
tests/cp/sparse.sh
tests/dd/misc.sh
tests/dd/nocache.sh
tests/dd/stderr.sh
tests/df/no-mtab-status.sh
tests/df/skip-rootfs.sh
tests/du/deref.sh
tests/id/context.sh
tests/id/gnu-zero-uids.sh
tests/id/uid.sh
tests/id/zero.sh
tests/init.sh
tests/install/basic-1.sh
tests/install/install-C.sh
tests/install/strip-program.sh
tests/ln/misc.sh
tests/ln/slash-decorated-nonexistent-dest.sh
tests/ls/dangle.sh
tests/ls/follow-slink.sh
tests/ls/stat-failed.sh
tests/misc/cat-self.sh
tests/misc/chcon-fail.sh
tests/misc/chroot-credentials.sh
tests/misc/close-stdout.sh
tests/misc/cut-huge-range.sh
tests/misc/env.sh
tests/misc/false-status.sh
tests/misc/md5sum-bsd.sh
tests/misc/nproc-positive.sh
tests/misc/pathchk1.sh
tests/misc/printf.sh
tests/misc/realpath.sh
tests/misc/selinux.sh
tests/misc/shred-remove.sh
tests/misc/sort-compress-proc.sh
tests/misc/sort-exit-early.sh
tests/misc/stat-hyphen.sh
tests/misc/stat-slash.sh
tests/misc/stty-invalid.sh
tests/misc/stty.sh
tests/misc/tr-case-class.sh
tests/misc/truncate-dir-fail.sh
tests/misc/truncate-overflow.sh
tests/misc/truncate-parameters.sh
tests/misc/truncate-relative.sh
tests/misc/wc-parallel.sh
tests/mkdir/p-3.sh
tests/mkdir/parents.sh
tests/mkdir/perm.sh
tests/mkdir/special-1.sh
tests/mv/childproof.sh
tests/mv/dir-file.sh
tests/mv/hardlink-case.sh
tests/mv/into-self-4.sh
tests/mv/mv-n.sh
tests/mv/no-target-dir.sh
tests/mv/part-rename.sh
tests/mv/trailing-slash.sh
tests/readlink/can-e.sh
tests/readlink/can-f.sh
tests/readlink/can-m.sh
tests/readlink/multi.sh
tests/readlink/rl-1.sh
tests/rm/i-no-r.sh
tests/rm/no-give-up.sh
tests/rm/r-4.sh
tests/rm/r-root.sh
tests/rm/rm4.sh
tests/rm/sunos-1.sh
tests/rmdir/fail-perm.sh
tests/split/additional-suffix.sh
tests/split/fail.sh
tests/split/filter.sh
tests/split/guard-input.sh
tests/split/numeric.sh
tests/split/suffix-auto-length.sh
tests/split/suffix-length.sh
tests/touch/no-dereference.sh
tests/touch/trailing-slash.sh

diff --git a/cfg.mk b/cfg.mk
index 91045b852efc0f4b72b30bc46d623e1b6ec2d40b..70ca2e5ddb0d76a8ac4c166561fc5221e88be737 100644 (file)
--- a/cfg.mk
+++ b/cfg.mk
@@ -377,6 +377,17 @@ sc_prohibit_fail_0:
        halt='fail=0 initialization'                                    \
          $(_sc_search_regexp)
 
+# Ensure that tests don't use `cmd ... && fail=1` as that hides crashes.
+# The "exclude" expression allows common idioms like `test ... && fail=1`
+# and the 2>... portion allows commands that redirect stderr and so probably
+# independently check its contents and thus detect any crash messages.
+sc_prohibit_and_fail_1:
+       @prohibit='&& fail=1'                                           \
+       exclude='(stat|kill|test |EGREP|grep|env|2> *[^/])'             \
+       halt='&& fail=1 detected. Please use: returns_ 1 ... || fail=1' \
+       in_vc_files='^tests/'                                           \
+         $(_sc_search_regexp)
+
 # The mode part of a setfacl -m option argument must be three bytes long.
 # I.e., an argument of user:bin:rw or user:bin:r will make Solaris 10's
 # setfacl reject it with: "Unrecognized character found in mode field".
index 6f47a076c88b00aee97c92170f3242f940a0c43a..23d0542f77c560b37868cef31582840713dfc32a 100755 (executable)
@@ -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
+  returns_ 1 chmod "$mode" . 2>/dev/null || fail=1
+done
 
 Exit $fail
index 85b087d05e92b3a960d909b31c81068073becbf6..f31452a3c4e05fd10fef02d523d3245dba6f1f9a 100755 (executable)
@@ -21,6 +21,6 @@ print_ver_ chmod
 
 touch file
 chmod 755 file
-(umask 77 && chmod -x file) 2>/dev/null && fail=1
+(umask 77 && returns_ 1 chmod -x file) 2>/dev/null || fail=1
 
 Exit $fail
index 133115233c6e9b04879741897368ce3e7f7be5d2..ac6d635abe2ad0a64a3401ca0fd65d969063d95f 100755 (executable)
@@ -67,7 +67,7 @@ for case in $cases; do
   case $files in
   '')
     touch -- $all_files || framework_failure_
-    chmod $args 2>/dev/null && fail=1
+    returns_ 1 chmod $args 2>/dev/null || 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
+      returns_ 1 chmod $args 2>/dev/null || fail=1
     done
     ;;
   esac
index 3eee1569410ceddefc4148a2fab13b82056a4545..e57b9c8905e6a87b3610b0eed50d2b9e7effa49a 100755 (executable)
@@ -34,7 +34,7 @@ printf "ownership of 'f' retained as $(id -nu)\n" > exp
 compare exp out || fail=1
 
 # Ensure diagnostics work for non existent files.
-chown -v 0 nf > out && fail=1
+returns_ 1 chown -v 0 nf > out || fail=1
 printf "failed to change ownership of 'nf' to 0\n" > exp
 compare exp out || fail=1
 
index 815533036bdb2eb184593d617e3c7c91d6d73a0a..642b00238e082f883f5781d8bdcb7b003cffa5ff 100755 (executable)
@@ -59,7 +59,7 @@ 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) returns_ 1 chown "$u$sep$g" . 2>/dev/null || fail=1 ;;
         *) chown "$u$sep$g" . || fail=1 ;;
       esac
     done
index fa983253737ba2849ed20afa6ef54fdcc2e51c40..08a72b13aca80c27c480d5295fbf03908d728025 100755 (executable)
@@ -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
+returns_ 1 cat dest-dir/src-dir/slink >/dev/null 2>&1 || fail=1
 
 # FIXME: test -L, too.
 
index 2ecbd238685156ca34dbbfc199f433ec47086ea2..d000ee8f17261f8a7f935bcaeb2c758bc28f3f83 100755 (executable)
@@ -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
+  returns_ 1 cp -Z "$ctx" ../f g || 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
+returns_ 1 cp -Z --preserve=context ../f g || fail=1
+returns_ 1 cp --preserve=context -Z ../f g || fail=1
+returns_ 1 cp --preserve=context --context="$ctx" ../f g || fail=1
 
 Exit $fail
index d9d8051165916ee2547a17075d864098356db09c..e7414130701e70100570c9b6e400910306a9b0e7 100755 (executable)
@@ -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
+returns_ 1 cp -bn c d 2>/dev/null || fail=1
 
 Exit $fail
index 4814d6557248cae435c559a5f25d805708fc0eed..f0454f7145da68e6e7ced9064a34a5c025175236 100755 (executable)
@@ -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
+returns_ 1 cp --parents f/g d 2>/dev/null || fail=1
 test -d d/f && fail=1
 
 # Check that re_protect works.
index 826d9bce096c2119cfed2fc3c38a421184a15348..8ac159c04eef81428a5c0a2d31660fe2a31db942 100755 (executable)
@@ -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
+returns_ 1 cp -R dir file 2>/dev/null || fail=1
 
 # Make sure file is not replaced with a directory.
 # In 4.0.35, it was.
index abc5e4ebed988f3a7dd199a3f30a8de15a2fada2..6a9cc8804dbbf7a0a5f0809f98acccd9c6e84440 100755 (executable)
@@ -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
+returns_ 1 cp -pR D DD > /dev/null 2>&1 || fail=1
 
 # Permissions on DD must be 'dr-x------'
 
index 3cae5831439e50c38ffc90c8a0fc4a6b9540df0a..19d68b8fff971616e1e3833f0034becb5f50fd52 100755 (executable)
@@ -57,7 +57,7 @@ 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 returns_ 1 cp --preserve=context file_src file_dst || fail=1
 
 test -e preloaded || skip_ 'LD_PRELOAD interception failed'
 
index 666620879dc3c2ab585dfb3e3c393f3058840951..b0464a2eb7886bbfdb11388aae0366c449c999a8 100755 (executable)
@@ -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
+returns_ 1 cp --reflink "$a_other" b || fail=1
 
 # --reflink=auto should fall back to a normal copy
 cp --reflink=auto "$a_other" b || fail=1
index 3d6fb58762056d40c4eef507fb2cc8946ad24dc8..958de8306cd4855baa2aecf1214441c8a0655b8b 100755 (executable)
@@ -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
+returns_ 1 cp --sparse=always --reflink sparse copy || fail=1
+returns_ 1 cp --sparse=never --reflink sparse copy || fail=1
 
 
 # Ensure we handle sparse/non-sparse transitions correctly
index 59f0f50a733db53b8d886906a0f1f7c360eceaf0..2a536e8d724c826e3e83993ae78e0e52f401eacc 100755 (executable)
@@ -40,7 +40,7 @@ dd status=noxfer status=none if=$tmp_in of=/dev/null 2> err || fail=1
 compare /dev/null err || fail=1
 # check later status=noxfer overrides earlier status=none
 dd status=none status=noxfer if=$tmp_in of=/dev/null 2> err || fail=1
-compare /dev/null err && fail=1
+test -s err || fail=1
 
 dd if=$tmp_in of=$tmp_out 2> /dev/null || fail=1
 compare $tmp_in $tmp_out || fail=1
@@ -61,12 +61,12 @@ 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
+  returns_ 1 dd iflag=nofollow if=$tmp_sym count=0 2> /dev/null || 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
+  returns_ 1 dd iflag=directory count=0 <$tmp_in 2> /dev/null || fail=1
 fi
 
 old_ls=$(ls -u --full-time $tmp_in)
@@ -87,8 +87,8 @@ 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
+  returns_ 1 dd iflag=nolinks if=$tmp_in > /dev/null 2>&1 || fail=1
+  returns_ 1 dd iflag=nolinks < $tmp_in > /dev/null 2>&1 || fail=1
   dd oflag=nolinks < $tmp_in > $tmp_out 2>&1 || fail=1
 fi
 
index 33421480ac4c0512990ef9deecd8322bee84f665..e7fdf4e5e87b2362189dfaa02c773c7189b83667 100755 (executable)
@@ -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 | returns_ 1 dd iflag=nocache count=0 || fail=1
 
 # O_DIRECT is orthogonal to drop cache so mutually exclusive
-dd iflag=nocache,direct if=/dev/null && fail=1
+returns_ 1 dd iflag=nocache,direct if=/dev/null || fail=1
 
 # The rest ensure that the documented uses cases
 # proceed without error
index ce67a7a9e92ab9dd80e006cb4212792450b77085..82ab08f17d07279edc20a40a7716732a95918596 100755 (executable)
@@ -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
+  : | returns_ 1 dd 2>&- || 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
+  : | returns_ 1 dd 2>/dev/full || fail=1
 fi
 
 Exit $fail
index d9899c4ad1e80bd9bcee4393fa7a9918bc88a952..0c1bec8ef27125781680fcf08053f3574a45cafb 100755 (executable)
@@ -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 returns_ 1 df || fail=1
+LD_PRELOAD=./k.so returns_ 1 df -i || fail=1
+LD_PRELOAD=./k.so returns_ 1 df -T || fail=1
+LD_PRELOAD=./k.so returns_ 1 df -Ti || fail=1
+LD_PRELOAD=./k.so returns_ 1 df --total || fail=1
 
-LD_PRELOAD=./k.so df -a && fail=1
-LD_PRELOAD=./k.so df -a '.' && fail=1
+LD_PRELOAD=./k.so returns_ 1 df -a || fail=1
+LD_PRELOAD=./k.so returns_ 1 df -a '.' || fail=1
 
-LD_PRELOAD=./k.so df -l && fail=1
-LD_PRELOAD=./k.so df -l '.' && fail=1
+LD_PRELOAD=./k.so returns_ 1 df -l || fail=1
+LD_PRELOAD=./k.so returns_ 1 df -l '.' || fail=1
 
-LD_PRELOAD=./k.so df -t hello && fail=1
-LD_PRELOAD=./k.so df -t hello '.' && fail=1
+LD_PRELOAD=./k.so returns_ 1 df -t hello || fail=1
+LD_PRELOAD=./k.so returns_ 1 df -t hello '.' || fail=1
 
-LD_PRELOAD=./k.so df -x hello && fail=1
-LD_PRELOAD=./k.so df -x hello '.' && fail=1
+LD_PRELOAD=./k.so returns_ 1 df -x hello || fail=1
+LD_PRELOAD=./k.so returns_ 1 df -x hello '.' || fail=1
 
 Exit $fail
index ed5364eb361530b2905e534c7ffa84244b2877e7..c42253dc341a592f92afd19bffc7a3943a201572 100755 (executable)
@@ -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
+returns_ 1 df -t rootfs >out || fail=1
 grep '^rootfs' out && { fail=1; cat out; }
 
 # Ensure that the rootfs is shown when explicitly both specifying "-t rootfs"
index 670ee5cc6c8a54bb83d032a4fefd8246ecacb431..6c2a4724198a0bcfe1baceccd50ebb9e70daaf9b 100755 (executable)
@@ -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
+returns_ 1 du -L dangle > /dev/null 2>&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)
index 754d0c3baf02860bd176011b1905a489005cb93d..b1aefe73f5858da1dd71eb1555b0ab60fe83f216 100755 (executable)
@@ -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 "$name"; then
+  id "$name" > id_name || fail=1
+  grep context= id_name >/dev/null && fail=1
+fi
 
 Exit $fail
index edd74f7dd8b7c29961160720581507c33a6aabec..c2ee6cfb3450d62258d61e097e04e7d9d4d3d9ee 100755 (executable)
@@ -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
+returns_ 1 sush - id > out || fail=1
 
 Exit $fail
index c0766b321c9408ef1fb37fcd17b97de348e50a0a..e7a8385862ef63dc28f753a4ef836097d5461765 100755 (executable)
@@ -22,7 +22,7 @@ uid=$(id -u) || fail=1
 user=$(id -nu) || fail=1
 
 # Ensure the empty user spec is discarded
-id '' && fail=1
+returns_ 1 id '' || fail=1
 
 for mode in '' '-G' '-g'; do
   id $mode $user > user_out || fail=1 # lookup name for comparison
index a67a789e26618aa4eeb2391bd7ffe8e76534f08f..7bee3a644311aac2490092f2332466525294b357 100755 (executable)
@@ -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
index 37fc7b62ee8e39f906798c4b71bf988fde8554ea..added1760c8458e828555f0c7fabb237b019c964 100755 (executable)
@@ -93,6 +93,19 @@ skip_ () { warn_ "$ME_: skipped test: $@"; Exit 77; }
 fatal_ () { warn_ "$ME_: hard error: $@"; Exit 99; }
 framework_failure_ () { warn_ "$ME_: set-up failure: $@"; Exit 99; }
 
+# This is used to simplify checking of the return value
+# which is useful when ensuring a command fails as desired.
+# I.E. just doing `command ... &&fail=1` will not catch
+# a segfault in command for example.  With this helper you
+# instead check an explicit exit code like
+#   returns_ 1 command ... || fail
+returns_ () {
+  local exp_exit="$1"
+  shift
+  "$@"
+  test $? -eq $exp_exit
+}
+
 # Sanitize this shell to POSIX mode, if possible.
 DUALCASE=1; export DUALCASE
 if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
index 3a1bfae8d3a8124728479683b97dfe51b47df61a..db3b3c31db8977b8953cc2a166595cf1a9c16bd8 100755 (executable)
@@ -80,8 +80,8 @@ iwd=$(pwd)
 mkdir sub || fail=1
 (cd sub &&
  chmod 0 . &&
- ginstall -d "$iwd/xx/yy" rel/sub1 rel/sub2 2> /dev/null
-) && fail=1
returns_ 1 ginstall -d "$iwd/xx/yy" rel/sub1 rel/sub2 2> /dev/null
+) || fail=1
 chmod 755 sub
 
 # Ensure that the first argument-dir has been created.
index 214e3ae1414be5086b46ddfb0ba22e69f4c6c929..630005c89f2194d716d52f084b785185aa9648ad 100755 (executable)
@@ -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
+returns_ 1 ginstall -C --preserve-timestamps a b || fail=1
 
 # options -C and --strip are mutually exclusive
-ginstall -C --strip --strip-program=echo a b && fail=1
+returns_ 1 ginstall -C --strip --strip-program=echo a b || fail=1
 
 Exit $fail
index 1350e30d2a974d678dcd147911f4956404a337a8..7ac2165ea7628b7310578351ff348b99b27fa0b2 100755 (executable)
@@ -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
+returns_ 1 ginstall src dest2 -s --strip-program=./FOO || fail=1
 test -e dest2 && fail=1
 
 Exit $fail
index 9b23fdab47f1b20fdffb02a8d9d086fd4affc6b9..68756309a62d8d1653acad01e09f552bff3f561d 100755 (executable)
@@ -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
+returns_ 1 ln $f $d/ 2> /dev/null || fail=1
+returns_ 1 ln -s $f $d/ 2> /dev/null || 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
+returns_ 1 ln -s $t $t 2> /dev/null || 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
+returns_ 1 ln -sf $t $t 2> /dev/null || fail=1
 rm $t
 
 # Create a symlink with source file and no explicit directory
index dc5b189942088c463cd16ab77960b162c588c1dc..7a0696f2fe7f466a487f913bdfe46424e127ff3b 100755 (executable)
@@ -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
+returns_ 1 ln -T f no-such-file/ || fail=1
 test -e no-such-file && fail=1
 
 Exit $fail
index 1f1849d2bdbe7d842a1b45d7821d9c7402154587..d27f03fe5f8bf14f472871ebdcaeb86ab3683800 100755 (executable)
@@ -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
+returns_ $LS_FAILURE ls -L dangle > /dev/null 2>&1 || fail=1
 # So must this.
-ls -H dangle > /dev/null 2>&1 && fail=1
+returns_ $LS_FAILURE ls -H dangle > /dev/null 2>&1 || 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
+returns_ $LS_MINOR_PROBLEM ls -Li d > out 2>/dev/null || 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
+returns_ $LS_MINOR_PROBLEM ls -Ls d > out 2>/dev/null || fail=1
 compare subdir_Ls_exp out || fail=1
 
 Exit $fail
index 58d77fba413f42277e67d8ea46e2c1cf096b7f5c..edf6a4810ecf4b45eb2c78b0f90e4d26c1d35baf 100755 (executable)
@@ -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
+returns_ $LS_FAILURE ls -L link 2> /dev/null || 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
index cb8b3bd269c2b261e2ebb3c65113ae9cc795c562..002b71cf4093634d3353c6477e452f6f7031f52e 100755 (executable)
@@ -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
+returns_ $LS_MINOR_PROBLEM ls --dired -l d > out || fail=1
 
 cat <<\EOF > exp || fail=1
   total 0
index 555177b1f894065ffa26b363d7c1cb567be0dee5..57777e537f4a819204c89b9baf4e560894fd2c54 100755 (executable)
@@ -21,7 +21,7 @@ print_ver_ cat
 
 echo x >out || framework_failure_
 echo x >out1 || framework_failure_
-cat out >>out && fail=1
+returns_ 1 cat out >>out || fail=1
 compare out out1 || fail=1
 
 # This example is taken from the POSIX spec for 'cat'.
index 48c3fcdfc758b5c490d3030efff644269eed86ee..5265fa011da0df60787a853fcb34636b1c8d26a7 100755 (executable)
@@ -22,16 +22,16 @@ print_ver_ chcon
 
 
 # neither context nor file
-chcon 2> /dev/null && fail=1
+returns_ 1 chcon 2> /dev/null || fail=1
 
 # No file
-chcon CON 2> /dev/null && fail=1
+returns_ 1 chcon CON 2> /dev/null || fail=1
 
 # No file
 touch f
-chcon --reference=f 2> /dev/null && fail=1
+returns_ 1 chcon --reference=f 2> /dev/null || fail=1
 
 # No file
-chcon -u anyone 2> /dev/null && fail=1
+returns_ 1 chcon -u anyone 2> /dev/null || fail=1
 
 Exit $fail
index d33fe97b12533274249dd00745431c5efb4b90b1..8b67710000c2d12d81e4854f7428f83f8d740992 100755 (executable)
@@ -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,8 @@ 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
+  returns_ $EXIT_CANCELED chroot --groups="$g" / id -G >invalid || fail=1
+  compare /dev/null invalid || fail=1
 done
 
 # Verify that root credentials are kept.
@@ -111,7 +114,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
+  returns_ $EXIT_CANCELED chroot --userspec=+12342 / true || fail=1
 fi
 
 Exit $fail
index 0210678db2c819053f8a61f63b87368cdafd7b67..6714ec0f3df76b2d8cd835dcfe8d118327736942 100755 (executable)
@@ -44,21 +44,21 @@ 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
+  returns_ 1 "$p/src/printf" 'foo' >&- 2>/dev/null || fail=1
+  returns_ 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
+  returns_ 1 mktemp tmpfile-XXXXXX >&- 2>/dev/null || fail=1
+  returns_ 1 mktemp tmpfile-XXXXXX -q >&- 2>/dev/null || 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
+  returns_ 1 "$p/src/printf" 'foo' >/dev/full 2>/dev/null || fail=1
+  returns_ 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
+  returns_ 1 mktemp -d tmpdir-XXXXXX >/dev/full 2>/dev/null || fail=1
+  returns_ 1 mktemp -d -q tmpdir-XXXXXX >/dev/full 2>/dev/null || fail=1
   case $(echo tmpfile-??????) in 'tmpfile-??????') ;; *) fail=1 ;; esac
 fi
 
index f0713d05a1c6828b017e232be73171a723c412aa..035d8d0875224566ed8b262d472309cf0b870537 100755 (executable)
@@ -56,8 +56,8 @@ CUT_MAX=$(echo $SIZE_MAX | sed "$subtract_one")
 (ulimit -v 20000; : | cut -b1-$CUT_MAX >> err 2>&1) || fail=1
 
 # Explicitly disallow values above CUT_MAX
-(ulimit -v 20000; : | cut -b$SIZE_MAX 2>/dev/null) && fail=1
-(ulimit -v 20000; : | cut -b$SIZE_OFLOW 2>/dev/null) && fail=1
+(ulimit -v 20000; : | returns_ 1 cut -b$SIZE_MAX 2>/dev/null) || fail=1
+(ulimit -v 20000; : | returns_ 1 cut -b$SIZE_OFLOW 2>/dev/null) || fail=1
 
 compare /dev/null err || fail=1
 
index 6994738f0c750e308a8ca810c89af15c67c327de..d7c5a099ae5216d8ce55438a430fb608760f23ab 100755 (executable)
@@ -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
+returns_ 127 env also_unlikely || 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
 
index 0b72c6aad338b15ce7795ae2bfcd2fdca5e2cc72..03fe98c2ecc59f608b58d7ecb648489cdad73672 100755 (executable)
 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
 print_ver_ false true
 
-env false --version > /dev/null && fail=1
-env false --help > /dev/null && fail=1
+returns_ 1 env false --version > /dev/null || fail=1
+returns_ 1 env false --help > /dev/null || fail=1
 
 if test -w /dev/full && test -c /dev/full; then
-  env true --version > /dev/full && fail=1
-  env true --help > /dev/full && fail=1
+  returns_ 1 env true --version > /dev/full || fail=1
+  returns_ 1 env true --help > /dev/full || fail=1
 fi
 
 Exit $fail
index 9031c1901c33c0bc60ced4b619466a2dce0fabd7..a092894b5449ed448c01b23c5273ba60a84142c2 100755 (executable)
@@ -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 | returns_ 1 md5sum --strict -c || fail=1
 
 
 ## BSD traditional format tests (--tag option) ##
 
 # Ensure --tag and --check are mutually exclusive
-md5sum --tag --check /dev/null && fail=1
+returns_ 1 md5sum --tag --check /dev/null || 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
+returns_ 1 md5sum --tag --text /dev/null || fail=1
 
 # Ensure we can --check BSD traditional format we produce
 rm check.md5
index a001d8049cf451bf1fa9834b4eeb694fce4bac6f..fb825facb0d923678dcf09ae26642fbe788a0f63 100755 (executable)
@@ -35,7 +35,7 @@ for i in 0 ' 1' 1000; do
 done
 
 for i in -1 N; do
-    nproc --ignore=$i && fail=1
+    returns_ 1 nproc --ignore=$i || fail=1
 done
 
 procs=$(OMP_NUM_THREADS=42 nproc --ignore=40)
index 74a1c850ce811b13ba1f1e70b05e5e45b26e7e3f..6c8a50883c04a665dc1f2fc185978d1dbfc24954 100755 (executable)
@@ -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
+returns_ 1 pathchk file/x > /dev/null 2>&1 || fail=1
 
 # This should exit nonzero.  Through 5.3.0 it exited with status zero.
-pathchk -p '' > /dev/null 2>&1 && fail=1
+returns_ 1 pathchk -p '' > /dev/null 2>&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
+returns_ 1 pathchk -P '' > /dev/null 2>&1 || fail=1
+returns_ 1 pathchk -P -- - > /dev/null 2>&1 || fail=1
+returns_ 1 pathchk -p -P x/- > /dev/null 2>&1 || fail=1
 
 Exit $fail
index 142328595b0f7c2d0461a189ff4244f17c566c5d..87ca489f266c1bd12344bb1e4e2a1ba7c876943c 100755 (executable)
@@ -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.
@@ -68,17 +70,17 @@ $prog '8 %b %b %b %b\n' '\1y' '\01y' '\001y' '\0001y'|tr '\1' = >> out
 $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
+returns_ 1 $prog '%.*dx\n' $INT_OFLOW 0 >>out 2> /dev/null || fail=1
 
 $prog '11 %*c\n' 2 x >>out || fail=1
 
-$prog '%#d\n' 0 >>out 2> /dev/null && fail=1
+returns_ 1 $prog '%#d\n' 0 >>out 2> /dev/null || fail=1
 
-$prog '%0s\n' 0 >>out 2> /dev/null && fail=1
+returns_ 1 $prog '%0s\n' 0 >>out 2> /dev/null || fail=1
 
-$prog '%.9c\n' 0 >>out 2> /dev/null && fail=1
+returns_ 1 $prog '%.9c\n' 0 >>out 2> /dev/null || fail=1
 
-$prog '%'\''s\n' 0 >>out 2> /dev/null && fail=1
+returns_ 1 $prog '%'\''s\n' 0 >>out 2> /dev/null || fail=1
 
 cat <<\EOF > exp
 1 x  y
index 1d1d3ed75f982237bd81e41d3ed799938498ed33..ed4be3962592f12d0e16449cbc39108533d2d809 100755 (executable)
@@ -42,17 +42,17 @@ 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
+returns_ 1 realpath >/dev/null || fail=1
+returns_ 1 realpath --relative-base . --relative-to . || fail=1
+returns_ 1 realpath --relative-base . || fail=1
 
 # -e --relative-* require directories
-realpath -e --relative-to=dir1/f --relative-base=. . && fail=1
+returns_ 1 realpath -e --relative-to=dir1/f --relative-base=. . || 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
+returns_ 1 realpath -m '' || fail=1
+returns_ 1 realpath --relative-base= --relative-to=. . || fail=1
 
 # symlink resolution
 this=$(realpath .)
index 0914f50ddf5a61eb428ff34bc1819fb6c66bb5bb..1f906dde992abd23a56eb88e8c5b25fa02a1b0bc 100755 (executable)
@@ -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
+  returns_ 1 cp --context='invalid-selinux-context' f f.cp || fail=1
 fi
 
 # Copy each to a new directory and ensure that context is preserved.
index 8c04c26a324c8a4a740b6aa0af97ef922a40f199..cb27c1caf378a98901330805df3c7c8fbe74ff8f 100755 (executable)
@@ -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
+returns_ 1 shred -u $file > /dev/null 2>&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
+returns_ 1 shred -n0 --remove=none $file 2>/dev/null || fail=1
 
 Exit $fail
index 719dfc6caddc93bd0d6b191ea91ee576fb9d13a7..a191a3c511954694f80d4ad17cc4a92460fde4a5 100755 (executable)
@@ -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
@@ -52,7 +54,8 @@ do
       exec >/dev/null 2>&1 <&1 || exit
       expr $size "<" '"$insize"' / 2 || { sleep 1; exit 1; }
     }
-  ' sort --compress-program=./compress -S 1k --batch-size=2 in > out && fail=1
+  ' sort --compress-program=./compress -S 1k --batch-size=2 in > out
+  test $? -eq $SORT_FAILURE || fail=1
 done
 
 # "Pre-exec child" test
index c2bc9949d89c1734676a8054765c24bb45aef14c..c675503c40d4ee143c92cd6e8c217f461db7dfc8 100755 (executable)
 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
+returns_ $SORT_FAILURE timeout 10 sort -o input || 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
+returns_ $SORT_FAILURE timeout 10 sort -o typo - output || fail=1
 test -e typo && fail=1
 
 Exit $fail
index 2896bcb5bd31327e7c42a363cf76fb55047f9985..a2e0a3fbdce0d730b5e8a441e0742afb67f5ce21 100755 (executable)
@@ -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
+returns_ 1 stat -f - < f || fail=1
 
 compare exp out || fail=1
 
index 39cce2d75cec566d41f7ff0e678a3dcab11702f3..fecb7b6951b07b6962cb3b7826bcafac08ef2269 100755 (executable)
@@ -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
+returns_ 1 stat --format=%n link1/ >> out || fail=1
 
 stat --format=%F link2 >> out || fail=1
 stat -L --format=%F link2 >> out || fail=1
index f14af840d2f89541c14c0a63359779cf6cd0e2b5..881146f65627a82ba6a8cc01008a5c7a744c5a7a 100755 (executable)
@@ -34,8 +34,10 @@ stty $saved_state || fail=1
 # For each of the following, with coreutils-6.9 and earlier,
 # 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
-stty $(echo $saved_state |sed 's/:[0-9a-f]*$/:'$hex_2_64/) 2>/dev/null && fail=1
+returns_ 1 stty $(echo $saved_state |sed 's/^[^:]*:/'$hex_2_64:/) \
+  2>/dev/null || fail=1
+returns_ 1 stty $(echo $saved_state |sed 's/:[0-9a-f]*$/:'$hex_2_64/) \
+  2>/dev/null || fail=1
 
 # Just in case either of the above mistakenly succeeds (and changes
 # the state of our tty), try to restore the initial state.
index 787915b87fcc24df3433f1db524a46480ed97e03..5c2575522d4c4be9e4e101434f21e8ca0f91b2d9 100755 (executable)
@@ -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
+returns_ 1 stty -F 2>/dev/null || fail=1
+returns_ 1 stty -raw -F no/such/file 2>/dev/null || fail=1
+returns_ 1 stty -raw -a 2>/dev/null || 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,
index 162b74f3a125da216142a719d768d9dbd89bfd04..07c376077fc79f35d7e38f65380d74e6a233cabb 100755 (executable)
@@ -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
+returns_ 1 tr 'A-Z[:lower:]' 'a-y[:upper:]' </dev/null || fail=1
+returns_ 1 tr '[:upper:][:lower:]' 'a-y[:upper:]' </dev/null || fail=1
+returns_ 1 tr 'A-Y[:lower:]' 'a-z[:upper:]' </dev/null || fail=1
+returns_ 1 tr 'A-Z[:lower:]' '[:lower:][:upper:]' </dev/null || fail=1
+returns_ 1 tr 'A-Z[:lower:]' '[:lower:]A-Z' </dev/null || fail=1
 tr '[:upper:][:lower:]' 'a-z[:upper:]' < /dev/null || fail=1
 tr '[:upper:][:lower:]' '[:upper:]a-z' < /dev/null || fail=1
 
index b2e76772f1bec91acdbeda6dd95b30504062e41f..7787381ee8512d3e64a33705beb91aa39a83ef93 100755 (executable)
@@ -20,6 +20,6 @@
 print_ver_ truncate
 
 # truncate on dir not allowed
-truncate -s+0 . && fail=1
+returns_ 1 truncate -s+0 . || fail=1
 
 Exit $fail
index a4a513cf00195e48e52147bf1c4d2c029024861d..c690c4068332e8d87b3184a8657903a848874f77 100755 (executable)
@@ -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
+returns_ 1 truncate -s$OFF_T_OFLOW file || fail=1
 
 # += signed overflow
-truncate -s+$OFF_T_MAX non-empty-file && fail=1
+returns_ 1 truncate -s+$OFF_T_MAX non-empty-file || 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
+returns_ 1 truncate --io-blocks --size=$IO_BLOCK_OFLOW file || fail=1
 
 Exit $fail
index 62eb2c18f3abb0c0a4fe794ccb11f1bbc4624a9c..d3cf594003e0314fa47d0bc8bd9d8a028a031fc7 100755 (executable)
@@ -21,22 +21,22 @@ print_ver_ truncate
 
 
 # must specify at least 1 file
-truncate --size=0 && fail=1
+returns_ 1 truncate --size=0 || fail=1
 
 # must specify size. don't default to 0
-truncate file && fail=1
+returns_ 1 truncate file || fail=1
 
 # mixture of absolute size & reference not allowed
-truncate --size=0 --reference=file file && fail=1
+returns_ 1 truncate --size=0 --reference=file file || fail=1
 
 # blocks without size is not valid
-truncate --io-blocks --reference=file file && fail=1
+returns_ 1 truncate --io-blocks --reference=file file || fail=1
 
 # must specify valid numbers
-truncate --size="invalid" file && fail=1
+returns_ 1 truncate --size="invalid" file || fail=1
 
 # spaces not significant around size
-truncate --size="> -1" file && fail=1
+returns_ 1 truncate --size="> -1" file || 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
index 933e76385a3835b28528becd584bcd5ccbd518cf..97be8cb7d6996bded8aa461d5d2da775b94374cc 100755 (executable)
@@ -21,15 +21,15 @@ print_ver_ truncate
 
 
 # mixture of relative modifiers not allowed
-truncate --size="+>0" file && fail=1
+returns_ 1 truncate --size="+>0" file || fail=1
 
 # mixture of relative modifiers not allowed
-truncate --size=">+0" file && fail=1
+returns_ 1 truncate --size=">+0" file || fail=1
 
 # division by zero
-truncate --size="/0" file && fail=1
+returns_ 1 truncate --size="/0" file || fail=1
 
 # division by zero
-truncate --size="%0" file && fail=1
+returns_ 1 truncate --size="%0" file || fail=1
 
 Exit $fail
index c522ea7d7417ddf3985af3eb3be01d999244c2bb..2d1e9f4053ff20c1e1365967bf9c14ed50fc5622 100755 (executable)
@@ -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
index 6ffa533a2daa759d0d8d3ccfc52c81fb65a856b2..199e7e1de3b9e42af4985af3273a215727f3d61a 100755 (executable)
@@ -27,7 +27,8 @@ mkdir no-acce2s || framework_failure_
 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
+(cd no-access && chmod 0 . && mkdir -p "$p/a/b" u/v) 2> /dev/null
+test $? -eq 1 || fail=1
 test -d "$p/a/b" || fail=1
 
 # Same as above, but with a following *absolute* name, it should succeed
index 2bc5419bab4268365262280e827391af9f7eeaad..ebdb527139d50d8afe9a70b5786c1bfca730e024 100755 (executable)
@@ -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
+returns_ 1 mkdir e-dir > /dev/null 2>&1 || fail=1
 
 # Create an existing directory.
 umask 077
index ab78f1f894a1800e4b4ae55fc02afbbd852c1a9a..ff0a57dceffe064c74154f36d627a4cc3e931cbd 100755 (executable)
@@ -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------
index 94b6f8c34b9d2f6ba783ac07e93fa03ffe329e05..a6ba642f8c862ea594f85c8404685c50b7972295 100755 (executable)
@@ -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
+returns_ 1 mkdir -m$set_mode_string $tmp2 2> /dev/null || fail=1
 
 # Now test the --parents option.
 mkdir --parents -m$set_mode_string $tmp2 || fail=1
index bb7e661c391d9b068cb61e2d24773426f198deb0..cc879ff1901a36cf460ef3eeb81ae7b0caa54372 100755 (executable)
@@ -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
+returns_ 1 cp a/f b/f c 2> /dev/null || 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
+returns_ 1 mv a/f b/f c 2> /dev/null || 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
+returns_ 1 mv a/f b/f b/g c 2> /dev/null || 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
+returns_ 1 ln -f a/f b/f c 2> /dev/null || 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
index 36b1a7dcfe99ead96e85dad2d129a8961d97dd11..7b798ed6f935e82bf9058f2dcff73a72401db991 100755 (executable)
@@ -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
+returns_ 1 mv dir file > /dev/null 2>&1 || fail=1
+returns_ 1 mv file dir > /dev/null 2>&1 || fail=1
 
 Exit $fail
index 4a0b2a54f550a33678bb88448cb1a9c4f8cf83c5..3e51c38a5cd0693190713ef68aa9b21ff343805e 100755 (executable)
@@ -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
+returns_ 1 mv foo Foo || fail=1
 test -r foo || fail=1
 
 Exit $fail
index fe0322ea524786c84b98f7c73383f0cfcdf28ad2..2ae0468fdc39303a57a89a70700b2f133087b42f 100755 (executable)
@@ -25,7 +25,7 @@ ln -s file s || framework_failure_
 
 
 # This must fail.
-mv s s 2> /dev/null && fail=1
+returns_ 1 mv s s 2> /dev/null || fail=1
 
 # But the symlink, s, must not be removed.
 # Before 4.0.36, 's' would have been removed.
index 97133339cb9bcfda3b00bf4c81ddd1a9620c5e36..8c3fedb811b6c2724aec947b76c0da03745c4c15 100755 (executable)
@@ -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
+returns_ 1 mv -bn a b 2>/dev/null || fail=1
 
 Exit $fail
index 9f8ece0a1366b2682a8e02304dc16aba65942091..d7bca59b119bb171dbc21678a734d5e9ba051b2f 100755 (executable)
@@ -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
+returns_ $LS_FAILURE ls -d d > /dev/null 2>&1 || 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
+returns_ 1 mv -fT src d2 2> /dev/null || fail=1
 
 # rename must fail, since the src is not a directory.
-mv -fT f e2 2> /dev/null && fail=1
+returns_ 1 mv -fT f e2 2> /dev/null || fail=1
 
 Exit $fail
index da88260a8795cb17b6b5974bdec5127a9912d06b..b84f6886476ea1ad96823ee337dccb87f05bf2b5 100755 (executable)
@@ -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
+returns_ 1 mv bar "$other_partition_tmpdir/" || 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
+returns_ 1 mv bar2 "$other_partition_tmpdir/" || 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
+returns_ 1 mv bar3 "$other_partition_tmpdir/" || fail=1
 test -e "$other_partition_tmpdir/bar3/file2" && fail=1
 
 Exit $fail
index da2d95d1a0654f30be6340461d79551c61b0b9d1..47335d3ca7f5e7cd1c01b8d1bfa6cbfaaa980088 100755 (executable)
@@ -48,14 +48,14 @@ done
 # underlying rename syscall handles the trailing slash.
 # It does fail, as desired, on recent Linux and Solaris systems.
 #touch a a2
-#mv a a2/ && fail=1
+#returns_ 1 mv a a2/ || fail=1
 
 # Test for a cp-specific diagnostic introduced after coreutils-8.7:
 printf '%s\n' \
   "cp: cannot create regular file 'no-such/': Not a directory" \
 > expected-err
 touch b
-cp b no-such/ 2> err && fail=1
+cp b no-such/ 2> err
 
 # Map "No such file..." diagnostic to the expected "Not a directory"
 sed 's/No such file or directory/Not a directory/' err > k && mv k err
index 91bea780758ba65818a1b1bb1a8c619871437114..05f297b7c21b849cc40d47468ae7afee2187a0cf 100755 (executable)
@@ -38,7 +38,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
+  v=$(returns_ 1 readlink -e .) || fail=1
   test -z "$v" || fail=1
 fi
 
@@ -49,7 +49,7 @@ for p in "" "$pwd/$tmp/"; do
   v=$(readlink -e "${p}regfile") || fail=1
   test "$v" = "$my_pwd/$tmp/regfile" || fail=1
 
-  v=$(readlink -e "${p}./regfile/") && fail=1
+  v=$(returns_ 1 readlink -e "${p}./regfile/") || fail=1
   test -z "$v" || fail=1
 
   v=$(readlink -e "${p}subdir") || fail=1
@@ -58,19 +58,19 @@ for p in "" "$pwd/$tmp/"; do
   v=$(readlink -e "${p}./subdir/") || fail=1
   test "$v" = "$my_pwd/$tmp/subdir" || fail=1
 
-  v=$(readlink -e "${p}missing") && fail=1
+  v=$(returns_ 1 readlink -e "${p}missing") || fail=1
   test -z "$v" || fail=1
 
-  v=$(readlink -e "${p}./missing/") && fail=1
+  v=$(returns_ 1 readlink -e "${p}./missing/") || 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
+  v=$(returns_ 1 readlink -e "${p}./link1/") || fail=1
   test -z "$v" || fail=1
 
-  v=$(readlink -e "${p}link1/more") && fail=1
+  v=$(returns_ 1 readlink -e "${p}link1/more") || fail=1
   test -z "$v" || fail=1
 
   v=$(readlink -e "${p}link2") || fail=1
@@ -79,25 +79,25 @@ for p in "" "$pwd/$tmp/"; do
   v=$(readlink -e "${p}./link2/") || fail=1
   test "$v" = "$my_pwd/$tmp/subdir" || fail=1
 
-  v=$(readlink -e "${p}link2/more") && fail=1
+  v=$(returns_ 1 readlink -e "${p}link2/more") || fail=1
   test -z "$v" || fail=1
 
-  v=$(readlink -e "${p}link3") && fail=1
+  v=$(returns_ 1 readlink -e "${p}link3") || fail=1
   test -z "$v" || fail=1
 
-  v=$(readlink -e "${p}./link3/") && fail=1
+  v=$(returns_ 1 readlink -e "${p}./link3/") || fail=1
   test -z "$v" || fail=1
 
-  v=$(readlink -e "${p}link3/more") && fail=1
+  v=$(returns_ 1 readlink -e "${p}link3/more") || fail=1
   test -z "$v" || fail=1
 
-  v=$(readlink -e "${p}link4") && fail=1
+  v=$(returns_ 1 readlink -e "${p}link4") || fail=1
   test -z "$v" || fail=1
 
-  v=$(readlink -e "${p}./link4/") && fail=1
+  v=$(returns_ 1 readlink -e "${p}./link4/") || fail=1
   test -z "$v" || fail=1
 
-  v=$(readlink -e "${p}link4/more") && fail=1
+  v=$(returns_ 1 readlink -e "${p}link4/more") || fail=1
   test -z "$v" || fail=1
 done
 
index 44697225ee6835dacc1a5d29c76c601d19968472..4b25fc63da0079d1d56978ef644dfddb2ddf148b 100755 (executable)
@@ -39,7 +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
+  v=$(returns_ 1 readlink -e .) || fail=1
   test -z "$v" || fail=1
 fi
 
@@ -50,13 +50,13 @@ for p in "" "$pwd/$tmp/"; do
   v=$(readlink -f "${p}regfile") || fail=1
   test "$v" = "$my_pwd/$tmp/regfile" || fail=1
 
-  v=$(readlink -f "${p}./regfile/") && fail=1
+  v=$(returns_ 1 readlink -f "${p}./regfile/") || fail=1
   test -z "$v" || fail=1
 
-  v=$(readlink -f "${p}regfile/more") && fail=1
+  v=$(returns_ 1 readlink -f "${p}regfile/more") || fail=1
   test -z "$v" || fail=1
 
-  v=$(readlink -f "${p}./regfile/more/") && fail=1
+  v=$(returns_ 1 readlink -f "${p}./regfile/more/") || fail=1
   test -z "$v" || fail=1
 
   v=$(readlink -f "${p}subdir") || fail=1
@@ -77,22 +77,22 @@ for p in "" "$pwd/$tmp/"; do
   v=$(readlink -f "${p}./missing/") || fail=1
   test "$v" = "$my_pwd/$tmp/missing" || fail=1
 
-  v=$(readlink -f "${p}missing/more") && fail=1
+  v=$(returns_ 1 readlink -f "${p}missing/more") || fail=1
   test -z "$v" || fail=1
 
-  v=$(readlink -f "${p}./missing/more/") && fail=1
+  v=$(returns_ 1 readlink -f "${p}./missing/more/") || fail=1
   test -z "$v" || fail=1
 
   v=$(readlink -f "${p}link1") || fail=1
   test "$v" = "$my_pwd/$tmp/regfile" || fail=1
 
-  v=$(readlink -f "${p}./link1/") && fail=1
+  v=$(returns_ 1 readlink -f "${p}./link1/") || fail=1
   test -z "$v" || fail=1
 
-  v=$(readlink -f "${p}link1/more") && fail=1
+  v=$(returns_ 1 readlink -f "${p}link1/more") || fail=1
   test -z "$v" || fail=1
 
-  v=$(readlink -f "${p}./link1/more/") && fail=1
+  v=$(returns_ 1 readlink -f "${p}./link1/more/") || fail=1
   test -z "$v" || fail=1
 
   v=$(readlink -f "${p}link2") || fail=1
@@ -107,10 +107,10 @@ for p in "" "$pwd/$tmp/"; do
   v=$(readlink -f "${p}./link2/more/") || fail=1
   test "$v" = "$my_pwd/$tmp/subdir/more" || fail=1
 
-  v=$(readlink -f "${p}link2/more/more2") && fail=1
+  v=$(returns_ 1 readlink -f "${p}link2/more/more2") || fail=1
   test -z "$v" || fail=1
 
-  v=$(readlink -f "${p}./link2/more/more2/") && fail=1
+  v=$(returns_ 1 readlink -f "${p}./link2/more/more2/") || fail=1
   test -z "$v" || fail=1
 
   v=$(readlink -f "${p}link3") || fail=1
@@ -119,10 +119,10 @@ for p in "" "$pwd/$tmp/"; do
   v=$(readlink -f "${p}./link3/") || fail=1
   test "$v" = "$my_pwd/$tmp/missing" || fail=1
 
-  v=$(readlink -f "${p}link3/more") && fail=1
+  v=$(returns_ 1 readlink -f "${p}link3/more") || fail=1
   test -z "$v" || fail=1
 
-  v=$(readlink -f "${p}./link3/more/") && fail=1
+  v=$(returns_ 1 readlink -f "${p}./link3/more/") || fail=1
   test -z "$v" || fail=1
 
   v=$(readlink -f "${p}link4") || fail=1
@@ -131,22 +131,22 @@ for p in "" "$pwd/$tmp/"; do
   v=$(readlink -f "${p}./link4/") || fail=1
   test "$v" = "$my_pwd/$tmp/subdir/missing" || fail=1
 
-  v=$(readlink -f "${p}link4/more") && fail=1
+  v=$(returns_ 1 readlink -f "${p}link4/more") || fail=1
   test -z "$v" || fail=1
 
-  v=$(readlink -f "${p}./link4/more") && fail=1
+  v=$(returns_ 1 readlink -f "${p}./link4/more") || fail=1
   test -z "$v" || fail=1
 
-  v=$(readlink -f "${p}link5") && fail=1
+  v=$(returns_ 1 readlink -f "${p}link5") || fail=1
   test -z "$v" || fail=1
 
-  v=$(readlink -f "${p}./link5/") && fail=1
+  v=$(returns_ 1 readlink -f "${p}./link5/") || fail=1
   test -z "$v" || fail=1
 
-  v=$(readlink -f "${p}link5/more") && fail=1
+  v=$(returns_ 1 readlink -f "${p}link5/more") || fail=1
   test -z "$v" || fail=1
 
-  v=$(readlink -f "${p}./link5/more") && fail=1
+  v=$(returns_ 1 readlink -f "${p}./link5/more") || fail=1
   test -z "$v" || fail=1
 done
 
index 6d8ca81978508c02e1283d8f89713988ebb6733c..2eb13565a78d5421f21fe89a5edf836913a13944 100755 (executable)
@@ -38,7 +38,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
+  v=$(returns_ 1 readlink -e .) || fail=1
   test -z "$v" || fail=1
 fi
 
index 17aab4059c1b4f8bb3849317f229f22425517e47..c7c2ef7118434a0b645de1531d1a0bb3d566a416 100755 (executable)
@@ -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
+returns_ 1 readlink link1 link2 || fail=1
+returns_ 1 readlink link1 link2 link1 || fail=1
 readlink -m link1 link2 || fail=1
 
 printf '/1\0/1\0' > exp || framework_failure_
index a6b92c747b68edf3f6659b8a115d736916b2c1f3..5b429edeccaa30063232a13f823e1693e397d741 100755 (executable)
@@ -31,13 +31,13 @@ test "$v" = regfile || fail=1
 v=$(readlink link2) || fail=1
 test "$v" = missing || fail=1
 
-v=$(readlink subdir) && fail=1
+v=$(returns_ 1 readlink subdir) || fail=1
 test -z "$v" || fail=1
 
-v=$(readlink regfile) && fail=1
+v=$(returns_ 1 readlink regfile) || fail=1
 test -z "$v" || fail=1
 
-v=$(readlink missing) && fail=1
+v=$(returns_ 1 readlink missing) || fail=1
 test -z "$v" || fail=1
 
 Exit $fail
index e7f7196aabb4ef3b854e569426b8ca3dd7874a0e..22819ab6f213070755126d13a332c6584bbe6f46 100755 (executable)
@@ -26,7 +26,7 @@ echo y > y || framework_failure_
 
 
 # This must fail.
-rm -i dir < y > /dev/null 2>&1 && fail=1
+returns_ 1 rm -i dir < y > /dev/null 2>&1 || fail=1
 
 # The directory must remain.
 test -d dir || fail=1
index b7b5b0eda0156554eff1e04713c6bad2765ac6c6..a5134d7607fa374f8256a1790c3a31aefae629b8 100755 (executable)
@@ -30,8 +30,8 @@ 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
+returns_ 1 chroot --skip-chdir --user=$NON_ROOT_USERNAME / env PATH="$PATH" \
+  rm -rf d 2>/dev/null || fail=1
 
 # d must remain.
 test -d d || fail=1
index de3da0cf7d495d7e20e928f4b5f9ae993a97e445..91a8b58aa55ff6ee098ca450103f64ad034e263b 100755 (executable)
@@ -43,8 +43,8 @@ rmtest 'd/..'    || fail=1
 rmtest 'd/../'   || fail=1
 
 
-# This test is too dangerous -- if there's a bug you're wiped out!
-# rm -fr / 2>/dev/null && fail=1
+# This test is handled more carefully in r-root.sh
+# returns_ 1 rm -fr / 2>/dev/null || fail=1
 
 test -f d/a || fail=1
 
index 179edf6ffafcdd4fecdb9a4072e80bebcf858500..e8fe714af238a2ee8b5f8cbf0f30f365938332c8 100755 (executable)
@@ -143,8 +143,7 @@ for opts in           \
   'rootlink2/'        \
   'rootlink3/'        ; do
 
-  exercise_rm_r_root $opts \
-    && fail=1
+  returns_ 1 exercise_rm_r_root $opts || fail=1
 
   # For some of the synonyms, the error diagnostic slightly differs from that
   # of the basic "/" case (see gnulib's fts_open' and ROOT_DEV_INO_WARN):
@@ -178,8 +177,7 @@ done
 # by setting the following variable.
 CU_TEST_SKIP_EXIT=1
 
-exercise_rm_r_root --preserve-root file1 '/' file2 \
-  && fail=1
+returns_ 1 exercise_rm_r_root --preserve-root file1 '/' file2 || fail=1
 
 unset CU_TEST_SKIP_EXIT
 
@@ -219,8 +217,7 @@ for file in      \
 
   test -d "$file" || continue   # if e.g. /etc does not exist.
 
-  exercise_rm_r_root --preserve-root "$file" \
-    && fail=1
+  returns_ 1 exercise_rm_r_root --preserve-root "$file" || fail=1
 
   grep "^rm: refusing to remove '\.' or '\.\.' directory: skipping" err \
     || fail=1
@@ -244,8 +241,7 @@ exercise_rm_r_root  --interactive=never --no-preserve-root '/' \
   || fail=1
 
 # The 'err' file should not contain the above error diagnostic.
-grep "^rm: it is dangerous to operate recursively on '/'" err \
-  && fail=1
+grep "^rm: it is dangerous to operate recursively on '/'" err && fail=1
 
 # Instead, rm(1) should have called the intercepted unlinkat() function,
 # i.e. the evidence file "x" should exist.
index 28ff20bdf2e7ddff54b7026a518ac38203c9baa8..e0f141fd4850d2e3ddcb4b1f5678c0acaf000296 100755 (executable)
@@ -24,7 +24,7 @@ mkdir dir || framework_failure_
 
 
 # This should fail.
-rm dir > /dev/null 2>&1 && fail=1
+returns_ 1 rm dir > /dev/null 2>&1 || fail=1
 
 test -d dir || fail=1
 
index d2468217b7dcab9522d35746c8ab21ddeb0a533a..db4221f0339b807f56ec06653947901c2b062a97 100755 (executable)
@@ -24,6 +24,6 @@
 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
 print_ver_ rm
 
-rm -r '' > /dev/null 2>&1 && fail=1
+returns_ 1 rm -r '' > /dev/null 2>&1 || fail=1
 
 Exit $fail
index 4026201e38cf8a17a7cad0e02385247458dec2f0..985cb23bb43ec3775091e1eff695579c7a2ce0f2 100755 (executable)
@@ -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
+returns_ 1 rmdir -p d d/e/f 2> /dev/null || fail=1
 
 Exit $fail
index 9195915fa876ca98cbf33c3f0d345589b3fc821f..79a3f9727a028833aab78150a27e74d50c931279 100755 (executable)
@@ -39,6 +39,6 @@ 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
+returns_ 1 split --lines=2 --additional-suffix=a/b in 2>/dev/null >out || fail=1
 
 Exit $fail
index 67259956ca7f458886f9d6dc41a58cc01561597c..e8f7bc3cfbb137f6e69a77105917b5bd0526af1e 100755 (executable)
@@ -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
+returns_ 1 split -b 0 in 2> /dev/null || fail=1
+returns_ 1 split -C 0 in 2> /dev/null || fail=1
+returns_ 1 split -l 0 in 2> /dev/null || fail=1
+returns_ 1 split -n 0 in 2> /dev/null || fail=1
+returns_ 1 split -n 1/0 in 2> /dev/null || fail=1
+returns_ 1 split -n 0/1 in 2> /dev/null || fail=1
+returns_ 1 split -n 2/1 in 2> /dev/null || fail=1
 
 # Make sure -C doesn't create empty files.
 rm -f x?? || fail=1
@@ -42,21 +42,21 @@ 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
+returns_ 1 split -0 in 2> /dev/null || 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
+returns_ 1 split --line-bytes=$OFF_T_OFLOW 2> /dev/null in || fail=1
+returns_ 1 split --line-bytes=$SIZE_OFLOW 2> /dev/null in || 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
+returns_ 1 split --number=r/$UINTMAX_OFLOW </dev/null 2>/dev/null || fail=1
 
 # Make sure that a huge obsolete option evokes the right failure.
-split -99999999999999999991 2> out && fail=1
+split -99999999999999999991 2> out
 
 # On losing systems (x86 Solaris 5.9 c89), we get a message like this:
 #   split: line count option -9999999999... is too large
@@ -75,7 +75,7 @@ compare exp out || fail=1
 # (the current directory in this case)
 if ! cat . >/dev/null; then
   # can't read() directories
-  split . && fail=1
+  returns_ 1 split . || fail=1
 fi
 
 Exit $fail
index 93a1bebbef9bc1bdec00793394da871fce322df7..55610e4176e01d98925b88894d66883ff788879b 100755 (executable)
@@ -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
+returns_ 1 split -n 1/2 --filter='true' /dev/null 2>&1 || fail=1
 
 # Ensure SIGPIPEs sent by the children don't propagate back
 # where they would result in a non zero exit from split.
index cc413606af017ff1ad5cae04cb73763a5203f914..1213ab04c0d8e6b3ef8ef2aba3c3793169d48550 100755 (executable)
@@ -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
+returns_ 1 split -C 6 xaa || fail=1
+returns_ 1 split -C 6 in2 || fail=1
+returns_ 1 split -C 6 in3 || fail=1
+returns_ 1 split -C 6 - < xaa || fail=1
 
 compare exp-1 xaa || fail=1
 
index e40430563ed6c76db1e7d62f7e2a10b37597018e..9c4e1c55d86d8df2e48257b3337686daa6a9c9df 100755 (executable)
@@ -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
+returns_ 1 split -a 3 --numeric-suffixes=1000 in 2>/dev/null || 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
+returns_ 1 split --numeric-suffixes=-1 in 2> /dev/null || fail=1
+returns_ 1 split --numeric-suffixes=one in 2> /dev/null || fail=1
 
 Exit $fail
index a50bd23b48d9bfe5ac54646e305ce2027ed05a50..6ee220066f6624438ad2c4dea691b3fa9abc0a42 100755 (executable)
@@ -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
+returns_ 1 split file.in -b1 --numeric=89 || fail=1
 test "$(ls -1 x* | wc -l)" = 11 || fail=1
 rm -f x*
 
index 48f83eb82ac9e4d214576a06c8025337e9f62621..0be3e9bc434560d65bd3290ab073fcdfac043c50 100755 (executable)
@@ -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
+returns_ 1 split -a2 -n1000 < /dev/null || fail=1
 test -f xaa && fail=1
 
 Exit $fail
index a4c85c2affa644ae55cb4c1b1040d1b6745d9428..776c255f2eb948d98c7b2498c34b41c76a685e60 100755 (executable)
@@ -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
+returns_ 1 touch -h no-file 2> err || 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
+  returns_ 1 touch -h - >&- || fail=1
   touch -h -c - >&- || fail=1
 fi
 
index a6463fa602c7e245ba4025bc69efd21b0f3da86d..2d57007ba71d48f9aee5bf1ad19be2f979a14843 100755 (executable)
@@ -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
+returns_ 1 touch no-file/ || fail=1
+returns_ 1 touch file/ || fail=1
+returns_ 1 touch dangling/ || fail=1
+returns_ 1 touch loop/ || fail=1
+returns_ 1 touch link1/ || 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
+returns_ 1 touch -c file/ || fail=1
 touch -c dangling/ || fail=1
-touch -c loop/ && fail=1
-touch -c link1/ && fail=1
+returns_ 1 touch -c loop/ || fail=1
+returns_ 1 touch -c link1/ || fail=1
 touch -c dir/ || fail=1
-test -f no-file && fail=1
-test -f nowhere && fail=1
+returns_ 1 test -f no-file || fail=1
+returns_ 1 test -f nowhere || fail=1
 
 # Trailing slash dereferences a symlink, even with -h.
 # mtime is sufficient to show pass (besides, lstat changes atime of