]> git.ipfire.org Git - thirdparty/automake.git/commitdiff
tap: correctly handle string "0" in TAP messages
authorStefano Lattarini <stefano.lattarini@gmail.com>
Wed, 17 Aug 2011 15:07:59 +0000 (17:07 +0200)
committerStefano Lattarini <stefano.lattarini@gmail.com>
Wed, 17 Aug 2011 16:39:29 +0000 (18:39 +0200)
* lib/tap-driver.pl (is_null_string): New function, can be used
to determine whether a given string variable is empty or undefined.
Useful to avoid pitfalls like:
  if ($message) { print "$message\n"; }
which wouldn't print anything if $message is the literal "0".
(handle_tap_test, handle_tap_plan, handle_tap_bailout): Use it,
to avoid missing messages composed only by a literal "0" in TAP
result descriptions and in skip, todo and bailout explanations.
* tests/tap-message-0.test: Enhance.
* tests/Makefile.am (XFAIL_TESTS): Remove it, it passes now.

ChangeLog
lib/tap-driver.pl
tests/Makefile.am
tests/Makefile.in
tests/tap-message-0.test

index 571218b4352b286272e920afae866f5852c4441b..985cc86af6eec5db3ac90ce4969de72e676733f5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2011-08-17  Stefano Lattarini  <stefano.lattarini@gmail.com>
+
+       tap: correctly handle string "0" in TAP messages
+       * lib/tap-driver.pl (is_null_string): New function, can be used
+       to determine whether a given string variable is empty or undefined.
+       Useful to avoid pitfalls like:
+         if ($message) { print "$message\n"; }
+       which wouldn't print anything if $message is the literal "0".
+       (handle_tap_test, handle_tap_plan, handle_tap_bailout): Use it,
+       to avoid missing messages composed only by a literal "0" in TAP
+       result descriptions and in skip, todo and bailout explanations.
+       * tests/tap-message-0.test: Enhance.
+       * tests/Makefile.am (XFAIL_TESTS): Remove it, it passes now.
+
 2011-08-17  Stefano Lattarini  <stefano.lattarini@gmail.com>
 
        tap: a minor simplification in the perl TAP driver
index ed991310295fa1b5fa3a601f0dd7a75f16b6794c..7043815f3652c37ac424ace3b92cb15b8a019b50 100755 (executable)
@@ -106,6 +106,7 @@ sub get_test_results ();
 sub handle_tap_bailout ($);
 sub handle_tap_plan ($);
 sub handle_tap_test ($);
+sub is_null_string ($);
 sub main (@);
 sub must_recheck ();
 sub report ($;$);
@@ -136,6 +137,16 @@ sub bool_opt ($$)
     }
 }
 
+# If the given string is undefined or empty, return true, otherwise
+# return false.  This function is useful to avoid pitfalls like:
+#   if ($message) { print "$message\n"; }
+# which wouldn't print anything if $message is the literal "0".
+sub is_null_string ($)
+{
+  my $str = shift;
+  return ! (defined $str and length $str);
+}
+
 # Convert a boolean to a "yes"/"no" string.
 sub yn ($)
 {
@@ -329,10 +340,9 @@ sub handle_tap_test ($)
   my $test_result = stringify_test_result $test;
   my $string = $test->number;
   
-  if (my $description = $test->description)
-    {
-      $string .= " $description";
-    }
+  my $description = $test->description;
+  $string .= " $description"
+    unless is_null_string $description;
 
   if ($plan_seen == LATE_PLAN)
     {
@@ -349,10 +359,9 @@ sub handle_tap_test ($)
   elsif (my $directive = $test->directive)
     {
       $string .= " # $directive";
-      if (my $explanation = $test->explanation)
-        {
-          $string .= " $explanation";
-        }
+      my $explanation = $test->explanation;
+      $string .= " $explanation"
+        unless is_null_string $explanation;
     }
 
   report $test_result, $string;
@@ -381,8 +390,8 @@ sub handle_tap_plan ($)
   # of SKIP result.
   if ($plan->directive && $testno == 0)
     {
-      my $explanation = $plan->explanation ?
-                        "- " . $plan->explanation : undef;
+      my $explanation = is_null_string ($plan->explanation) ?
+                        undef : "- " . $plan->explanation;
       report "SKIP", $explanation;
     }
 }
@@ -391,7 +400,8 @@ sub handle_tap_bailout ($)
 {
   my ($bailout, $msg) = ($_[0], "Bail out!");
   $bailed_out = 1;
-  $msg .= " " . $bailout->explanation if $bailout->explanation;
+  $msg .= " " . $bailout->explanation
+    unless is_null_string $bailout->explanation;
   testsuite_error $msg;
 }
 
index be61a412ca06e8ed2d7566ea7519994ba6684f01..174f07bdfef5c2769a63bb7c3871af8bc28aa628 100644 (file)
@@ -31,7 +31,6 @@ gcj6.test \
 override-conditional-2.test \
 pr8365-remake-timing.test \
 yacc-dist-nobuild-subdir.test \
-tap-message-0.test \
 txinfo5.test
 
 
index 5a1751478d9cd47790b106d30e8e73edf506d19d..b014a8d8d4694b7efda7b960ec00ef8087ae9b52 100644 (file)
@@ -288,7 +288,7 @@ EXTRA_DIST = ChangeLog-old gen-parallel-tests instspc-tests.sh \
        extract-testsuite-summary tap-setup.sh tap-summary-aux.sh
 XFAIL_TESTS = all.test auxdir2.test cond17.test gcj6.test \
        override-conditional-2.test pr8365-remake-timing.test \
-       yacc-dist-nobuild-subdir.test tap-message-0.test txinfo5.test \
+       yacc-dist-nobuild-subdir.test txinfo5.test \
        $(instspc_xfail_tests)
 parallel_tests = backcompat5-p.test check-exported-srcdir-p.test \
        check-fd-redirect-p.test check-tests-in-builddir-p.test \
index bce333fbb9c0524f2599a6415bd6ed54ec3f707d..87b24925725ba0c51d11cce7adda7cdac09a2f6c 100755 (executable)
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 # TAP support:
-#  - having "0" as a test description (or TODO or SKIP message) should
-#    be supported
-# Note that a bug in some versions of TAP::Parser causes this not to be
-# generally true!
+#  - having "0" as a test description (or TODO or SKIP or "Bail out!"
+#    message) should be supported
 
 parallel_tests=yes
 . ./defs || Exit 1
@@ -63,4 +61,21 @@ cat exp
 cat got
 diff exp got
 
+echo '1..0 # SKIP 0' > all.test
+$MAKE check >stdout || { cat stdout; Exit 1; }
+cat stdout
+
+count_test_results total=1 pass=0 fail=0 xpass=0 xfail=0 skip=1 error=0
+
+grep '^SKIP: all.test - 0' stdout
+
+echo 'Bail out! 0' > all.test
+$MAKE check >stdout && { cat stdout; Exit 1; }
+cat stdout
+
+count_test_results total=1 pass=0 fail=0 xpass=0 xfail=0 skip=0 error=1
+
+grep '^ERROR: all.test - Bail out! 0' stdout
+
+
 :