]> git.ipfire.org Git - thirdparty/automake.git/commitdiff
tap: support colorization of testsuite progress output
authorStefano Lattarini <stefano.lattarini@gmail.com>
Sun, 17 Jul 2011 14:46:41 +0000 (16:46 +0200)
committerStefano Lattarini <stefano.lattarini@gmail.com>
Tue, 2 Aug 2011 21:01:25 +0000 (23:01 +0200)
* lib/tap-driver (%COLORS): New variable (definition extracted
from `lib/am/check.am:$(am__tty_colors)', with some obvious
adjustments.
(report): Adjust to colorize console output when required,
using ...
(decorate_result): ... this new function.
(colored): New function, used by the one above.
* tests/tap-summary.test: Also run the checks when `color-tests'
is in use.
* tests/Makefile.am (XFAIL_TESTS): Remove `tap-color.test'.

ChangeLog
lib/tap-driver
tests/Makefile.am
tests/Makefile.in
tests/tap-summary.test

index 6ee3fd5b9c1bfb340ee963aca41ce0a0427c9bc9..965b11fd8c15b86bdc15671a5333db4ead29ea56 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2011-07-18  Stefano Lattarini  <stefano.lattarini@gmail.com>
+
+       tap: support colorization of testsuite progress output
+       * lib/tap-driver (%COLORS): New variable (definition extracted
+       from `lib/am/check.am:$(am__tty_colors)', with some obvious
+       adjustments.
+       (report): Adjust to colorize console output when required,
+       using ...
+       (decorate_result): ... this new function.
+       (colored): New function, used by the one above.
+       * tests/tap-summary.test: Also run the checks when `color-tests'
+       is in use.
+       * tests/Makefile.am (XFAIL_TESTS): Remove `tap-color.test'.
+
 2011-07-18  Stefano Lattarini  <stefano.lattarini@gmail.com>
 
        tap: some preparatory refactoring (2)
index b669292b9f21457c6ec711095cf04debb2193fbd..69533b4954e092beae7d9f5dec00da46ea43154a 100755 (executable)
@@ -27,6 +27,17 @@ my $HELP = "$ME: TAP-aware test driver for Automake testsuite harness." .
 
 my $VERSION = '(experimental version)';
 
+# Keep this in sync with `lib/am/check.am:$(am__tty_colors)'.
+my %COLOR = (
+  red => "\e[0;31m",
+  grn => "\e[0;32m",
+  lgn => "\e[1;32m",
+  blu => "\e[1;34m",
+  mgn => "\e[0;35m",
+  brg => "\e[1m",
+  std => "\e[m",
+);
+
 # ------------------- #
 #  Global variables.  #
 # ------------------- #
@@ -211,17 +222,46 @@ sub stringify_test_result ($)
   die "INTERNAL ERROR"; # NOTREACHED
 }
 
+sub colored ($$)
+{
+  my ($color_name, $text) = @_;
+  return  $COLOR{$color_name} . $text . $COLOR{'std'};
+}
+
+sub decorate_result ($)
+{
+  my $result = shift;
+  return $result unless $cfg{"color-tests"};
+  my %color_for_result =
+    (
+      "ERROR" => 'mgn',
+      "PASS"  => 'grn',
+      "XPASS" => 'red',
+      "FAIL"  => 'red',
+      "XFAIL" => 'lgn',
+      "SKIP"  => 'blu',
+    );
+  if (my $color = $color_for_result{$result})
+    {
+      return colored ($color, $result);
+    }
+  else
+    {
+      return $result; # Don't colorize unknown stuff.
+    }
+}
+
 sub report ($;$)
 {
   my ($msg, $result, $explanation) = (undef, @_);
   if ($result =~ /^(?:X?(?:PASS|FAIL)|SKIP|ERROR)/)
     {
-      $msg = "$result: $test_script_name";
+      $msg = ": $test_script_name";
       add_test_result $result;
     }
   elsif ($result eq "#")
     {
-      $msg = "# $test_script_name:";
+      $msg = " $test_script_name:";
     }
   else
     {
@@ -229,10 +269,11 @@ sub report ($;$)
     }
   $msg .= " $explanation" if defined $explanation;
   $msg .= "\n";
-  print OLDOUT $msg;
+  # Output on console might be colorized.
+  print OLDOUT decorate_result ($result) . $msg;
   # Log the result in the log file too, to help debugging (this is
   # especially true when said result is a TAP error or "Bail out!").
-  print $msg;
+  print $result . $msg;
 }
 
 sub testuite_error ($)
index 2ef4d7005c4e9560b45da382935b0711ec052536..b857f49e77e8f16b5c2a1e84e778e1bc1d11f8da 100644 (file)
@@ -28,7 +28,6 @@ override-conditional-2.test \
 pr8365-remake-timing.test \
 yacc-dist-nobuild-subdir.test \
 tap-bad-prog.test \
-tap-color.test \
 tap-plan-corner2.test \
 tap-message-0.test \
 tap-signal.test \
index c5e100951ce517a13a06a8d8bb5366f3901bcd35..2ebfa4d2ff3f11229b84c22e7baae5df1050869c 100644 (file)
@@ -273,7 +273,7 @@ EXTRA_DIST = ChangeLog-old gen-parallel-tests instspc-tests.sh \
        extract-testsuite-summary
 XFAIL_TESTS = all.test auxdir2.test cond17.test gcj6.test \
        override-conditional-2.test pr8365-remake-timing.test \
-       yacc-dist-nobuild-subdir.test tap-bad-prog.test tap-color.test \
+       yacc-dist-nobuild-subdir.test tap-bad-prog.test \
        tap-plan-corner2.test tap-message-0.test tap-signal.test \
        txinfo5.test $(instspc_xfail_tests)
 parallel_tests = backcompat5-p.test check-exported-srcdir-p.test \
index 649485e72bee227e96e30e57b65e2eacc6ed6261..d5c512e501eb70a4d7453b7c7efa2547b2ec9105 100755 (executable)
@@ -58,7 +58,12 @@ do_check ()
   cat > summary.exp
   cat all.test
   st=0
-  $MAKE check > stdout || st=$?
+  if test $use_colors = yes; then
+    make_cmd="env AM_COLOR_TESTS=always $MAKE -e"
+  else
+    make_cmd=$MAKE
+  fi
+  $make_cmd check > stdout || st=$?
   cat stdout
   if test $expect_failure = yes; then
     test $st -gt 0 || Exit 1
@@ -78,9 +83,7 @@ do_check ()
   $compare summary.exp summary.got || Exit 1
 }
 
-# FIXME: also enable testing of colors!
-#for use_colors in "no" "yes"; do
-for use_colors in "no"; do
+for use_colors in "no" "yes"; do
 
   cp Makefile.stub Makefile.am