]> sjero.net Git - wget/blob - tests/run-px
Add colors to test summary.
[wget] / tests / run-px
1 #!/usr/bin/env perl
2
3 use 5.006;
4 use warnings;
5 use strict;
6
7 use Term::ANSIColor ':constants';
8 $Term::ANSIColor::AUTORESET = 1;
9
10 die "Please specify the top source directory.\n" if (!@ARGV);
11 my $top_srcdir = shift @ARGV;
12
13 my @tests = (
14     'Test-auth-basic.px',
15     'Test-proxy-auth-basic.px',
16     'Test-proxied-https-auth.px',
17     'Test-N-HTTP-Content-Disposition.px',
18     'Test--spider.px',
19     'Test-c-full.px',
20     'Test-c-partial.px',
21     'Test-c-shorter.px',
22     'Test-c.px',
23     'Test-E-k-K.px',
24     'Test-E-k.px',
25     'Test-ftp.px',
26     'Test-HTTP-Content-Disposition-1.px',
27     'Test-HTTP-Content-Disposition-2.px',
28     'Test-HTTP-Content-Disposition.px',
29     'Test-N-current.px',
30     'Test-N-smaller.px',
31     'Test-N-no-info.px',
32     'Test-N--no-content-disposition.px',
33     'Test-N--no-content-disposition-trivial.px',
34     'Test--no-content-disposition.px',
35     'Test--no-content-disposition-trivial.px',
36     'Test-N-old.px',
37     'Test-nonexisting-quiet.px',
38     'Test-noop.px',
39     'Test-np.px',
40     'Test-N.px',
41     'Test-O-HTTP-Content-Disposition.px',
42     'Test-O--no-content-disposition.px',
43     'Test-O--no-content-disposition-trivial.px',
44     'Test-O-nonexisting.px',
45     'Test-O.px',
46     'Test-O-nc.px',
47     'Test-Restrict-Lowercase.px',
48     'Test-Restrict-Uppercase.px',
49     'Test--spider-fail.px',
50     'Test--spider-r-HTTP-Content-Disposition.px',
51     'Test--spider-r--no-content-disposition.px',
52     'Test--spider-r--no-content-disposition-trivial.px',
53     'Test--spider-r.px',
54 );
55
56 my @tested;
57
58 foreach my $test (@tests) {
59     print "Running $test\n\n";
60     system("$^X $top_srcdir/tests/$test");
61     push @tested, { name => $test, result => $? };
62 }
63
64 print "\n";
65 foreach my $test (@tested) {
66     ($test->{result} == 0)
67       ? print GREEN 'pass: '
68       : print RED 'FAIL: ';
69    print $test->{name}, "\n";
70 }
71
72 my $count = sub
73 {
74     return {
75       pass => sub { scalar grep $_->{result} == 0, @tested },
76       fail => sub { scalar grep $_->{result} != 0, @tested },
77     }->{$_[0]}->();
78 };
79
80 my $summary = sub
81 {
82     my @lines = (
83         "${\scalar @tested} tests were run",
84         "${\$count->('pass')} PASS, ${\$count->('fail')} FAIL",
85     );
86     my $len_longest = sub
87     {
88         local $_ = 0;
89         foreach my $line (@lines) {
90             if (length $line > $_) {
91                 $_ = length $line;
92             }
93         }
94         return $_;
95     }->();
96     return join "\n",
97       '=' x $len_longest,
98       @lines,
99       '=' x $len_longest;
100 }->();
101
102 print "\n";
103 print $count->('fail')
104   ? RED $summary
105   : GREEN $summary;
106 print "\n";
107
108 exit $count->('fail');