[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[FYI 3/3] {test-protocols} tap/awk: handle non-zero exit status from the
From: |
Stefano Lattarini |
Subject: |
[FYI 3/3] {test-protocols} tap/awk: handle non-zero exit status from the test command |
Date: |
Mon, 22 Aug 2011 15:33:08 +0200 |
* lib/tap-driver.sh (get_test_exit_message): New function in the
awk script, used to extract the exit status of the test program,
or at least a good guess of it.
(write_test_results): Use it, reporting an ERROR result if it
detects that the test program exited with a non-zero status.
* tests/tap-signal.test: Account for the differences in the
error messages generated by the awk and perl TAP drivers. Fix
an unrelated typo in comments since we are at it.
---
ChangeLog | 12 ++++++++++++
lib/tap-driver.sh | 24 ++++++++++++++++++++++++
tests/tap-signal.test | 19 ++++++++++++-------
3 files changed, 48 insertions(+), 7 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 5f17e99..db6a46b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
2011-08-22 Stefano Lattarini <address@hidden>
+ tap/awk: handle non-zero exit status from the test command
+ * lib/tap-driver.sh (get_test_exit_message): New function in the
+ awk script, used to extract the exit status of the test program,
+ or at least a good guess of it.
+ (write_test_results): Use it, reporting an ERROR result if it
+ detects that the test program exited with a non-zero status.
+ * tests/tap-signal.test: Account for the differences in the
+ error messages generated by the awk and perl TAP drivers. Fix
+ an unrelated typo in comments since we are at it.
+
+2011-08-22 Stefano Lattarini <address@hidden>
+
tap/awk: prepare to fetch the exit status of the test command
* lib/tap-driver.sh: Rewrite some logic in the main parsing loop,
to make it possible to read the exit status of the test command
diff --git a/lib/tap-driver.sh b/lib/tap-driver.sh
index 09fcaee..1255662 100755
--- a/lib/tap-driver.sh
+++ b/lib/tap-driver.sh
@@ -416,6 +416,23 @@ function setup_result_obj(line)
result_obj["explanation"] = line
}
+function get_test_exit_message(status)
+{
+ if (status == 0)
+ return ""
+ if (status !~ /^[1-9][0-9]*$/)
+ abort("getting exit status")
+ if (status < 127)
+ exit_details = ""
+ else if (status == 127)
+ exit_details = " (command not found?)"
+ else if (status >= 128 && status <= 255)
+ exit_details = sprintf(" (terminated by signal %d?)", status - 128)
+ else if (status >= 256)
+ exit_details = " (abnormal termination)"
+ return sprintf("exited with status %d%s", status, exit_details)
+}
+
function write_test_results()
{
print ":global-test-result: " get_global_test_result() > trs_file
@@ -559,6 +576,13 @@ if (!bailed_out)
testsuite_error(sprintf("too %s tests run (expected %d, got %d)",
bad_amount, planned_tests, testno))
}
+ if (!ignore_exit)
+ {
+ # Fetch exit status from the last line.
+ exit_message = get_test_exit_message(nextline)
+ if (exit_message)
+ testsuite_error(exit_message)
+ }
}
write_test_results()
diff --git a/tests/tap-signal.test b/tests/tap-signal.test
index 8ceeddd..416422e 100755
--- a/tests/tap-signal.test
+++ b/tests/tap-signal.test
@@ -55,22 +55,27 @@ signal_caught ()
numeric=$1
symbolic=$2
sig_re="((SIG)?$symbolic|$numeric)"
- tst_re="signal-$numeric\\.test"
- if $EGREP "^ERROR: $tst_re - terminated by signal $sig_re$" stdout; then
+ wbound_re="($|[^a-zA-Z0-9_-])"
+ pfx_re="^ERROR: signal-$numeric\\.test"
+ case $am_tap_implementation in
+ perl) rx="$pfx_re - terminated by signal $sig_re$";;
+ shell) rx="$pfx_re .*terminated by signal $sig_re$wbound_re";;
+ *) fatal_ "invalid \$am_tap_implementation '$am_tap_implementation'";;
+ esac
+ if LC_ALL=C $EGREP "$rx" stdout; then
return 0
elif test $have_solaris_bug = yes; then
case $symbolic in
- INT|TERM) $EGREP "^ERROR: $tst_re - exited with status 208$" stdout;;
- *) return 1;;
+ INT|TERM)
+ $EGREP "$pfx_re - exited with status 208( |$)" stdout;;
esac
- else
- return 1
fi
+ return 1
}
all_signals_caught ()
{
- # This are the only signals that are portably trappable.
+ # These are the only signals that are portably trappable.
signal_caught 1 HUP
signal_caught 2 INT
signal_caught 13 PIPE
--
1.7.2.3