]> sjero.net Git - wget/commitdiff
Add colors to test summary.
authorSteven Schubiger <stsc@members.fsf.org>
Fri, 7 Nov 2008 21:06:38 +0000 (22:06 +0100)
committerSteven Schubiger <stsc@members.fsf.org>
Fri, 7 Nov 2008 21:06:38 +0000 (22:06 +0100)
tests/ChangeLog
tests/run-px

index a401c297942c19de850a2e91158eba1ba5201b51..751402d053f2a55bf0ee22627401cd81ab1b9d1f 100644 (file)
@@ -1,3 +1,9 @@
+2008-11-07  Steven Schubiger  <stsc@members.fsf.org>
+
+       * 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  <stsc@members.fsf.org>
 
        * run-px: When executing test scripts, invoke them with the
 2008-11-06  Steven Schubiger  <stsc@members.fsf.org>
 
        * run-px: When executing test scripts, invoke them with the
index 60b848d100fd9c9356284bd581ea415097ddaa65..92e9061e0694645e3e3474dfbe07e80fff19647d 100755 (executable)
@@ -1,7 +1,12 @@
 #!/usr/bin/env perl
 #!/usr/bin/env perl
+
+use 5.006;
 use warnings;
 use strict;
 
 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;
 
 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',
 );
 
     '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");
     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 "\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');