]> Savannah Git Hosting - gnulib.git/commitdiff
tests: provide returns_() to simplify exit status checking
authorPádraig Brady <P@draigBrady.com>
Wed, 11 Feb 2015 00:16:55 +0000 (00:16 +0000)
committerPádraig Brady <P@draigBrady.com>
Wed, 11 Feb 2015 00:20:34 +0000 (00:20 +0000)
* tests/init.sh (returns_): A new function for use in tests,
to allow for easier checking of return values, where you expect
a command to exit with failure status.  By checking for a particular
exit code, you don't hide any crashes for example.

ChangeLog
tests/init.sh

index b769bbb79e2cb208755297235f7257f362e6509c..20139087fc1d3d9d562105e87ea4bc8f391426b6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2015-02-11  Pádraig Brady  <P@draigBrady.com>
+
+       tests: provide returns_() to simplify exit status checking
+       * tests/init.sh (returns_): A new function for use in tests,
+       to allow for easier checking of return values, where you expect
+       a command to exit with failure status.  By checking for a particular
+       exit code, you don't hide any crashes for example.
+
 2015-02-11  Pádraig Brady  <P@draigBrady.com>
 
        mountlist: only use libmount when specified
index 37fc7b62ee8e39f906798c4b71bf988fde8554ea..ac1e1a21154b538dfbe1d92000cf94ca70279215 100644 (file)
@@ -93,6 +93,19 @@ skip_ () { warn_ "$ME_: skipped test: $@"; Exit 77; }
 fatal_ () { warn_ "$ME_: hard error: $@"; Exit 99; }
 framework_failure_ () { warn_ "$ME_: set-up failure: $@"; Exit 99; }
 
+# This is used to simplify checking of the return value
+# which is useful when ensuring a command fails as desired.
+# I.e., just doing `command ... &&fail=1` will not catch
+# a segfault in command for example.  With this helper you
+# instead check an explicit exit code like
+#   returns_ 1 command ... || fail
+returns_ () {
+  local exp_exit="$1"
+  shift
+  "$@"
+  test $? -eq $exp_exit
+}
+
 # Sanitize this shell to POSIX mode, if possible.
 DUALCASE=1; export DUALCASE
 if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then