summaryrefslogtreecommitdiff
path: root/tests/dd
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2015-01-13 03:30:33 +0000
committerPádraig Brady <P@draigBrady.com>2015-01-14 12:20:32 +0000
commit58cff8a009ed9b8280c5f35074cef97231286023 (patch)
tree771e8b3fa70fab99b548790931803b75dd272603 /tests/dd
parent924b1cadff3f2782475516d7eca9aabe856dbf0f (diff)
downloadcoreutils-58cff8a009ed9b8280c5f35074cef97231286023.tar.xz
tests: add extra protection against unexpected exits
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.
Diffstat (limited to 'tests/dd')
-rwxr-xr-xtests/dd/misc.sh10
-rwxr-xr-xtests/dd/nocache.sh4
-rwxr-xr-xtests/dd/stderr.sh4
3 files changed, 9 insertions, 9 deletions
diff --git a/tests/dd/misc.sh b/tests/dd/misc.sh
index 59f0f50a7..2a536e8d7 100755
--- a/tests/dd/misc.sh
+++ b/tests/dd/misc.sh
@@ -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
diff --git a/tests/dd/nocache.sh b/tests/dd/nocache.sh
index 33421480a..e7fdf4e5e 100755
--- a/tests/dd/nocache.sh
+++ b/tests/dd/nocache.sh
@@ -23,10 +23,10 @@ print_ver_ dd
dd iflag=nocache oflag=nocache if=/dev/null of=/dev/null || fail=1
# We should get an error for trying to process a pipe
-dd count=0 | dd iflag=nocache count=0 && fail=1
+dd count=0 | 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
diff --git a/tests/dd/stderr.sh b/tests/dd/stderr.sh
index ce67a7a9e..82ab08f17 100755
--- a/tests/dd/stderr.sh
+++ b/tests/dd/stderr.sh
@@ -32,12 +32,12 @@ dd --help >/dev/null 2>&- || fail=1
# This exposes a failure present in 6.11 through 7.5.
if "$p/src/test" -w /dev/stderr 2>/dev/null &&
"$p/src/test" ! -w /dev/stderr 2>&-; then
- : | dd 2>&- && fail=1
+ : | 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