summaryrefslogtreecommitdiff
path: root/tests/split
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/split
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/split')
-rwxr-xr-xtests/split/additional-suffix.sh2
-rwxr-xr-xtests/split/fail.sh26
-rwxr-xr-xtests/split/filter.sh2
-rwxr-xr-xtests/split/guard-input.sh8
-rwxr-xr-xtests/split/numeric.sh6
-rwxr-xr-xtests/split/suffix-auto-length.sh2
-rwxr-xr-xtests/split/suffix-length.sh2
7 files changed, 24 insertions, 24 deletions
diff --git a/tests/split/additional-suffix.sh b/tests/split/additional-suffix.sh
index 9195915fa..79a3f9727 100755
--- a/tests/split/additional-suffix.sh
+++ b/tests/split/additional-suffix.sh
@@ -39,6 +39,6 @@ compare exp-2 xab.txt || fail=1
compare exp-3 xac.txt || fail=1
# Additional suffix must not contain slash
-split --lines=2 --additional-suffix=a/b in 2>/dev/null > out && fail=1
+returns_ 1 split --lines=2 --additional-suffix=a/b in 2>/dev/null >out || fail=1
Exit $fail
diff --git a/tests/split/fail.sh b/tests/split/fail.sh
index 67259956c..e8f7bc3cf 100755
--- a/tests/split/fail.sh
+++ b/tests/split/fail.sh
@@ -24,13 +24,13 @@ touch in || framework_failure_
split -a 0 in 2> /dev/null || fail=1
-split -b 0 in 2> /dev/null && fail=1
-split -C 0 in 2> /dev/null && fail=1
-split -l 0 in 2> /dev/null && fail=1
-split -n 0 in 2> /dev/null && fail=1
-split -n 1/0 in 2> /dev/null && fail=1
-split -n 0/1 in 2> /dev/null && fail=1
-split -n 2/1 in 2> /dev/null && fail=1
+returns_ 1 split -b 0 in 2> /dev/null || fail=1
+returns_ 1 split -C 0 in 2> /dev/null || fail=1
+returns_ 1 split -l 0 in 2> /dev/null || fail=1
+returns_ 1 split -n 0 in 2> /dev/null || fail=1
+returns_ 1 split -n 1/0 in 2> /dev/null || fail=1
+returns_ 1 split -n 0/1 in 2> /dev/null || fail=1
+returns_ 1 split -n 2/1 in 2> /dev/null || fail=1
# Make sure -C doesn't create empty files.
rm -f x?? || fail=1
@@ -42,21 +42,21 @@ test -f xac && fail=1
split -1 in 2> /dev/null || fail=1
# Then make sure that -0 evokes a failure.
-split -0 in 2> /dev/null && fail=1
+returns_ 1 split -0 in 2> /dev/null || fail=1
split --lines=$UINTMAX_MAX in || fail=1
split --bytes=$OFF_T_MAX in || fail=1
-split --line-bytes=$OFF_T_OFLOW 2> /dev/null in && fail=1
-split --line-bytes=$SIZE_OFLOW 2> /dev/null in && fail=1
+returns_ 1 split --line-bytes=$OFF_T_OFLOW 2> /dev/null in || fail=1
+returns_ 1 split --line-bytes=$SIZE_OFLOW 2> /dev/null in || fail=1
if truncate -s$SIZE_OFLOW large; then
# Ensure we can split chunks of a large file on 32 bit hosts
split --number=$SIZE_OFLOW/$SIZE_OFLOW large >/dev/null || fail=1
fi
split --number=r/$UINTMAX_MAX/$UINTMAX_MAX </dev/null >/dev/null || fail=1
-split --number=r/$UINTMAX_OFLOW </dev/null 2>/dev/null && fail=1
+returns_ 1 split --number=r/$UINTMAX_OFLOW </dev/null 2>/dev/null || fail=1
# Make sure that a huge obsolete option evokes the right failure.
-split -99999999999999999991 2> out && fail=1
+split -99999999999999999991 2> out
# On losing systems (x86 Solaris 5.9 c89), we get a message like this:
# split: line count option -9999999999... is too large
@@ -75,7 +75,7 @@ compare exp out || fail=1
# (the current directory in this case)
if ! cat . >/dev/null; then
# can't read() directories
- split . && fail=1
+ returns_ 1 split . || fail=1
fi
Exit $fail
diff --git a/tests/split/filter.sh b/tests/split/filter.sh
index 93a1bebbe..55610e417 100755
--- a/tests/split/filter.sh
+++ b/tests/split/filter.sh
@@ -44,7 +44,7 @@ split -e -n 10 --filter='xz > $FILE.xz' /dev/null || fail=1
stat x?? 2>/dev/null && fail=1
# Ensure this invalid combination is flagged
-split -n 1/2 --filter='true' /dev/null 2>/dev/null && fail=1
+returns_ 1 split -n 1/2 --filter='true' /dev/null 2>&1 || fail=1
# Ensure SIGPIPEs sent by the children don't propagate back
# where they would result in a non zero exit from split.
diff --git a/tests/split/guard-input.sh b/tests/split/guard-input.sh
index cc413606a..1213ab04c 100755
--- a/tests/split/guard-input.sh
+++ b/tests/split/guard-input.sh
@@ -23,10 +23,10 @@ seq 10 | tee exp-1 > xaa
ln -s xaa in2
ln xaa in3
-split -C 6 xaa && fail=1
-split -C 6 in2 && fail=1
-split -C 6 in3 && fail=1
-split -C 6 - < xaa && fail=1
+returns_ 1 split -C 6 xaa || fail=1
+returns_ 1 split -C 6 in2 || fail=1
+returns_ 1 split -C 6 in3 || fail=1
+returns_ 1 split -C 6 - < xaa || fail=1
compare exp-1 xaa || fail=1
diff --git a/tests/split/numeric.sh b/tests/split/numeric.sh
index e40430563..9c4e1c55d 100755
--- a/tests/split/numeric.sh
+++ b/tests/split/numeric.sh
@@ -56,10 +56,10 @@ compare exp-3 x03 || fail=1
# Check that split failed when suffix length is not large enough for
# the numerical suffix start value
-split -a 3 --numeric-suffixes=1000 in 2> /dev/null && fail=1
+returns_ 1 split -a 3 --numeric-suffixes=1000 in 2>/dev/null || fail=1
# check invalid --numeric-suffixes start values are flagged
-split --numeric-suffixes=-1 in 2> /dev/null && fail=1
-split --numeric-suffixes=one in 2> /dev/null && fail=1
+returns_ 1 split --numeric-suffixes=-1 in 2> /dev/null || fail=1
+returns_ 1 split --numeric-suffixes=one in 2> /dev/null || fail=1
Exit $fail
diff --git a/tests/split/suffix-auto-length.sh b/tests/split/suffix-auto-length.sh
index a50bd23b4..6ee220066 100755
--- a/tests/split/suffix-auto-length.sh
+++ b/tests/split/suffix-auto-length.sh
@@ -22,7 +22,7 @@ print_ver_ split
# ensure this feature is off when start number specified
truncate -s12 file.in
-split file.in -b1 --numeric=89 && fail=1
+returns_ 1 split file.in -b1 --numeric=89 || fail=1
test "$(ls -1 x* | wc -l)" = 11 || fail=1
rm -f x*
diff --git a/tests/split/suffix-length.sh b/tests/split/suffix-length.sh
index 48f83eb82..0be3e9bc4 100755
--- a/tests/split/suffix-length.sh
+++ b/tests/split/suffix-length.sh
@@ -70,7 +70,7 @@ split -a2 -C1000 < /dev/null || fail=1
# Ensure that -a fails early with a -n that is too large
rm -f x*
-split -a2 -n1000 < /dev/null && fail=1
+returns_ 1 split -a2 -n1000 < /dev/null || fail=1
test -f xaa && fail=1
Exit $fail