+2011-08-06 Stefano Lattarini <stefano.lattarini@gmail.com>
+
+ tap driver: handle signals received by the tests being run
+ * lib/tap-driver (get_test_exit_message): Also deal with signals,
+ by using the `wait' method of the TAP::Parser object instead of
+ the `exit' method. This required the use of the standard perl
+ module `POSIX'.
+ * doc/automake.texi (Use TAP with the Automake test harness):
+ Document that `--ignore-exit' has effect also on terminating
+ signals. Add a "synchronizing" comment that references the tests
+ 'tap-exit.test' and 'tap-signal.test'.
+ * tests/tap-signal.test: Extend and adjust.
+
2011-08-06 Stefano Lattarini <stefano.lattarini@gmail.com>
test driver: a preparatory refactoring (2)
compatibility with the @command{prove} utility.
@table @option
+@c Keep in sync with 'tap-exit.test' and 'tap-signal.test'.
@item --ignore-exit
Causes the test driver to ignore the exit status of the test scripts;
by default, the driver will report an error if the script exit with a
-non-zero status.
+non-zero status. This option has effect also
@item --comments
Instruct the test driver to display TAP diagnostic (i.e., lines beginning
with the @samp{#} character) in the testsuite progress output too; by
# Flush all the remaining TAP stream, so that we can obtain the
# exit status of the TAP producer.
do {} while defined get_tap_line ();
- # TODO: we should probably use $parser->wait here, to catch signals too
- if ($parser->exit != 0)
- {
- return sprintf "exited with status %d", $parser->exit;
- }
+ my $wstatus = $parser->wait;
+ # Return an undefined value if the producer exited with success.
+ return unless $wstatus;
+ # Otherwise, determine whether it exited with error or was terminated
+ # by a signal.
+ use POSIX qw (WIFEXITED WEXITSTATUS WIFSIGNALED WTERMSIG);
+ if (WIFEXITED ($wstatus))
+ {
+ return sprintf "exited with status %d", WEXITSTATUS ($wstatus);
+ }
+ elsif (WIFSIGNALED ($wstatus))
+ {
+ return sprintf "terminated by signal %d", WTERMSIG ($wstatus);
+ }
+ else
+ {
+ return "terminated abnormally";
+ }
}
sub finish ()
. "$testsrcdir"/tap-setup.sh || fatal_ "sourcing tap-setup.sh"
-for append in '' 'TEST_LOG_DRIVER_FLAGS = --ignore-exit'; do
- echo "$append" >> Makefile
- $MAKE check >stdout && { cat stdout; Exit 1; }
- cat stdout
- count_test_results total=8 pass=4 fail=0 xpass=0 xfail=0 skip=0 error=4
- for sig in 1 2 13 15; do
- grep "^ERROR: signal-$sig\\.test - terminated by signal.*" stdout
- done
-done
+signal_caught ()
+{
+ numeric=$1
+ symbolic=$2
+ sig_re="((SIG)?$symbolic|$numeric)"
+ tst_re="signal-$numeric\\.test"
+ $EGREP "^ERROR: $tst_re - terminated by signal $sig_re$" stdout
+}
+
+all_signals_caught ()
+{
+ # This are the only signals that are portably trappable.
+ signal_caught 1 HUP
+ signal_caught 2 INT
+ signal_caught 13 PIPE
+ signal_caught 15 TERM
+}
+
+$MAKE check >stdout && { cat stdout; Exit 1; }
+cat stdout
+count_test_results total=8 pass=4 fail=0 xpass=0 xfail=0 skip=0 error=4
+all_signals_caught
+
+echo 'TEST_LOG_DRIVER_FLAGS = --ignore-exit' >> Makefile
+$MAKE check >stdout || { cat stdout; Exit 1; }
+cat stdout
+count_test_results total=4 pass=4 fail=0 xpass=0 xfail=0 skip=0 error=0
: