* 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 | 14 ++++++++++++++ lib/tap-driver | 42 ++++++++++++++++++++++++++++++++++++++---- tests/Makefile.am | 1 - tests/Makefile.in | 2 +- tests/tap-summary.test | 11 +++++++---- 5 files changed, 60 insertions(+), 10 deletions(-)
diff --git a/ChangeLog b/ChangeLog index 9cf06aa..e718a98 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,19 @@ 2011-07-18 Stefano Lattarini <stefano.lattar...@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.lattar...@gmail.com> + tap: some preparatory refactoring (2) This is a follow-up simplification. * lib/tap-driver (console_output): Renamed ... diff --git a/lib/tap-driver b/lib/tap-driver index b669292..2abd5d9 100755 --- a/lib/tap-driver +++ b/lib/tap-driver @@ -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 => '[0;31m', + grn => '[0;32m', + lgn => '[1;32m', + blu => '[1;34m', + mgn => '[0;35m', + brg => '[1m', + std => '[m', +); + # ------------------- # # Global variables. # # ------------------- # @@ -211,17 +222,39 @@ sub stringify_test_result ($) die "INTERNAL ERROR"; # NOTREACHED } +sub colored ($$) +{ + my ($color_name, $text) = @_; + return $COLOR{$color_name} . $text . $COLOR{'std'}; +} + +sub decorate_result ($) +{ + return $_[0] unless $cfg{"color-tests"}; + # Best way to simulate a 'switch' construct here. + for (@_) + { + $_ eq "ERROR" and return colored ('mgn', $_); + $_ eq "PASS" and return colored ('grn', $_); + $_ eq "XPASS" and return colored ('red', $_); + $_ eq "FAIL" and return colored ('red', $_); + $_ eq "XFAIL" and return colored ('lgn', $_); + $_ eq "SKIP" and return colored ('blu', $_); + return $_; # 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 +262,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 ($) diff --git a/tests/Makefile.am b/tests/Makefile.am index 2ef4d70..b857f49 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 \ diff --git a/tests/Makefile.in b/tests/Makefile.in index c5e1009..2ebfa4d 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -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 \ diff --git a/tests/tap-summary.test b/tests/tap-summary.test index 649485e..d5c512e 100755 --- a/tests/tap-summary.test +++ b/tests/tap-summary.test @@ -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 -- 1.7.2.3