]> sjero.net Git - wget/blob - tests/run-px
fixed 204 response handling, added new Test-204.px
[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-ftp-list-Multinet.px',
39     'Test-ftp-list-Unknown.px',
40     'Test-ftp-list-Unknown-a.px',
41     'Test-ftp-list-Unknown-hidden.px',
42     'Test-ftp-list-Unknown-list-a-fails.px',
43     'Test-ftp-list-UNIX-hidden.px',
44     'Test-HTTP-Content-Disposition-1.px',
45     'Test-HTTP-Content-Disposition-2.px',
46     'Test-HTTP-Content-Disposition.px',
47     'Test-i-ftp.px',
48     'Test-i-http.px',
49     'Test-idn-headers.px',
50     'Test-idn-meta.px',
51     'Test-idn-cmd.px',
52     'Test-idn-cmd-utf8.px',
53     'Test-idn-robots.px',
54     'Test-idn-robots-utf8.px',
55     'Test-iri.px',
56     'Test-iri-percent.px',
57     'Test-iri-disabled.px',
58     'Test-iri-forced-remote.px',
59     'Test-iri-list.px',
60     'Test-k.px',
61     'Test-meta-robots.px',
62     'Test-N-current.px',
63     'Test-N-smaller.px',
64     'Test-N-no-info.px',
65     'Test-N--no-content-disposition.px',
66     'Test-N--no-content-disposition-trivial.px',
67     'Test--no-content-disposition.px',
68     'Test--no-content-disposition-trivial.px',
69     'Test-N-old.px',
70     'Test-nonexisting-quiet.px',
71     'Test-noop.px',
72     'Test-np.px',
73     'Test-N.px',
74     'Test-O-HTTP-Content-Disposition.px',
75     'Test-O--no-content-disposition.px',
76     'Test-O--no-content-disposition-trivial.px',
77     'Test-O-nonexisting.px',
78     'Test-O.px',
79     'Test--post-file.px',
80     'Test-O-nc.px',
81     'Test-restrict-ascii.px',
82     'Test-Restrict-Lowercase.px',
83     'Test-Restrict-Uppercase.px',
84     'Test-stdouterr.px',
85     'Test--spider-fail.px',
86     'Test--spider-r-HTTP-Content-Disposition.px',
87     'Test--spider-r--no-content-disposition.px',
88     'Test--spider-r--no-content-disposition-trivial.px',
89     'Test--spider-r.px',
90     'Test--httpsonly-r.px',
91     'Test--start-pos.px',
92     'Test-ftp--start-pos.px',
93     'Test--start-pos--continue.px',
94     'Test-204.px',
95 );
96
97 foreach my $var (qw(SYSTEM_WGETRC WGETRC)) {
98     $ENV{$var} = '/dev/null';
99 }
100
101 my @tested;
102
103 foreach my $test (@tests) {
104     print "Running $test\n\n";
105     system("$^X -I$top_srcdir/tests $top_srcdir/tests/$test $top_srcdir");
106     push @tested, { name => $test, result => $? >> 8 };
107 }
108
109 foreach my $var (qw(SYSTEM_WGETRC WGETRC)) {
110     delete $ENV{$var};
111 }
112
113 my %exit = (
114     pass    => 0,
115     fail    => 1,
116     skip    => 2,
117     unknown => 3, # or greater
118 );
119
120 my %colors = (
121     $exit{pass}    => colored('pass:',    'green'  ),
122     $exit{fail}    => colored('FAIL:',    'red'    ),
123     $exit{skip}    => colored('Skip:',    'yellow' ),
124     $exit{unknown} => colored('Unknown:', 'magenta'),
125 );
126
127 print "\n";
128 foreach my $test (@tested) {
129     my $colored = exists $colors{$test->{result}}
130       ? $colors{$test->{result}}
131       : $colors{$exit{unknown}};
132     print "$colored $test->{name}\n";
133 }
134
135 my $count = sub
136 {
137     return {
138       pass    => sub { scalar grep $_->{result} == $exit{pass},    @tested },
139       fail    => sub { scalar grep $_->{result} == $exit{fail},    @tested },
140       skip    => sub { scalar grep $_->{result} == $exit{skip},    @tested },
141       unknown => sub { scalar grep $_->{result} >= $exit{unknown}, @tested },
142     }->{$_[0]}->();
143 };
144
145 my $summary = sub
146 {
147     my @lines = (
148         "${\scalar @tested} tests were run",
149         "${\$count->('pass')} PASS, ${\$count->('fail')} FAIL",
150         "${\$count->('skip')} SKIP, ${\$count->('unknown')} UNKNOWN",
151     );
152     my $len_longest = sub
153     {
154         local $_ = 0;
155         foreach my $line (@lines) {
156             if (length $line > $_) {
157                 $_ = length $line;
158             }
159         }
160         return $_;
161     }->();
162     return join "\n",
163       '=' x $len_longest,
164       @lines,
165       '=' x $len_longest;
166 }->();
167
168 print "\n";
169 print $count->('fail') || $count->('unknown')
170   ? colored($summary, 'red')
171   : colored($summary, 'green');
172 print "\n";
173
174 exit $count->('fail') + $count->('unknown');