+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)
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. #
# ------------------- #
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
{
}
$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 ($)
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 \
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 \
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
$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