]> git.ipfire.org Git - thirdparty/automake.git/commitdiff
tap/awk: handle non-zero exit status from the test command
authorStefano Lattarini <stefano.lattarini@gmail.com>
Mon, 22 Aug 2011 13:00:09 +0000 (15:00 +0200)
committerStefano Lattarini <stefano.lattarini@gmail.com>
Mon, 22 Aug 2011 13:23:43 +0000 (15:23 +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
lib/tap-driver.sh
tests/tap-signal.test

index 5f17e99a0157a3d3d79eccf4aa4a984bc4fc4542..db6a46b196403b6c92a1c7b20aaead2cc88d5c46 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2011-08-22  Stefano Lattarini  <stefano.lattarini@gmail.com>
+
+       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  <stefano.lattarini@gmail.com>
 
        tap/awk: prepare to fetch the exit status of the test command
index 09fcaee0f7ee6962e2b61c58d1bba03bd1b249e2..12556625925c7a6a812d95a01801ea9d171dc5ed 100755 (executable)
@@ -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()
index 8ceedddb60576d4e37fa5f54875754f6a5eba8a0..416422e23a50272063501ae65a718157c0c2125b 100755 (executable)
@@ -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