From: Stefano Lattarini Date: Sun, 17 Jul 2011 14:46:41 +0000 (+0200) Subject: tap: support colorization of testsuite progress output X-Git-Tag: ng-0.5a~89^2~155^2~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2fdeb6bb98b502373fbd7af66fd304724ddc94b6;p=thirdparty%2Fautomake.git 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'. --- diff --git a/ChangeLog b/ChangeLog index 6ee3fd5b9..965b11fd8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2011-07-18 Stefano Lattarini + + 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 tap: some preparatory refactoring (2) diff --git a/lib/tap-driver b/lib/tap-driver index b669292b9..69533b495 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 => "\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 ($) diff --git a/tests/Makefile.am b/tests/Makefile.am index 2ef4d7005..b857f49e7 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 c5e100951..2ebfa4d2f 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 649485e72..d5c512e50 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