]> sjero.net Git - wget/blobdiff - tests/run-px
Add colors to test summary.
[wget] / tests / run-px
index 37f14324d59f535a4fb99d5d215aa46719fe9aef..92e9061e0694645e3e3474dfbe07e80fff19647d 100755 (executable)
@@ -1,5 +1,11 @@
 #!/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;
@@ -12,6 +18,7 @@ my @tests = (
     'Test--spider.px',
     'Test-c-full.px',
     'Test-c-partial.px',
+    'Test-c-shorter.px',
     'Test-c.px',
     'Test-E-k-K.px',
     'Test-E-k.px',
@@ -36,6 +43,7 @@ my @tests = (
     'Test-O--no-content-disposition-trivial.px',
     'Test-O-nonexisting.px',
     'Test-O.px',
+    'Test-O-nc.px',
     'Test-Restrict-Lowercase.px',
     'Test-Restrict-Uppercase.px',
     'Test--spider-fail.px',
@@ -45,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("$top_srcdir/tests/$test");
-    push @results, $?;
+    system("$^X $top_srcdir/tests/$test");
+    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');