From e7ca7771e57e0d02c9dedf0e3bfc5128b397d7f2 Mon Sep 17 00:00:00 2001 From: Stefano Lattarini Date: Fri, 12 Aug 2011 15:51:12 +0200 Subject: [PATCH] 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. --- 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 42985e0e2..f3b06840f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2011-08-12 Stefano Lattarini + + 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 coverage: TAP diagnostics after "Bail out!" aren't reported diff --git a/lib/tap-driver b/lib/tap-driver index 0f4eb84d4..a1dacdbb6 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 b9b6bf76f..7af1eb6e8 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 a298a5711..e294596dd 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 000000000..9854ea805 --- /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 . + +# 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 <