From: Stefano Lattarini Date: Mon, 22 Aug 2011 13:00:09 +0000 (+0200) Subject: tap/awk: handle non-zero exit status from the test command X-Git-Tag: ng-0.5a~89^2~97^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d630a0d4dc7c1af141ab3c61458cdbc690dac88c;p=thirdparty%2Fautomake.git 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. --- diff --git a/ChangeLog b/ChangeLog index 5f17e99a0..db6a46b19 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2011-08-22 Stefano Lattarini + + 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 tap/awk: prepare to fetch the exit status of the test command diff --git a/lib/tap-driver.sh b/lib/tap-driver.sh index 09fcaee0f..125566259 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 8ceedddb6..416422e23 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