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