tap/awk: "Bail out!" recognized also after leading whitespace
authorStefano Lattarini <stefano.lattarini@gmail.com>
Tue, 27 Dec 2011 10:45:59 +0000 (11:45 +0100)
committerStefano Lattarini <stefano.lattarini@gmail.com>
Tue, 27 Dec 2011 17:30:00 +0000 (18:30 +0100)
Newer versions of TAP::Harness (e.g., 3.23 on Perl 5.14.1)
recognize a "Bail out!" directive also when it is prepended by
leading whitespace; this was not the case for older TAP:Harness
versions, (e.g., for version 3.17 on Perl 5.12.4), and for our
TAP driver implemented in awk.

* lib/tap-driver.sh: Handle the "Bail out!" directive also when
it is preceded by leading whitespace.
* tests/tap-spurious.test: Remove the tests checking that a
"Bail out!" string coming right after leading whitespace does
not trigger a bailout action.
* tests/tap-bailout-leading-space.test: New test.
* tests/list-of-tests.mk: Add it.

Problem reported by Jim Meyering in automake bug#10374.

ChangeLog
lib/tap-driver.sh
tests/list-of-tests.mk
tests/tap-bailout-leading-space.test [new file with mode: 0755]
tests/tap-no-spurious.test

index e0122fb..d7ff68b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,22 @@
 2011-12-27  Stefano Lattarini  <stefano.lattarini@gmail.com>
 
+       tap/awk: "Bail out!" recognized also after leading whitespace
+       Newer versions of TAP::Harness (e.g., 3.23 on Perl 5.14.1)
+       recognize a "Bail out!" directive also when it is prepended by
+       leading whitespace; this was not the case for older TAP:Harness
+       versions, (e.g., for version 3.17 on Perl 5.12.4), and for our
+       TAP driver implemented in awk.
+       * lib/tap-driver.sh: Handle the "Bail out!" directive also when
+       it is preceded by leading whitespace.
+       * tests/tap-spurious.test: Remove the tests checking that a
+       "Bail out!" string coming right after leading whitespace does
+       not trigger a bailout action.
+       * tests/tap-bailout-leading-space.test: New test.
+       * tests/list-of-tests.mk: Add it.
+       Problem reported by Jim Meyering in automake bug#10374.
+
+2011-12-27  Stefano Lattarini  <stefano.lattarini@gmail.com>
+
        tests: fix spurious failure of cond29.test
        * tests/cond29.test: Limit the amount of virtual memory available
        to the automake process to ~ 150 MB, rather than only ~ 20 MB, to
index c911991..c011298 100755 (executable)
@@ -23,7 +23,7 @@
 # bugs to <bug-automake@gnu.org> or send patches to
 # <automake-patches@gnu.org>.
 
-scriptversion=2011-09-28.14; # UTC
+scriptversion=2011-12-27.17; # UTC
 
 # Make unconditional expansion of undefined variables an error.  This
 # helps a lot in preventing typo-related bugs.
@@ -573,12 +573,16 @@ while (1)
         handle_tap_plan(0, $0)
       }
     # "Bail out!" magic.
-    else if ($0 ~ /^Bail out!/)
+    # Older versions of prove and TAP::Harness (e.g., 3.17) did not
+    # recognize a "Bail out!" directive when preceded by leading
+    # whitespace, but more modern versions (e.g., 3.23) do.  So we
+    # emulate the latter, "more modern" behaviour.
+    else if ($0 ~ /^[ \t]*Bail out!/)
       {
         bailed_out = 1
         # Get the bailout message (if any), with leading and trailing
         # whitespace stripped.  The message remains stored in `$0`.
-        sub("^Bail out![ \t]*", "");
+        sub("^[ \t]*Bail out![ \t]*", "");
         sub("[ \t]*$", "");
         # Format the error message for the
         bailout_message = "Bail out!"
index 71a7693..259b232 100644 (file)
@@ -1001,6 +1001,7 @@ syntax.test \
 tap-ambiguous-directive.test \
 tap-autonumber.test \
 tap-bailout.test \
+tap-bailout-leading-space.test \
 tap-bailout-and-logging.test \
 tap-bailout-suppress-badexit.test \
 tap-bailout-suppress-later-diagnostic.test \
diff --git a/tests/tap-bailout-leading-space.test b/tests/tap-bailout-leading-space.test
new file mode 100755 (executable)
index 0000000..1615c09
--- /dev/null
@@ -0,0 +1,72 @@
+#! /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/>.
+
+# Older versions of prove and TAP::Harness (e.g., 3.17) didn't recognize
+# a "Bail out!" directive that was preceded by whitespace, but more modern
+# versions (e.g., 3.23) do.  So we leave this behaviour undefined for the
+# perl implementation of the Automake TAP driver, but expect the latter,
+# "more modern" behaviour in our awk TAP driver.
+
+am_parallel_tests=yes
+am_tap_implementation=shell
+. ./defs || Exit 1
+
+. "$testsrcdir"/tap-setup.sh || fatal_ "sourcing tap-setup.sh"
+
+cat > a.test <<END
+1..1
+ok 1
+ Bail out!
+END
+
+cat > b.test <<END
+1..1
+ok 1 # SKIP
+${tab}Bail out!
+END
+
+cat > c.test <<END
+1..1
+  ${tab}  ${tab}${tab}Bail out!   FUBAR! $tab
+END
+
+cat >> exp <<END
+PASS: a.test 1
+ERROR: a.test - Bail out!
+SKIP: b.test 1
+ERROR: b.test - Bail out!
+ERROR: c.test - Bail out! FUBAR!
+END
+
+TESTS='a.test b.test c.test' $MAKE -e check >stdout \
+  && { cat stdout; Exit 1; }
+cat stdout
+
+count_test_results total=5 pass=1 fail=0 xpass=0 xfail=0 skip=1 error=3
+
+LC_ALL=C sort exp > t
+mv -f t exp
+
+# We need the sort below to account for parallel make usage.
+grep ': [abcde]\.test' stdout \
+  | sed "s/[ $tab]*#[ $tab]*SKIP.*//" \
+  | LC_ALL=C sort > got
+
+cat exp
+cat got
+diff exp got
+
+:
index bf3d7ae..c2d5bc5 100755 (executable)
@@ -84,6 +84,8 @@ set -x # Reset shell xtraces.
 
 # The prove(1) utility doesn't bail out on these, so our driver
 # shouldn't either.
+# See comments in `tap-bailout-leading-space.test' for an explanation
+# of why we don't have a whitespace-prepended "Bail out!" line here.
 cat >> all.test <<'END'
 bailout
 bailout!
@@ -93,7 +95,6 @@ Bailout
 Bailout!
 Bail out
  Bail out
- Bail out!
 #Bail out!
 # Bail out!
 END