From: Steven Schubiger Date: Fri, 7 Nov 2008 21:06:38 +0000 (+0100) Subject: Add colors to test summary. X-Git-Tag: v1.13~391 X-Git-Url: http://sjero.net/git/?p=wget;a=commitdiff_plain;h=7fc928183366c256ef4c425c19ea2f054d68aafd Add colors to test summary. --- diff --git a/tests/ChangeLog b/tests/ChangeLog index a401c297..751402d0 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,9 @@ +2008-11-07 Steven Schubiger + + * run-px: Use some colors for the summary part of the test + output to strengthen the distinction between a successful + or failing run. + 2008-11-06 Steven Schubiger * run-px: When executing test scripts, invoke them with the diff --git a/tests/run-px b/tests/run-px index 60b848d1..92e9061e 100755 --- a/tests/run-px +++ b/tests/run-px @@ -1,7 +1,12 @@ #!/usr/bin/env perl + +use 5.006; use warnings; use strict; +use Term::ANSIColor ':constants'; +$Term::ANSIColor::AUTORESET = 1; + die "Please specify the top source directory.\n" if (!@ARGV); my $top_srcdir = shift @ARGV; @@ -48,26 +53,56 @@ my @tests = ( 'Test--spider-r.px', ); -my @results; +my @tested; -for my $test (@tests) { +foreach my $test (@tests) { print "Running $test\n\n"; system("$^X $top_srcdir/tests/$test"); - push @results, $?; + push @tested, { name => $test, result => $? }; } -for (my $i=0; $i != @tests; ++$i) { - if ($results[$i] == 0) { - print "pass: "; - } else { - print "FAIL: "; - } - print "$tests[$i]\n"; +print "\n"; +foreach my $test (@tested) { + ($test->{result} == 0) + ? print GREEN 'pass: ' + : print RED 'FAIL: '; + print $test->{name}, "\n"; } +my $count = sub +{ + return { + pass => sub { scalar grep $_->{result} == 0, @tested }, + fail => sub { scalar grep $_->{result} != 0, @tested }, + }->{$_[0]}->(); +}; + +my $summary = sub +{ + my @lines = ( + "${\scalar @tested} tests were run", + "${\$count->('pass')} PASS, ${\$count->('fail')} FAIL", + ); + my $len_longest = sub + { + local $_ = 0; + foreach my $line (@lines) { + if (length $line > $_) { + $_ = length $line; + } + } + return $_; + }->(); + return join "\n", + '=' x $len_longest, + @lines, + '=' x $len_longest; +}->(); + +print "\n"; +print $count->('fail') + ? RED $summary + : GREEN $summary; print "\n"; -print scalar(@results) . " tests were run\n"; -print scalar(grep $_ == 0, @results) . " PASS\n"; -print scalar(grep $_ != 0, @results) . " FAIL\n"; -exit scalar (grep $_ != 0, @results); +exit $count->('fail');