+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
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
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 ();
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
}
}
-sub finish ()
-{
- write_test_results;
- close LOG or die "closing $log_file: $!\n";
- exit 0;
-}
-
sub stringify_test_result ($)
{
my $result = shift;
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 ($)
{
# 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);
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;
}
# ----------- #
--- /dev/null
+#! /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
+
+: