test defs: new subroutines for test skipping/failing.
authorJim Meyering <meyering@redhat.com>
Sun, 16 Jan 2011 14:36:07 +0000 (15:36 +0100)
committerStefano Lattarini <stefano.lattarini@gmail.com>
Sat, 23 Apr 2011 21:40:54 +0000 (23:40 +0200)
* tests/defs.in (Exit): Move definition of this function earlier.
(warn_, skip_, fail_, framework_failure_): New functions, inspired
to the homonyms in gnulib's tests/init.sh.
($stderr_fileno_): New global variable, used by the new functions
above.
* tests/README: Updated.

From a suggestion by Ralf Wildenhues.

ChangeLog
tests/README
tests/defs.in

index 1764e86..5963deb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2011-04-23  Jim Meyering  <meyering@redhat.com>
+           Stefano Lattarini  <stefano.lattarini@gmail.com>
+
+       test defs: new subroutines for test skipping/failing
+       * tests/defs.in (Exit): Move definition of this function earlier.
+       (warn_, skip_, fail_, framework_failure_): New functions, inspired
+       to the homonyms in gnulib's tests/init.sh.
+       ($stderr_fileno_): New global variable, used by the new functions
+       above.
+       * tests/README: Updated.
+       From a suggestion by Ralf Wildenhues.
+
 2011-04-23  Stefano Lattarini  <stefano.lattarini@gmail.com>
 
        tests: fix typo (copy & paste blunder) in heading comment
index 93f9cbf..26ce3ff 100644 (file)
@@ -100,6 +100,11 @@ Do
   Include ./defs in every test script (see existing tests for examples
   of how to do this).
 
+  Use the `skip_' function to skip tests, with a meaningful message if
+  possible.  Where convenient, use the `warn_' function to print generic
+  warnings, and the `fail_' function for test failures.  Finally, you may
+  use the `framework_fail_' function for hard errors.
+
   For tests that use the `parallel-tests' Automake option, set the shell
   variable `parallel_tests' to "yes" before including ./defs.  Also,
   use for them a name that ends in `-p.test' and does not clash with any
index ef35d9f..4e0db16 100644 (file)
@@ -122,6 +122,32 @@ echo "$PATH"
 # (See note about `export' in the Autoconf manual.)
 export PATH
 
+# We use a trap below for cleanup.  This requires us to go through
+# hoops to get the right exit status transported through the signal.
+# So use `Exit STATUS' instead of `exit STATUS' inside of the tests.
+# Turn off errexit here so that we don't trip the bug with OSF1/Tru64
+# sh inside this function.
+Exit ()
+{
+  set +e
+  (exit $1)
+  exit $1
+}
+
+# Print warnings (e.g., about skipped and failed tests) to this file
+# number.  Override by putting, say:
+#   stderr_fileno_=9; export stderr_fileno_; exec 9>&2;
+# in the definition of AM_TESTS_ENVIRONMENT.
+# This is useful when using automake's parallel tests mode, to print the
+# reason for skip/failure to console, rather than to the *.log files.
+: ${stderr_fileno_=2}
+
+# Copied from Gnulib's `tests/init.sh'.
+warn_ () { echo "$@" 1>&$stderr_fileno_; }
+fail_ () { warn_ "$me: failed test: $@"; Exit 1; }
+skip_ () { warn_ "$me: skipped test: $@"; Exit 77; }
+framework_failure_ () { warn_ "$me: set-up failure: $@"; Exit 99; }
+
 for tool in : $required
 do
   # Check that each required tool is present.
@@ -278,18 +304,6 @@ case "$srcdir" in
     ;;
 esac
 
-# We use a trap below for cleanup.  This requires us to go through
-# hoops to get the right exit status transported through the signal.
-# So use `Exit STATUS' instead of `exit STATUS' inside of the tests.
-# Turn off errexit here so that we don't trip the bug with OSF1/Tru64
-# sh inside this function.
-Exit ()
-{
-  set +e
-  (exit $1)
-  exit $1
-}
-
 curdir=`pwd`
 testSubDir=$me.dir
 test ! -d $testSubDir || {