From 58cff8a009ed9b8280c5f35074cef97231286023 Mon Sep 17 00:00:00 2001 From: Pádraig Brady Date: Tue, 13 Jan 2015 03:30:33 +0000 Subject: 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. --- tests/touch/no-dereference.sh | 4 ++-- tests/touch/trailing-slash.sh | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) (limited to 'tests/touch') 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 -- cgit v1.2.3-54-g00ecf