]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tests: improve diagnostics when asserting empty files
authorPádraig Brady <P@draigBrady.com>
Tue, 6 May 2014 01:37:43 +0000 (02:37 +0100)
committerPádraig Brady <P@draigBrady.com>
Tue, 6 May 2014 23:06:00 +0000 (00:06 +0100)
* tests/chmod/c-option.sh: Use `compare /dev/null ... || fail=1`
rather than `test -s ... && fail=1`, so that the file contents
are output, thus improving diagnostics for failing tests.
* tests/cp/acl.sh: Likewise.
* tests/cp/cp-a-selinux.sh: Likewise.
* tests/cp/cp-mv-enotsup-xattr.sh: Likewise.
* tests/cp/reflink-perm.sh: Likewise.
* tests/dd/misc.sh: Likewise.
* tests/misc/env-null.sh: Likewise.
* tests/misc/env.sh: Likewise.
* tests/misc/nice.sh: Likewise.
* tests/misc/nohup.sh: Likewise.
* tests/misc/printenv.sh: Likewise.
* tests/misc/xattr.sh: Likewise.
* tests/mv/update.sh: Likewise.
* tests/rm/deep-2.sh: Likewise.
* tests/rm/read-only.sh: Likewise.
* tests/split/r-chunk.sh: Likewise.
* tests/tail-2/follow-stdin.sh: Likewise.
* tests/tail-2/inotify-race.sh: Likewise.
* tests/tail-2/wait.sh: Likewise.
* tests/touch/no-dereference.sh: Likewise.

* cfg.mk (sc_prohibit_test_empty:): New syntax-check.
* tests/cp/proc-zero-len.sh: Adjust to avoid false syntax-check failure.
* tests/cp/proc-zero-len.sh: Likewise.
* tests/mv/part-symlink.sh: Likewise.
* tests/tail-2/infloop-1.sh: Likewise.

24 files changed:
cfg.mk
tests/chmod/c-option.sh
tests/cp/acl.sh
tests/cp/cp-a-selinux.sh
tests/cp/cp-mv-enotsup-xattr.sh
tests/cp/proc-zero-len.sh
tests/cp/reflink-perm.sh
tests/dd/misc.sh
tests/misc/env-null.sh
tests/misc/env.sh
tests/misc/nice.sh
tests/misc/nohup.sh
tests/misc/printenv.sh
tests/misc/xattr.sh
tests/mv/part-symlink.sh
tests/mv/update.sh
tests/rm/deep-2.sh
tests/rm/read-only.sh
tests/split/r-chunk.sh
tests/tail-2/follow-stdin.sh
tests/tail-2/infloop-1.sh
tests/tail-2/inotify-race.sh
tests/tail-2/wait.sh
tests/touch/no-dereference.sh

diff --git a/cfg.mk b/cfg.mk
index b3c0f708b1f7c68be866ce934f9f91d9e0a0c289..f84b1a443ee2ac81c70809e71de83a1637374472 100644 (file)
--- a/cfg.mk
+++ b/cfg.mk
@@ -423,6 +423,13 @@ sc_prohibit_test_backticks:
        halt='use $$(...), not `...` in tests/'                         \
          $(_sc_search_regexp)
 
+# Ensure that compare is used to check empty files
+# so that the unexpected contents are displayed
+sc_prohibit_test_empty:
+       @prohibit='test -s.*&&' in_vc_files='^tests/'                   \
+       halt='use `compare /dev/null ...`, not `test -s ...` in tests/' \
+         $(_sc_search_regexp)
+
 # Programs like sort, ls, expr use PROG_FAILURE in place of EXIT_FAILURE.
 # Others, use the EXIT_CANCELED, EXIT_ENOENT, etc. macros defined in system.h.
 # In those programs, ensure that EXIT_FAILURE is not used by mistake.
index a1782c3d8a54e66d4d9e703eaf3f26281fdf37de..03e1db9a670b19aa6efe14192013d2164335cb4a 100755 (executable)
@@ -31,7 +31,7 @@ chmod u=rwx $file || fail=1
 chmod -c g=rwx $file > out || fail=1
 chmod -c g=rwx $file > empty || fail=1
 
-test -s empty && fail=1
+compare /dev/null empty || fail=1
 case "$(cat out)" in
   "mode of 'f' changed from 0744 "?rwxr--r--?" to 0774 "?rwxrwxr--?) ;;
   *) cat out; fail=1 ;;
index 0dc9f882d37adcfb1e0110b2aafac08b79bd035d..36a5d298c19bf282137124a2d9148d0d2c00e61f 100755 (executable)
@@ -53,7 +53,7 @@ test "$acl1" = "$acl2" || fail=1
 echo > a/file || framework_failure_ # add some data
 test -s a/file || framework_failure_
 cp -p --attributes-only a/file b/ || fail=1
-test -s b/file && fail=1
+compare /dev/null b/file || fail=1
 acl2=$(cd b && getfacl file) || framework_failure_
 test "$acl1" = "$acl2" || fail=1
 
index 3ab7e0e287589920163af95cf6689316971fd8bb..db0d6893029bc4dcf7dd71ffc5a9f0c3b8b4f0c5 100755 (executable)
@@ -37,7 +37,8 @@ cp -a c d 2>err || framework_failure_
 cp --preserve=context c e || framework_failure_
 cp --preserve=all c f || framework_failure_
 ls -Z d | grep $ctx || fail=1
-test -s err && fail=1   #there must be no stderr output for -a
+# there must be no stderr output for -a
+compare /dev/null err || fail=1
 ls -Z e | grep $ctx || fail=1
 ls -Z f | grep $ctx || fail=1
 
@@ -116,7 +117,7 @@ echo > g                                     || framework_failure_
 # succeed (giving no diagnostics), yet leaving the destination file empty.
 cp -a f g 2>err || fail=1
 test -s g       || fail=1     # The destination file must not be empty.
-test -s err     && fail=1     # There must be no stderr output.
+compare /dev/null err || fail=1
 
 # =====================================================
 # Here, we expect cp to succeed and not warn with "Operation not supported"
@@ -151,7 +152,7 @@ echo > g
 # security context through NFS or a mount with fixed context.
 cp --preserve=context f g 2> out && fail=1
 # Here, we *do* expect the destination to be empty.
-test -s g && fail=1
+compare /dev/null g || fail=1
 sed "s/ .g'.*//" out > k
 mv k out
 compare exp out || fail=1
@@ -161,7 +162,7 @@ echo > g
 # Check if -a option doesn't silence --preserve=context option diagnostics
 cp -a --preserve=context f g 2> out2 && fail=1
 # Here, we *do* expect the destination to be empty.
-test -s g && fail=1
+compare /dev/null g || fail=1
 sed "s/ .g'.*//" out2 > k
 mv k out2
 compare exp out2 || fail=1
index 11809892a0b6bb0c09fa0b68831d0676de024e7a..f46977b60ed17798e118dccc6e246bb854b06554 100755 (executable)
@@ -69,19 +69,19 @@ grep -F "$xattr_pair" out_a >/dev/null \
 # This should pass without diagnostics
 cp -a xattr/a noxattr/ 2>err || fail=1
 test -s noxattr/a   || fail=1  # destination file must not be empty
-test -s err         && fail=1  # there must be no stderr output
+compare /dev/null err || fail=1
 
 rm -f err noxattr/a
 
 # This should pass without diagnostics (new file)
 cp --preserve=all xattr/a noxattr/ 2>err || fail=1
 test -s noxattr/a   || fail=1  # destination file must not be empty
-test -s err         && fail=1  # there must be no stderr output
+compare /dev/null err || fail=1
 
 # This should pass without diagnostics (existing file)
 cp --preserve=all xattr/a noxattr/ 2>err || fail=1
 test -s noxattr/a   || fail=1  # destination file must not be empty
-test -s err         && fail=1  # there must be no stderr output
+compare /dev/null err || fail=1
 
 rm -f err noxattr/a
 
@@ -104,7 +104,7 @@ rm -f err noxattr/a
 # This should pass without diagnostics
 mv xattr/a noxattr/ 2>err || fail=1
 test -s noxattr/a         || fail=1  # destination file must not be empty
-test -s err               && fail=1  # there must be no stderr output
+compare /dev/null err || fail=1
 
 # This should pass and copy xattrs of the symlink
 # since the xattrs used here are not in the 'user.' namespace.
index 3369cfb3cd8bc8f5c8f5a804ceed674ccb1edd68..3fcd5aab13504365cfdc8b55deaed9da00f8b87e 100755 (executable)
@@ -37,8 +37,10 @@ cp $f exp 2>err \
 # Don't simply compare contents; they might differ,
 # e.g., if CPU freq changes between cat and cp invocations.
 # Instead, simply compare whether they're both nonempty.
-test -s out && { rm -f out; echo nonempty > out; }
-test -s exp && { rm -f exp; echo nonempty > exp; }
+test -s out \
+  && { rm -f out; echo nonempty > out; }
+test -s exp \
+  && { rm -f exp; echo nonempty > exp; }
 
 compare exp out || fail=1
 
index 52f83fce132e8af05e5611cbaecdef273c536dc0..52f5e257615f405d1d9618e0cfe894fa5e052bab 100755 (executable)
@@ -38,8 +38,8 @@ test copy -nt file && fail=1
 # Ensure that --attributes-only overrides --reflink completely
 echo > file2 # file with data
 cp --reflink=auto --preserve --attributes-only file2 empty_copy || fail=1
-test -s empty_copy && fail=1
+compare /dev/null empty_copy || fail=1
 cp --reflink=always --preserve --attributes-only file2 empty_copy || fail=1
-test -s empty_copy && fail=1
+compare /dev/null empty_copy || fail=1
 
 Exit $fail
index bb4748cce3e7cdd576998e40608d51e8a8a73767..f877fddfa59f17f711172a64b9e0e77fbab6f9ff 100755 (executable)
@@ -32,12 +32,12 @@ ln -s $tmp_in $tmp_sym || framework_failure_
 
 # check status=none suppresses all output to stderr
 dd status=none if=$tmp_in of=/dev/null 2> err || fail=1
-test -s err && { cat err; fail=1; }
+compare /dev/null err || fail=1
 dd status=none if=$tmp_in skip=2 of=/dev/null 2> err || fail=1
-test -s err && { cat err; fail=1; }
+compare /dev/null err || fail=1
 # check status=none is cumulative with status=noxfer
 dd status=none status=noxfer if=$tmp_in of=/dev/null 2> err || fail=1
-test -s err && { cat err; fail=1; }
+compare /dev/null err || fail=1
 
 dd if=$tmp_in of=$tmp_out 2> /dev/null || fail=1
 compare $tmp_in $tmp_out || fail=1
index 6544fb37bb419369b0c8d6e27c0da90d434b024c..9b9c95e73b689f73efc17ee348578b6940ef32b0 100755 (executable)
@@ -40,7 +40,7 @@ compare out1 out2 || fail=1
 # env -0 does not work if a command is specified.
 env -0 echo hi > out
 test $? = 125 || fail=1
-test -s out && fail=1
+compare /dev/null out || fail=1
 
 # Test env -0 on a one-variable environment.
 printf 'a=b\nc=\0' > exp || framework_failure_
@@ -53,7 +53,7 @@ env "$(printf 'a=b\nc=')" printenv -0 a > out || fail=1
 compare exp out || fail=1
 env -u a printenv -0 a > out
 test $? = 1 || fail=1
-test -s out && fail=1
+compare /dev/null out || fail=1
 env -u b "$(printf 'a=b\nc=')" printenv -0 b a > out
 test $? = 1 || fail=1
 compare exp out || fail=1
index 877a5e35e71e61812077d786a945b06cafe08415..c4b97377a36f0e2aff0940c01dcdb0a6e823d70d 100755 (executable)
@@ -25,11 +25,11 @@ print_ver_ env
 a=1
 export a
 env - > out || fail=1
-test -s out && fail=1
+compare /dev/null out || fail=1
 env -i > out || fail=1
-test -s out && fail=1
+compare /dev/null out || fail=1
 env -u a -i -u a -- > out || fail=1
-test -s out && fail=1
+compare /dev/null out || fail=1
 env -i -- a=b > out || fail=1
 echo a=b > exp || framework_failure_
 compare exp out || fail=1
index 8efb7d87d9e94e3223bb466f7c9d4ed28ae5f3ed..26a01ca9f3d7ec1f95ab7b955b496f54e61cae26 100755 (executable)
@@ -81,12 +81,12 @@ if test x$(nice -n -1 nice 2> /dev/null) = x0 ; then
   if test -w /dev/full && test -c /dev/full; then
     nice -n -1 nice > out 2> /dev/full
     test $? = 125 || fail=1
-    test -s out && fail=1
+    compare /dev/null out || fail=1
   fi
 else
   # superuser - change succeeds
   nice -n -1 nice 2> err || fail=1
-  test -s err && fail=1
+  compare /dev/null err || fail=1
   test x$(nice -n -1 nice) = x-1 || fail=1
   test x$(nice --1 nice) = x-1 || fail=1
 fi
index 2328b43e2e242a8233958122a420301fe5b9af00..b3f4274ce3bcd5ac379f434b16c339a6c4aec988 100755 (executable)
@@ -73,7 +73,7 @@ if test -w /dev/full && test -c /dev/full; then
   nohup echo hi 2> /dev/full
   test $? = 125 || fail=1
   test -f nohup.out || fail=1
-  test -s nohup.out && fail=1
+  compare /dev/null nohup.out || fail=1
   rm -f nohup.out
   exit $fail
 ) || fail=1
@@ -86,7 +86,7 @@ if test -t 1; then
   # It must exist.
   test -f nohup.out || fail=1
   # It must be empty.
-  test -s nohup.out && fail=1
+  compare /dev/null nohup.out || fail=1
 fi
 
 cat <<\EOF > exp || fail=1
@@ -106,7 +106,7 @@ if test -t 1; then
   # It must exist.
   test -f nohup.out || fail=1
   # It must be empty.
-  test -s nohup.out && fail=1
+  compare /dev/null nohup.out || fail=1
 fi
 
 cat <<\EOF > exp || fail=1
index fb911d0041a4ac73a7c323110057dd370f96f7ab..054b02c25f1e441308cca8a606e758b696c7ef28 100755 (executable)
@@ -37,7 +37,7 @@ fi
 # Printing a single variable's value.
 env -- printenv ENV_TEST > out
 test $? = 1 || fail=1
-test -s out && fail=1
+compare /dev/null out || fail=1
 echo a > exp || framework_failure_
 ENV_TEST=a env -- printenv ENV_TEST > out || fail=1
 compare exp out || fail=1
@@ -76,6 +76,6 @@ compare exp out || fail=1
 # Bug present through coreutils 8.0.
 env a=b=c printenv a=b > out
 test $? = 1 || fail=1
-test -s out && fail=1
+compare /dev/null out || fail=1
 
 Exit $fail
index 269424611f3ed318a1074604c0612f696723aa84..f208090f5a169905ec507bf59603508a46a1802b 100755 (executable)
@@ -66,7 +66,7 @@ getfattr -d c >out_c || skip_ "failed to get xattr of file"
 grep -F "$xattr_pair" out_c || fail=1
 
 # cp's -a option must produce no diagnostics.
-cp -a a d 2>err && test -s err && fail=1
+cp -a a d 2>err && { compare /dev/null err || fail=1; }
 getfattr -d d >out_d || skip_ "failed to get xattr of file"
 grep -F "$xattr_pair" out_d || fail=1
 
index 9d1d6a4a7dca29faba55102b6014ae7037e19d45..9604d873e5089972b8b57dd27671c10aef10bf46 100755 (executable)
@@ -88,7 +88,8 @@ for copy in cp mv; do
           # Normalize the program name in the error output,
           # remove any site-dependent part of other-partition file name,
           # and put brackets around the output.
-          test -s .err && {
+          test -s .err \
+            && {
             echo ' [' | tr -d '\n'
             sed 's/^[^:][^:]*\(..\):/\1:/;s,'"$other_partition_tmpdir/,," .err |
               tr -d '\n'
index 688a8f2d6fbb3b24fd7d57509d598430f990ac81..4c0553a5c1aad1a2a4af57c363591e7e27c38726 100755 (executable)
@@ -30,7 +30,7 @@ for interactive in '' -i; do
     # With coreutils-6.9 and earlier, using --update with -i would
     # mistakenly elicit a prompt.
     $cp_or_mv $interactive --update old new < /dev/null > out 2>&1 || fail=1
-    test -s out && fail=1
+    compare /dev/null out || fail=1
     case "$(cat new)" in new) ;; *) fail=1 ;; esac
     case "$(cat old)" in old) ;; *) fail=1 ;; esac
   done
index 24415ed41c9851b1c4411afd5b451ea20de98a83..c3ea085671b72c3dd3ff0feef892a33b829baa75 100755 (executable)
@@ -46,7 +46,7 @@ echo n > no || framework_failure_
 rm ---presume-input-tty -r x < no > out || fail=1
 
 # expect empty output
-test -s out && fail=1
+compare /dev/null out || fail=1
 
 # the directory must have been removed
 test -d x && fail=1
index 1ac8f27a8585fb3558c76ad8b6591e55b8083be3..377305cd05a7ea9bdf5196d5d86b2a9fe980b0e2 100755 (executable)
@@ -42,7 +42,7 @@ test $skip = 1 \
 # Applying rm -f to a nonexistent file on a read-only file system must succeed.
 rm -f mnt/no-such > out 2>&1 || fail=1
 # It must produce no diagnostic.
-test -s out && fail=1
+compare /dev/null out || fail=1
 
 # However, trying to remove an existing file must fail.
 rm -f mnt/f > out 2>&1 && fail=1
index e84dfa5bd4830d7e750358e03537c05b32c0abe0..8a5f221e5aa0121ecb5538a4e33fc44510d87d82 100755 (executable)
@@ -32,7 +32,7 @@ stat x?? 2>/dev/null && fail=1
 printf '1\n2\n3\n4\n5\n' > in || framework_failure_
 
 split -n r/3 in > out || fail=1
-test -s out && fail=1
+compare /dev/null out || fail=1
 
 split -n r/1/3 in > r1 || fail=1
 split -n r/2/3 in > r2 || fail=1
index 8ca10d68018831ac7c05bfae9e6c126296622126..1769ee2c95eb1c1c122d0291f2f5614d6fe3d34c 100755 (executable)
@@ -28,7 +28,7 @@ timeout 1 tail -f < in > out 2> err
 test $? = 124 || fail=1
 
 # Ensure there was no error output.
-test -s err && fail=1
+compare /dev/null err || fail=1
 
 # Ensure there was
 compare exp out || fail=1
index f553e9a4cb575806b8906ac6ff8ba13ad6ef5efd..37d081f3fc557e038f410686ffdd0e3ab120294b 100755 (executable)
@@ -22,7 +22,8 @@ print_ver_ tail
 yes > t &
 yes_pid=$!
 while :; do
-  test -s t && break
+  test -s t \
+    && break
   sleep .1
 done
 tail -n 1 t &
index efef7d6957f32fc50457cd1921ea2ef9e23b90a9..c25f354a94e29f9000139e121fdf7ecf9263e047 100755 (executable)
@@ -52,7 +52,7 @@ timeout 10s gdb -nx --batch-silent                 \
 # FIXME: The above is seen to _intermittently_ fail with:
 # warning: .dynamic section for "/lib/libc.so.6" is not at the expected address
 # warning: difference appears to be caused by prelink, adjusting expectations
-test -s gdb.out && { cat gdb.out; skip_ "can't set breakpoints in tail"; }
+compare /dev/null gdb.out || skip_ "can't set breakpoints in tail"
 
 # Run "tail -f file", stopping to append a line just before
 # inotify initialization, and then continue.  Before the fix,
index 13898acf11eca62f498a656df42a5e80002902ad..3dec55c0c6b0b9ed4bf19f870c9c6c52b33c83ba 100755 (executable)
@@ -51,7 +51,7 @@ for inotify in ---disable-inotify ''; do
 
   grep -Ev 'inotify (resources exhausted|cannot be used)' tail.err > x
   mv x tail.err
-  test -s tail.err && fail=1
+  compare /dev/null tail.err || fail=1
   >tail.err
 
   tail_F()
index 718fea7441b8badd3fa61ed12a42efb7a302d0d4..1d012a1fe7c651152ac454a2145750d6e0b9d0a1 100755 (executable)
@@ -29,7 +29,7 @@ ln -s file link || framework_failure_
 touch -h no-file 2> err && fail=1
 test -s err || fail=1
 touch -h -c no-file 2> err || fail=1
-test -s err && fail=1
+compare /dev/null err || fail=1
 
 # -h works on regular files
 touch -h file || fail=1
@@ -49,7 +49,7 @@ grep '^#define HAVE_LUTIMES 1' "$CONFIG_HEADER" > /dev/null ||
 touch -h dangling 2> err
 case $? in
   0) test -f nowhere && fail=1
-     test -s err && fail=1;;
+     compare /dev/null err || fail=1;;
   1) grep 'Function not implemented' err \
        && skip_ 'this system lacks the utimensat function'
      fail=1;;