[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 3/3] tap driver: handle signals received by the tests being run
From: |
Stefano Lattarini |
Subject: |
[PATCH 3/3] tap driver: handle signals received by the tests being run |
Date: |
Sat, 6 Aug 2011 21:47:28 +0200 |
* 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.
---
ChangeLog | 13 +++++++++++++
doc/automake.texi | 3 ++-
lib/tap-driver | 23 ++++++++++++++++++-----
tests/tap-signal.test | 36 +++++++++++++++++++++++++++---------
4 files changed, 60 insertions(+), 15 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 3ca5076..bd71052 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
2011-08-06 Stefano Lattarini <address@hidden>
+ 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 <address@hidden>
+
test driver: a preparatory refactoring (2)
* lib/tap-driver (finish): Move code to fetch the message about
the exit status of the test being run to ...
diff --git a/doc/automake.texi b/doc/automake.texi
index c63742d..6be5c2d 100644
--- a/doc/automake.texi
+++ b/doc/automake.texi
@@ -9646,10 +9646,11 @@ supports the following options, whose names are chosen
for enhanced
compatibility with the @command{prove} utility.
@table @option
address@hidden 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
diff --git a/lib/tap-driver b/lib/tap-driver
index c9dbe19..1f5a271 100755
--- a/lib/tap-driver
+++ b/lib/tap-driver
@@ -236,11 +236,24 @@ sub get_test_exit_message ()
# 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 ()
diff --git a/tests/tap-signal.test b/tests/tap-signal.test
index fb75c83..ce75ddd 100755
--- a/tests/tap-signal.test
+++ b/tests/tap-signal.test
@@ -36,14 +36,32 @@ chmod a+x *.test
. "$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
:
--
1.7.2.3