automake-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] tap: log all TAP stream, even after a "Bail out!"


From: Stefano Lattarini
Subject: [PATCH] tap: log all TAP stream, even after a "Bail out!"
Date: Fri, 12 Aug 2011 17:08:57 +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                          |   18 +++++++++++
 lib/tap-driver                     |   56 +++++++++++++++++++----------------
 tests/Makefile.am                  |    1 +
 tests/Makefile.in                  |    1 +
 tests/tap-bailout-and-logging.test |   49 +++++++++++++++++++++++++++++++
 5 files changed, 99 insertions(+), 26 deletions(-)
 create mode 100755 tests/tap-bailout-and-logging.test

diff --git a/ChangeLog b/ChangeLog
index 42985e0..f3b0684 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,23 @@
 2011-08-12  Stefano Lattarini  <address@hidden>
 
+       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  <address@hidden>
+
        coverage: TAP diagnostics after "Bail out!" aren't reported
        This is compatible with the behaviour of the `prove' utility.
        * tests/tap-bailout-suppress-later-diagnostic.test: New test.
diff --git a/lib/tap-driver b/lib/tap-driver
index 0f4eb84..a1dacdb 100755
--- a/lib/tap-driver
+++ b/lib/tap-driver
@@ -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;
 }
 
 # ----------- #
diff --git a/tests/Makefile.am b/tests/Makefile.am
index b9b6bf7..7af1eb6 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -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 \
diff --git a/tests/Makefile.in b/tests/Makefile.in
index a298a57..e294596 100644
--- a/tests/Makefile.in
+++ b/tests/Makefile.in
@@ -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
index 0000000..9854ea8
--- /dev/null
+++ b/tests/tap-bailout-and-logging.test
@@ -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
+
+:
-- 
1.7.2.3




reply via email to

[Prev in Thread] Current Thread [Next in Thread]