]> sjero.net Git - wget/blob - tests/run-px
cce44e459927296d6f89bf44a3b854fcfbcc0c25
[wget] / tests / run-px
1 #!/usr/bin/env perl
2
3 use 5.006;
4 use strict;
5 use warnings;
6
7 use Term::ANSIColor;
8
9 die "Please specify the top source directory.\n" if (!@ARGV);
10 my $top_srcdir = shift @ARGV;
11
12 my @tests = (
13     'Test-auth-basic.px',
14     'Test-auth-no-challenge.px',
15     'Test-auth-no-challenge-url.px',
16     'Test-auth-with-content-disposition.px',
17     'Test-auth-retcode.px',
18     'Test-cookies.px',
19     'Test-cookies-401.px',
20     'Test-proxy-auth-basic.px',
21     'Test-proxied-https-auth.px',
22     'Test-N-HTTP-Content-Disposition.px',
23     'Test--spider.px',
24     'Test-c-full.px',
25     'Test-c-partial.px',
26     'Test-c-shorter.px',
27     'Test-c.px',
28     'Test-E-k-K.px',
29     'Test-E-k.px',
30     'Test-ftp.px',
31     'Test-ftp-pasv-fail.px',
32     'Test-ftp-bad-list.px',
33     'Test-ftp-recursive.px',
34     'Test-ftp-iri.px',
35     'Test-ftp-iri-fallback.px',
36     'Test-ftp-iri-recursive.px',
37     'Test-ftp-iri-disabled.px',
38     'Test-HTTP-Content-Disposition-1.px',
39     'Test-HTTP-Content-Disposition-2.px',
40     'Test-HTTP-Content-Disposition.px',
41     'Test-i-ftp.px',
42     'Test-i-http.px',
43     'Test-idn-headers.px',
44     'Test-idn-meta.px',
45     'Test-idn-cmd.px',
46     'Test-idn-robots.px',
47     'Test-iri.px',
48     'Test-iri-percent.px',
49     'Test-iri-disabled.px',
50     'Test-iri-forced-remote.px',
51     'Test-iri-list.px',
52     'Test-k.px',
53     'Test-meta-robots.px',
54     'Test-N-current.px',
55     'Test-N-smaller.px',
56     'Test-N-no-info.px',
57     'Test-N--no-content-disposition.px',
58     'Test-N--no-content-disposition-trivial.px',
59     'Test--no-content-disposition.px',
60     'Test--no-content-disposition-trivial.px',
61     'Test-N-old.px',
62     'Test-nonexisting-quiet.px',
63     'Test-noop.px',
64     'Test-np.px',
65     'Test-N.px',
66     'Test-O-HTTP-Content-Disposition.px',
67     'Test-O--no-content-disposition.px',
68     'Test-O--no-content-disposition-trivial.px',
69     'Test-O-nonexisting.px',
70     'Test-O.px',
71     'Test-O-nc.px',
72     'Test-restrict-ascii.px',
73     'Test-Restrict-Lowercase.px',
74     'Test-Restrict-Uppercase.px',
75     'Test--spider-fail.px',
76     'Test--spider-r-HTTP-Content-Disposition.px',
77     'Test--spider-r--no-content-disposition.px',
78     'Test--spider-r--no-content-disposition-trivial.px',
79     'Test--spider-r.px',
80 );
81
82 foreach my $var (qw(SYSTEM_WGETRC WGETRC)) {
83     $ENV{$var} = '/dev/null';
84 }
85
86 my @tested;
87
88 foreach my $test (@tests) {
89     print "Running $test\n\n";
90     system("$^X -I$top_srcdir/tests $top_srcdir/tests/$test $top_srcdir");
91     push @tested, { name => $test, result => $? >> 8 };
92 }
93
94 foreach my $var (qw(SYSTEM_WGETRC WGETRC)) {
95     delete $ENV{$var};
96 }
97
98 my %exit = (
99     pass    => 0,
100     fail    => 1,
101     skip    => 2,
102     unknown => 3, # or greater
103 );
104
105 my %colors = (
106     $exit{pass}    => colored('pass:',    'green'  ),
107     $exit{fail}    => colored('FAIL:',    'red'    ),
108     $exit{skip}    => colored('Skip:',    'yellow' ),
109     $exit{unknown} => colored('Unknown:', 'magenta'),
110 );
111
112 print "\n";
113 foreach my $test (@tested) {
114     my $colored = exists $colors{$test->{result}}
115       ? $colors{$test->{result}}
116       : $colors{$exit{unknown}};
117     print "$colored $test->{name}\n";
118 }
119
120 my $count = sub
121 {
122     return {
123       pass    => sub { scalar grep $_->{result} == $exit{pass},    @tested },
124       fail    => sub { scalar grep $_->{result} == $exit{fail},    @tested },
125       skip    => sub { scalar grep $_->{result} == $exit{skip},    @tested },
126       unknown => sub { scalar grep $_->{result} >= $exit{unknown}, @tested },
127     }->{$_[0]}->();
128 };
129
130 my $summary = sub
131 {
132     my @lines = (
133         "${\scalar @tested} tests were run",
134         "${\$count->('pass')} PASS, ${\$count->('fail')} FAIL",
135         "${\$count->('skip')} SKIP, ${\$count->('unknown')} UNKNOWN",
136     );
137     my $len_longest = sub
138     {
139         local $_ = 0;
140         foreach my $line (@lines) {
141             if (length $line > $_) {
142                 $_ = length $line;
143             }
144         }
145         return $_;
146     }->();
147     return join "\n",
148       '=' x $len_longest,
149       @lines,
150       '=' x $len_longest;
151 }->();
152
153 print "\n";
154 print $count->('fail') || $count->('unknown')
155   ? colored($summary, 'red')
156   : colored($summary, 'green');
157 print "\n";
158
159 exit $count->('fail') + $count->('unknown');