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