Commit | Line | Data |
---|---|---|
8d063cd8 LW |
1 | #!./perl |
2 | ||
8d063cd8 LW |
3 | # This is written in a peculiar style, since we're trying to avoid |
4 | # most of the constructs we'll be testing for. | |
5 | ||
a687059c LW |
6 | $| = 1; |
7 | ||
5d9a6404 MS |
8 | # Cheesy version of Getopt::Std. Maybe we should replace it with that. |
9 | if ($#ARGV >= 0) { | |
10 | foreach my $idx (0..$#ARGV) { | |
485988ae | 11 | next unless $ARGV[$idx] =~ /^-(\S+)$/; |
5a6e071d | 12 | $core = 1 if $1 eq 'core'; |
5d9a6404 MS |
13 | $verbose = 1 if $1 eq 'v'; |
14 | $with_utf= 1 if $1 eq 'utf8'; | |
485988ae RH |
15 | if ($1 =~ /^deparse(,.+)?$/) { |
16 | $deparse = 1; | |
17 | $deparse_opts = $1; | |
18 | } | |
5d9a6404 MS |
19 | splice(@ARGV, $idx, 1); |
20 | } | |
8d063cd8 LW |
21 | } |
22 | ||
378cc40b LW |
23 | chdir 't' if -f 't/TEST'; |
24 | ||
3e6e8be7 | 25 | die "You need to run \"make test\" first to set things up.\n" |
4633a7c4 LW |
26 | unless -e 'perl' or -e 'perl.exe'; |
27 | ||
7a315204 | 28 | if ($ENV{PERL_3LOG}) { # Tru64 third(1) tool, see perlhack |
09187cb1 JH |
29 | unless (-x 'perl.third') { |
30 | unless (-x '../perl.third') { | |
31 | die "You need to run \"make perl.third first.\n"; | |
32 | } | |
33 | else { | |
34 | print "Symlinking ../perl.third as perl.third...\n"; | |
35 | die "Failed to symlink: $!\n" | |
36 | unless symlink("../perl.third", "perl.third"); | |
37 | die "Symlinked but no executable perl.third: $!\n" | |
38 | unless -x 'perl.third'; | |
39 | } | |
40 | } | |
41 | } | |
42 | ||
3fb91a5e GS |
43 | # check leakage for embedders |
44 | $ENV{PERL_DESTRUCT_LEVEL} = 2 unless exists $ENV{PERL_DESTRUCT_LEVEL}; | |
45 | ||
4633a7c4 | 46 | $ENV{EMXSHELL} = 'sh'; # For OS/2 |
748a9306 | 47 | |
24c841ba MS |
48 | # Roll your own File::Find! |
49 | use TestInit; | |
50 | use File::Spec; | |
51 | my $curdir = File::Spec->curdir; | |
52 | my $updir = File::Spec->updir; | |
53 | ||
54 | sub _find_tests { | |
55 | my($dir) = @_; | |
56 | opendir DIR, $dir || die "Trouble opening $dir: $!"; | |
a1886d87 | 57 | foreach my $f (sort { $a cmp $b } readdir DIR) { |
24c841ba MS |
58 | next if $f eq $curdir or $f eq $updir; |
59 | ||
60 | my $fullpath = File::Spec->catdir($dir, $f); | |
61 | ||
62 | _find_tests($fullpath) if -d $fullpath; | |
63 | push @ARGV, $fullpath if $f =~ /\.t$/; | |
64 | } | |
65 | } | |
66 | ||
67 | unless (@ARGV) { | |
5a6e071d | 68 | foreach my $dir (qw(base comp cmd run io op)) { |
24c841ba MS |
69 | _find_tests($dir); |
70 | } | |
5a6e071d | 71 | _find_tests("lib") unless $core; |
7a315204 JH |
72 | my $mani = File::Spec->catdir($updir, "MANIFEST"); |
73 | if (open(MANI, $mani)) { | |
80ffb5f9 | 74 | while (<MANI>) { # similar code in t/harness |
b695f709 | 75 | if (m!^(ext/\S+/([^/]+\.t|test\.pl)|lib/\S+?(\.t|test\.pl))\s!) { |
5a6e071d PJ |
76 | $t = $1; |
77 | if (!$core || $t =~ m!^lib/[a-z]!) | |
78 | { | |
79 | push @ARGV, $t; | |
80 | $OVER{$t} = File::Spec->catdir($updir, $t); | |
81 | } | |
7a315204 JH |
82 | } |
83 | } | |
84 | } else { | |
85 | warn "$0: cannot open $mani: $!\n"; | |
86 | } | |
b695f709 | 87 | _find_tests('pod'); |
8d063cd8 LW |
88 | } |
89 | ||
7a315204 | 90 | # Tests known to cause infinite loops for the perlcc tests. |
595ae481 | 91 | # %infinite = ( 'comp/require.t', 1, 'op/bop.t', 1, 'lib/hostname.t', 1 ); |
24c841ba | 92 | %infinite = (); |
6ee623d5 | 93 | |
485988ae RH |
94 | if ($deparse) { |
95 | _testprogs('deparse', @ARGV); | |
96 | } else { | |
97 | _testprogs('perl', @ARGV); | |
98 | _testprogs('compile', @ARGV) if (-e "../testcompile"); | |
99 | } | |
6ee623d5 | 100 | |
bb365837 GS |
101 | sub _testprogs { |
102 | $type = shift @_; | |
103 | @tests = @_; | |
6ee623d5 | 104 | |
bb365837 | 105 | print <<'EOT' if ($type eq 'compile'); |
7a315204 | 106 | ------------------------------------------------------------------------------ |
6ee623d5 | 107 | TESTING COMPILER |
7a315204 | 108 | ------------------------------------------------------------------------------ |
bb365837 GS |
109 | EOT |
110 | ||
485988ae | 111 | print <<'EOT' if ($type eq 'deparse'); |
7a315204 | 112 | ------------------------------------------------------------------------------ |
485988ae | 113 | TESTING DEPARSER |
7a315204 | 114 | ------------------------------------------------------------------------------ |
485988ae RH |
115 | EOT |
116 | ||
595ae481 | 117 | $ENV{PERLCC_TIMEOUT} = 120 |
9636a016 | 118 | if ($type eq 'compile' && !$ENV{PERLCC_TIMEOUT}); |
ef712cf7 | 119 | |
bb365837 GS |
120 | $bad = 0; |
121 | $good = 0; | |
122 | $total = @tests; | |
123 | $files = 0; | |
124 | $totmax = 0; | |
908801fe JH |
125 | my $maxlen = 0; |
126 | my $maxsuflen = 0; | |
127 | foreach (@tests) { # The same code in lib/Test/Harness.pm:_run_all_tests | |
128 | my $suf = /\.(\w+)$/ ? $1 : ''; | |
129 | my $len = length; | |
130 | my $suflen = length $suf; | |
131 | $maxlen = $len if $len > $maxlen; | |
132 | $maxsuflen = $suflen if $suflen > $maxsuflen; | |
088b5126 | 133 | } |
908801fe JH |
134 | # + 3 : we want three dots between the test name and the "ok" |
135 | $dotdotdot = $maxlen + 3 - $maxsuflen; | |
bb365837 GS |
136 | while ($test = shift @tests) { |
137 | ||
138 | if ( $infinite{$test} && $type eq 'compile' ) { | |
595ae481 | 139 | print STDERR "$test creates infinite loop! Skipping.\n"; |
bb365837 | 140 | next; |
6ee623d5 | 141 | } |
bb365837 GS |
142 | if ($test =~ /^$/) { |
143 | next; | |
6ee623d5 | 144 | } |
485988ae RH |
145 | if ($type eq 'deparse') { |
146 | if ($test eq "comp/redef.t") { | |
147 | # Redefinition happens at compile time | |
148 | next; | |
149 | } | |
150 | elsif ($test eq "lib/switch.t") { | |
151 | # B::Deparse doesn't support source filtering | |
152 | next; | |
153 | } | |
154 | } | |
bb365837 | 155 | $te = $test; |
b695f709 | 156 | $te =~ s/\.\w+$/./; |
088b5126 | 157 | print "$te" . '.' x ($dotdotdot - length($te)); |
bb365837 | 158 | |
7a315204 JH |
159 | $test = $OVER{$test} if exists $OVER{$test}; |
160 | ||
d638aca2 GS |
161 | open(SCRIPT,"<$test") or die "Can't run $test.\n"; |
162 | $_ = <SCRIPT>; | |
485988ae | 163 | close(SCRIPT) unless ($type eq 'deparse'); |
d638aca2 GS |
164 | if (/#!.*perl(.*)$/) { |
165 | $switch = $1; | |
166 | if ($^O eq 'VMS') { | |
167 | # Must protect uppercase switches with "" on command line | |
168 | $switch =~ s/-([A-Z]\S*)/"-$1"/g; | |
55497cff | 169 | } |
135863df | 170 | } |
bb365837 | 171 | else { |
d638aca2 GS |
172 | $switch = ''; |
173 | } | |
6ee623d5 | 174 | |
485988ae RH |
175 | my $file_opts = ""; |
176 | if ($type eq 'deparse') { | |
177 | # Look for #line directives which change the filename | |
178 | while (<SCRIPT>) { | |
179 | $file_opts .= ",-f$3$4" | |
180 | if /^#\s*line\s+(\d+)\s+((\w+)|"([^"]+)")/; | |
181 | } | |
182 | close(SCRIPT); | |
183 | } | |
7a315204 | 184 | |
7a315204 | 185 | my $utf = $with_utf ? '-I../lib -Mutf8' : ''; |
4343e7c3 | 186 | my $testswitch = '-I. -MTestInit'; # -T will strict . from @INC |
485988ae RH |
187 | if ($type eq 'deparse') { |
188 | my $deparse = | |
189 | "./perl $testswitch $switch -I../lib -MO=-qq,Deparse,". | |
190 | "-l$deparse_opts$file_opts ". | |
7a315204 JH |
191 | "$test > $test.dp ". |
192 | "&& ./perl $testswitch $switch -I../lib $test.dp |"; | |
485988ae RH |
193 | open(RESULTS, $deparse) |
194 | or print "can't deparse '$deparse': $!.\n"; | |
195 | } | |
196 | elsif ($type eq 'perl') { | |
a7da9a42 JH |
197 | my $perl = $ENV{PERL} || './perl'; |
198 | my $run = "$perl $testswitch $switch $utf $test |"; | |
be24517c | 199 | open(RESULTS,$run) or print "can't run '$run': $!.\n"; |
d638aca2 GS |
200 | } |
201 | else { | |
be24517c | 202 | my $compile = |
4343e7c3 | 203 | "./perl $testswitch -I../lib ../utils/perlcc -o ". |
7a315204 JH |
204 | "$test.plc $utf $test ". |
205 | " && $test.plc |"; | |
be24517c JH |
206 | open(RESULTS, $compile) |
207 | or print "can't compile '$compile': $!.\n"; | |
7a315204 | 208 | unlink "$test.plc"; |
6ee623d5 | 209 | } |
d638aca2 | 210 | |
bb365837 GS |
211 | $ok = 0; |
212 | $next = 0; | |
213 | while (<RESULTS>) { | |
214 | if ($verbose) { | |
215 | print $_; | |
216 | } | |
217 | unless (/^#/) { | |
809908f7 | 218 | if (/^1\.\.([0-9]+)( todo ([\d ]+))?/) { |
bb365837 | 219 | $max = $1; |
809908f7 | 220 | %todo = map { $_ => 1 } split / /, $3 if $3; |
bb365837 GS |
221 | $totmax += $max; |
222 | $files += 1; | |
223 | $next = 1; | |
224 | $ok = 1; | |
225 | } | |
226 | else { | |
2fe373ce | 227 | if (/^(not )?ok (\d+)[^#]*(\s*#.*)?/ && |
595ae481 | 228 | $2 == $next) |
37ce32a7 MS |
229 | { |
230 | my($not, $num, $extra) = ($1, $2, $3); | |
231 | my($istodo) = $extra =~ /^\s*#\s*TODO/ if $extra; | |
809908f7 | 232 | $istodo = 1 if $todo{$num}; |
37ce32a7 MS |
233 | |
234 | if( $not && !$istodo ) { | |
235 | $ok = 0; | |
236 | $next = $num; | |
237 | last; | |
238 | } | |
239 | else { | |
240 | $next = $next + 1; | |
241 | } | |
d667a7e6 A |
242 | } |
243 | elsif (/^Bail out!\s*(.*)/i) { # magic words | |
244 | die "FAILED--Further testing stopped" . ($1 ? ": $1\n" : ".\n"); | |
bb365837 GS |
245 | } |
246 | else { | |
247 | $ok = 0; | |
248 | } | |
8d063cd8 LW |
249 | } |
250 | } | |
251 | } | |
bb365837 | 252 | close RESULTS; |
485988ae RH |
253 | if ($type eq 'deparse') { |
254 | unlink "./$test.dp"; | |
255 | } | |
211f317f JH |
256 | if ($ENV{PERL_3LOG}) { |
257 | my $tpp = $test; | |
a7da9a42 | 258 | $tpp =~ s:^../::; |
211f317f JH |
259 | $tpp =~ s:/:_:g; |
260 | $tpp =~ s:\.t$::; | |
a7da9a42 JH |
261 | rename("perl.3log", "perl.3log.$tpp") || |
262 | die "rename: perl3.log to perl.3log.$tpp: $!\n"; | |
211f317f | 263 | } |
bb365837 GS |
264 | $next = $next - 1; |
265 | if ($ok && $next == $max) { | |
266 | if ($max) { | |
267 | print "ok\n"; | |
268 | $good = $good + 1; | |
269 | } | |
270 | else { | |
271 | print "skipping test on this platform\n"; | |
272 | $files -= 1; | |
273 | } | |
bcce72a7 | 274 | } |
bb365837 GS |
275 | else { |
276 | $next += 1; | |
277 | print "FAILED at test $next\n"; | |
278 | $bad = $bad + 1; | |
279 | $_ = $test; | |
280 | if (/^base/) { | |
281 | die "Failed a basic test--cannot continue.\n"; | |
282 | } | |
8d063cd8 LW |
283 | } |
284 | } | |
8d063cd8 | 285 | |
bb365837 GS |
286 | if ($bad == 0) { |
287 | if ($ok) { | |
288 | print "All tests successful.\n"; | |
289 | # XXX add mention of 'perlbug -ok' ? | |
290 | } | |
291 | else { | |
292 | die "FAILED--no tests were run for some reason.\n"; | |
293 | } | |
8d063cd8 | 294 | } |
bb365837 | 295 | else { |
ba1398cf | 296 | $pct = $files ? sprintf("%.2f", ($files - $bad) / $files * 100) : "0.00"; |
bb365837 | 297 | if ($bad == 1) { |
e824fb2c | 298 | warn "Failed 1 test script out of $files, $pct% okay.\n"; |
bb365837 GS |
299 | } |
300 | else { | |
e824fb2c | 301 | warn "Failed $bad test scripts out of $files, $pct% okay.\n"; |
bb365837 GS |
302 | } |
303 | warn <<'SHRDLU'; | |
f46c10df CS |
304 | ### Since not all tests were successful, you may want to run some |
305 | ### of them individually and examine any diagnostic messages they | |
306 | ### produce. See the INSTALL document's section on "make test". | |
595ae481 NIS |
307 | ### If you are testing the compiler, then ignore this message |
308 | ### and run | |
6ee623d5 GS |
309 | ### ./perl harness |
310 | ### in the directory ./t. | |
f46c10df | 311 | SHRDLU |
bb365837 | 312 | warn <<'SHRDLU' if $good / $total > 0.8; |
3e6e8be7 MB |
313 | ### |
314 | ### Since most tests were successful, you have a good chance to | |
315 | ### get information with better granularity by running | |
595ae481 | 316 | ### ./perl harness |
3e6e8be7 MB |
317 | ### in directory ./t. |
318 | SHRDLU | |
bb365837 GS |
319 | } |
320 | ($user,$sys,$cuser,$csys) = times; | |
321 | print sprintf("u=%g s=%g cu=%g cs=%g scripts=%d tests=%d\n", | |
322 | $user,$sys,$cuser,$csys,$files,$totmax); | |
6ee623d5 | 323 | } |
3e6e8be7 | 324 | exit ($bad != 0); |