From 8840a00cd79b8beae72b1a0ec6b9e64912633c13 Mon Sep 17 00:00:00 2001 From: Pádraig Brady
Date: Tue, 6 May 2014 02:37:43 +0100 Subject: tests: improve diagnostics when asserting empty files * 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. --- tests/cp/acl.sh | 2 +- tests/cp/cp-a-selinux.sh | 9 +++++---- tests/cp/cp-mv-enotsup-xattr.sh | 8 ++++---- tests/cp/proc-zero-len.sh | 6 ++++-- tests/cp/reflink-perm.sh | 4 ++-- 5 files changed, 16 insertions(+), 13 deletions(-) (limited to 'tests/cp') diff --git a/tests/cp/acl.sh b/tests/cp/acl.sh index 0dc9f882d..36a5d298c 100755 --- a/tests/cp/acl.sh +++ b/tests/cp/acl.sh @@ -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 diff --git a/tests/cp/cp-a-selinux.sh b/tests/cp/cp-a-selinux.sh index 3ab7e0e28..db0d68930 100755 --- a/tests/cp/cp-a-selinux.sh +++ b/tests/cp/cp-a-selinux.sh @@ -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 diff --git a/tests/cp/cp-mv-enotsup-xattr.sh b/tests/cp/cp-mv-enotsup-xattr.sh index 11809892a..f46977b60 100755 --- a/tests/cp/cp-mv-enotsup-xattr.sh +++ b/tests/cp/cp-mv-enotsup-xattr.sh @@ -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. diff --git a/tests/cp/proc-zero-len.sh b/tests/cp/proc-zero-len.sh index 3369cfb3c..3fcd5aab1 100755 --- a/tests/cp/proc-zero-len.sh +++ b/tests/cp/proc-zero-len.sh @@ -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 diff --git a/tests/cp/reflink-perm.sh b/tests/cp/reflink-perm.sh index 52f83fce1..52f5e2576 100755 --- a/tests/cp/reflink-perm.sh +++ b/tests/cp/reflink-perm.sh @@ -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 -- cgit v1.2.3-70-g09d2