diff options
author | Pádraig Brady <P@draigBrady.com> | 2015-01-13 03:30:33 +0000 |
---|---|---|
committer | Pádraig Brady <P@draigBrady.com> | 2015-01-14 12:20:32 +0000 |
commit | 58cff8a009ed9b8280c5f35074cef97231286023 (patch) | |
tree | 771e8b3fa70fab99b548790931803b75dd272603 /tests/touch | |
parent | 924b1cadff3f2782475516d7eca9aabe856dbf0f (diff) | |
download | coreutils-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/touch')
-rwxr-xr-x | tests/touch/no-dereference.sh | 4 | ||||
-rwxr-xr-x | tests/touch/trailing-slash.sh | 20 |
2 files changed, 12 insertions, 12 deletions
diff --git a/tests/touch/no-dereference.sh b/tests/touch/no-dereference.sh index a4c85c2af..776c255f2 100755 --- a/tests/touch/no-dereference.sh +++ b/tests/touch/no-dereference.sh @@ -26,7 +26,7 @@ ln -s file link || framework_failure_ # These first tests should work on every platform. # -h does not create files, but it warns. Use -c to silence warning. -touch -h no-file 2> err && fail=1 +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 diff --git a/tests/touch/trailing-slash.sh b/tests/touch/trailing-slash.sh index a6463fa60..2d57007ba 100755 --- a/tests/touch/trailing-slash.sh +++ b/tests/touch/trailing-slash.sh @@ -29,22 +29,22 @@ ln -s dir link2 || framework_failure_ # Trailing slash can only appear on directory or symlink-to-directory. # Up through coreutils 8.0, Solaris 9 failed these tests. -touch no-file/ && fail=1 -touch file/ && fail=1 -touch dangling/ && fail=1 -touch loop/ && fail=1 -touch link1/ && fail=1 +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 |