]> git.ipfire.org Git - thirdparty/automake.git/commitdiff
tap: log all TAP stream, even after a "Bail out!"
authorStefano Lattarini <stefano.lattarini@gmail.com>
Fri, 12 Aug 2011 13:51:12 +0000 (15:51 +0200)
committerStefano Lattarini <stefano.lattarini@gmail.com>
Fri, 12 Aug 2011 15:06:28 +0000 (17:06 +0200)
* lib/tap-driver ($bailed_out): New global boolean variable,
telling whether a "Bail out!" directive has been seen or not.
(handle_tap_bailout): This function does not anymore stop the
reading from TAP stream; instead, it sets `$bailed_out' to a
true value, so that only the subsequent parsing of the input
TAP stream is stopped.
(finish): Remove, no more needed, its contents inlined into ...
(main): ... this function, with related adjustments in the code
flow.
(get_test_exit_message): Do not "flush" the input TAP stream
to fetch the exit status of test script, it is not anymore
required.  Add a sanity check.
* tests/tap-bailout-and-logging.test: New test.
* tests/Makefile.am (tap_with_common_setup_tests): Update.

ChangeLog
lib/tap-driver
tests/Makefile.am
tests/Makefile.in
tests/tap-bailout-and-logging.test [new file with mode: 0755]

index 42985e0e2eabcf9257a2a2d4ee5db1ed5c21005f..f3b06840f838112f53f5b0138f691b7d23f9e70d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2011-08-12  Stefano Lattarini  <stefano.lattarini@gmail.com>
+
+       tap: log all TAP stream, even after a "Bail out!"
+       * lib/tap-driver ($bailed_out): New global boolean variable,
+       telling whether a "Bail out!" directive has been seen or not.
+       (handle_tap_bailout): This function does not anymore stop the
+       reading from TAP stream; instead, it sets `$bailed_out' to a
+       true value, so that only the subsequent parsing of the input
+       TAP stream is stopped.
+       (finish): Remove, no more needed, its contents inlined into ...
+       (main): ... this function, with related adjustments in the code
+       flow.
+       (get_test_exit_message): Do not "flush" the input TAP stream
+       to fetch the exit status of test script, it is not anymore
+       required.  Add a sanity check.
+       * tests/tap-bailout-and-logging.test: New test.
+       * tests/Makefile.am (tap_with_common_setup_tests): Update.
+
 2011-08-12  Stefano Lattarini  <stefano.lattarini@gmail.com>
 
        coverage: TAP diagnostics after "Bail out!" aren't reported
index 0f4eb84d4bca7502c06fc4554c929d71d4142bcc..a1dacdbb6a317cd29003c0159f197ef053876c4d 100755 (executable)
@@ -45,6 +45,7 @@ my %COLOR = (
 
 my $testno = 0;     # Number of test results seen so far.
 my $plan_seen = 0;  # Whether the TAP plan has been seen or not.
+my $bailed_out = 0; # Whether a "Bail out!" directive has been seen.
 my $parser;         # TAP parser object (will be initialized later).
 
 # When true, it means that the rest of the input stream cannot
@@ -96,7 +97,6 @@ sub colored ($$);
 sub copy_in_global_log ();
 sub decorate_result ($);
 sub extract_tap_comment ($);
-sub finish ();
 sub get_global_test_result ();
 sub get_test_exit_message ();
 sub get_test_results ();
@@ -210,10 +210,10 @@ sub start (@)
 
 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 $parser->next;
   my $wstatus = $parser->wait;
+  # Watch out for possible internal errors.
+  die "couldn't get the exit ststus of the TAP producer"
+    unless defined $wstatus;
   # Return an undefined value if the producer exited with success.
   return unless $wstatus;
   # Otherwise, determine whether it exited with error or was terminated
@@ -233,13 +233,6 @@ sub get_test_exit_message ()
        }
 }
 
-sub finish ()
-{
-  write_test_results;
-  close LOG or die "closing $log_file: $!\n";
-  exit 0;
-}
-
 sub stringify_test_result ($)
 {
   my $result = shift;
@@ -387,9 +380,9 @@ sub handle_tap_plan ($)
 sub handle_tap_bailout ($)
 {
   my ($bailout, $msg) = ($_[0], "Bail out!");
+  $bailed_out = 1;
   $msg .= " " . $bailout->explanation if $bailout->explanation;
   testsuite_error $msg;
-  finish;
 }
 
 sub extract_tap_comment ($)
@@ -411,6 +404,9 @@ sub main (@)
     {
       # Verbatim copy any input line into the log file.
       print $cur->raw . "\n";
+      # Parsing of TAP input should stop after a "Bail out!" directive.
+      next if $bailed_out;
+
       if ($cur->is_plan)
         {
           handle_tap_plan ($cur);
@@ -429,22 +425,30 @@ sub main (@)
           report "#", "$comment" if length $comment;
        }
     }
-  if (!$plan_seen)
-    {
-      testsuite_error "missing test plan";
-    }
-  elsif ($parser->tests_planned != $parser->tests_run)
-    {
-      my ($planned, $run) = ($parser->tests_planned, $parser->tests_run);
-      my $bad_amount = $run > $planned ? "many" : "few";
-      testsuite_error (sprintf "too %s tests run (expected %d, got %d)",
-                               $bad_amount, $planned, $run);
-    }
-  if (!$cfg{"ignore-exit"} and my $msg = get_test_exit_message)
+  # A "Bail out!" directive should cause us to ignore any following TAP
+  # error, as well as a non-zero exit status from the TAP producer.
+  if (!$bailed_out)
     {
-      testsuite_error $msg;
+      if (!$plan_seen)
+      {
+        testsuite_error "missing test plan";
+      }
+    elsif ($parser->tests_planned != $parser->tests_run)
+      {
+        my ($planned, $run) = ($parser->tests_planned, $parser->tests_run);
+        my $bad_amount = $run > $planned ? "many" : "few";
+        testsuite_error (sprintf "too %s tests run (expected %d, got %d)",
+                                 $bad_amount, $planned, $run);
+      }
     }
-  finish;
+  if (!$cfg{"ignore-exit"} && !$bailed_out)
+  {
+    my $msg = get_test_exit_message ();
+    testsuite_error $msg if $msg;
+  }
+  write_test_results;
+  close LOG or die "closing $log_file: $!\n";
+  exit 0;
 }
 
 # ----------- #
index b9b6bf76f9e6e7161533fde351924e9e5e581967..7af1eb6e807d259e732213014804d48e33b7da13 100644 (file)
@@ -1144,6 +1144,7 @@ testsuite-summary-count-many.log: extract-testsuite-summary
 tap_with_common_setup_tests = \
 tap-autonumber.test \
 tap-bailout.test \
+tap-bailout-and-logging.test \
 tap-bailout-suppress-badexit.test \
 tap-bailout-suppress-later-diagnostic.test \
 tap-bailout-suppress-later-errors.test \
index a298a5711dd73cb7f2a8f2fd58ec1ea860ed0582..e294596dd0f73027b64eb55a3fda0c786c55b34f 100644 (file)
@@ -1384,6 +1384,7 @@ $(parallel_tests)
 tap_with_common_setup_tests = \
 tap-autonumber.test \
 tap-bailout.test \
+tap-bailout-and-logging.test \
 tap-bailout-suppress-badexit.test \
 tap-bailout-suppress-later-diagnostic.test \
 tap-bailout-suppress-later-errors.test \
diff --git a/tests/tap-bailout-and-logging.test b/tests/tap-bailout-and-logging.test
new file mode 100755 (executable)
index 0000000..9854ea8
--- /dev/null
@@ -0,0 +1,49 @@
+#! /bin/sh
+# Copyright (C) 2011 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# TAP support:
+#  - even after a "Bail out!" directive, all input is still copied in
+#    the log file
+
+parallel_tests=yes
+. ./defs || Exit 1
+
+. "$testsrcdir"/tap-setup.sh || fatal_ "sourcing tap-setup.sh"
+
+cat > all.test <<END
+First line
+Bail out!
+non-TAP line after bailout
+# TAP diagnostic after bailout
+1..0 # SKIP TAP plan after bailout
+ok 1 - TAP result after bailout
+END
+
+$MAKE check && { cat all.log; Exit 1; }
+cat all.log
+
+for rx in \
+  'First line' \
+  'Bail out!' \
+  'non-TAP line after bailout' \
+  '# TAP diagnostic after bailout' \
+  '1\.\.0 # SKIP TAP plan after bailout' \
+  'ok 1 - TAP result after bailout' \
+; do
+  grep "^$rx$" all.log
+done
+
+: