Commit | Line | Data |
8d063cd8 |
1 | #!./perl |
2 | |
8d063cd8 |
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 |
6 | $| = 1; |
7 | |
60e23f2f |
8 | # Let tests know they're running in the perl core. Useful for modules |
9 | # which live dual lives on CPAN. |
10 | $ENV{PERL_CORE} = 1; |
11 | |
5d9a6404 |
12 | # Cheesy version of Getopt::Std. Maybe we should replace it with that. |
b326da91 |
13 | @argv = (); |
5d9a6404 |
14 | if ($#ARGV >= 0) { |
15 | foreach my $idx (0..$#ARGV) { |
b326da91 |
16 | push( @argv, $ARGV[$idx] ), next unless $ARGV[$idx] =~ /^-(\S+)$/; |
5a6e071d |
17 | $core = 1 if $1 eq 'core'; |
5d9a6404 |
18 | $verbose = 1 if $1 eq 'v'; |
19 | $with_utf= 1 if $1 eq 'utf8'; |
f193aa2f |
20 | $byte_compile = 1 if $1 eq 'bytecompile'; |
21 | $compile = 1 if $1 eq 'compile'; |
485988ae |
22 | if ($1 =~ /^deparse(,.+)?$/) { |
23 | $deparse = 1; |
24 | $deparse_opts = $1; |
25 | } |
5d9a6404 |
26 | } |
8d063cd8 |
27 | } |
b326da91 |
28 | @ARGV = @argv; |
8d063cd8 |
29 | |
378cc40b |
30 | chdir 't' if -f 't/TEST'; |
31 | |
3e6e8be7 |
32 | die "You need to run \"make test\" first to set things up.\n" |
196918b0 |
33 | unless -e 'perl' or -e 'perl.exe' or -e 'perl.pm'; |
4633a7c4 |
34 | |
7a315204 |
35 | if ($ENV{PERL_3LOG}) { # Tru64 third(1) tool, see perlhack |
09187cb1 |
36 | unless (-x 'perl.third') { |
37 | unless (-x '../perl.third') { |
38 | die "You need to run \"make perl.third first.\n"; |
39 | } |
40 | else { |
41 | print "Symlinking ../perl.third as perl.third...\n"; |
42 | die "Failed to symlink: $!\n" |
43 | unless symlink("../perl.third", "perl.third"); |
44 | die "Symlinked but no executable perl.third: $!\n" |
45 | unless -x 'perl.third'; |
46 | } |
47 | } |
48 | } |
49 | |
3fb91a5e |
50 | # check leakage for embedders |
51 | $ENV{PERL_DESTRUCT_LEVEL} = 2 unless exists $ENV{PERL_DESTRUCT_LEVEL}; |
52 | |
4633a7c4 |
53 | $ENV{EMXSHELL} = 'sh'; # For OS/2 |
748a9306 |
54 | |
24c841ba |
55 | # Roll your own File::Find! |
56 | use TestInit; |
57 | use File::Spec; |
58 | my $curdir = File::Spec->curdir; |
59 | my $updir = File::Spec->updir; |
60 | |
61 | sub _find_tests { |
62 | my($dir) = @_; |
63 | opendir DIR, $dir || die "Trouble opening $dir: $!"; |
a1886d87 |
64 | foreach my $f (sort { $a cmp $b } readdir DIR) { |
24c841ba |
65 | next if $f eq $curdir or $f eq $updir; |
66 | |
67 | my $fullpath = File::Spec->catdir($dir, $f); |
68 | |
69 | _find_tests($fullpath) if -d $fullpath; |
70 | push @ARGV, $fullpath if $f =~ /\.t$/; |
71 | } |
72 | } |
73 | |
74 | unless (@ARGV) { |
9f3d340b |
75 | foreach my $dir (qw(base comp cmd run io op uni)) { |
24c841ba |
76 | _find_tests($dir); |
77 | } |
5a6e071d |
78 | _find_tests("lib") unless $core; |
7a315204 |
79 | my $mani = File::Spec->catdir($updir, "MANIFEST"); |
80 | if (open(MANI, $mani)) { |
80ffb5f9 |
81 | while (<MANI>) { # similar code in t/harness |
5157cb1b |
82 | if (m!^(ext/\S+/?([^/]+\.t|test\.pl)|lib/\S+?(\.t|test\.pl))\s!) { |
5a6e071d |
83 | $t = $1; |
84 | if (!$core || $t =~ m!^lib/[a-z]!) |
85 | { |
73ddec28 |
86 | $path = File::Spec->catdir($updir, $t); |
87 | push @ARGV, $path; |
88 | $name{$path} = $t; |
5a6e071d |
89 | } |
7a315204 |
90 | } |
91 | } |
92 | } else { |
93 | warn "$0: cannot open $mani: $!\n"; |
94 | } |
b695f709 |
95 | _find_tests('pod'); |
939256b9 |
96 | _find_tests('x2p'); |
8d063cd8 |
97 | } |
98 | |
7a315204 |
99 | # Tests known to cause infinite loops for the perlcc tests. |
595ae481 |
100 | # %infinite = ( 'comp/require.t', 1, 'op/bop.t', 1, 'lib/hostname.t', 1 ); |
24c841ba |
101 | %infinite = (); |
6ee623d5 |
102 | |
485988ae |
103 | if ($deparse) { |
f193aa2f |
104 | _testprogs('deparse', '', @ARGV); |
105 | } |
106 | elsif( $compile || $byte_compile ) { |
107 | _testprogs('compile', '', @ARGV) if $compile; |
108 | _testprogs('compile', '-B', @ARGV) if $byte_compile; |
109 | } |
110 | else { |
111 | _testprogs('compile', '', @ARGV) if -e "../testcompile"; |
112 | _testprogs('perl', '', @ARGV); |
485988ae |
113 | } |
6ee623d5 |
114 | |
bb365837 |
115 | sub _testprogs { |
116 | $type = shift @_; |
f193aa2f |
117 | $args = shift; |
bb365837 |
118 | @tests = @_; |
6ee623d5 |
119 | |
bb365837 |
120 | print <<'EOT' if ($type eq 'compile'); |
7a315204 |
121 | ------------------------------------------------------------------------------ |
6ee623d5 |
122 | TESTING COMPILER |
7a315204 |
123 | ------------------------------------------------------------------------------ |
bb365837 |
124 | EOT |
125 | |
485988ae |
126 | print <<'EOT' if ($type eq 'deparse'); |
7a315204 |
127 | ------------------------------------------------------------------------------ |
485988ae |
128 | TESTING DEPARSER |
7a315204 |
129 | ------------------------------------------------------------------------------ |
485988ae |
130 | EOT |
131 | |
595ae481 |
132 | $ENV{PERLCC_TIMEOUT} = 120 |
9636a016 |
133 | if ($type eq 'compile' && !$ENV{PERLCC_TIMEOUT}); |
ef712cf7 |
134 | |
bb365837 |
135 | $bad = 0; |
136 | $good = 0; |
137 | $total = @tests; |
138 | $files = 0; |
139 | $totmax = 0; |
73ddec28 |
140 | |
141 | foreach (@tests) { |
142 | $name{$_} = File::Spec->catdir('t',$_) unless exists $name{$_}; |
143 | } |
908801fe |
144 | my $maxlen = 0; |
73ddec28 |
145 | foreach (@name{@tests}) { |
146 | s/\.\w+\z/./; |
147 | my $len = length ; |
148 | $maxlen = $len if $len > $maxlen; |
088b5126 |
149 | } |
908801fe |
150 | # + 3 : we want three dots between the test name and the "ok" |
73ddec28 |
151 | $dotdotdot = $maxlen + 3 ; |
bb365837 |
152 | while ($test = shift @tests) { |
153 | |
154 | if ( $infinite{$test} && $type eq 'compile' ) { |
595ae481 |
155 | print STDERR "$test creates infinite loop! Skipping.\n"; |
bb365837 |
156 | next; |
6ee623d5 |
157 | } |
bb365837 |
158 | if ($test =~ /^$/) { |
159 | next; |
6ee623d5 |
160 | } |
485988ae |
161 | if ($type eq 'deparse') { |
162 | if ($test eq "comp/redef.t") { |
163 | # Redefinition happens at compile time |
164 | next; |
165 | } |
166 | elsif ($test eq "lib/switch.t") { |
167 | # B::Deparse doesn't support source filtering |
168 | next; |
169 | } |
170 | } |
73ddec28 |
171 | $te = $name{$test}; |
088b5126 |
172 | print "$te" . '.' x ($dotdotdot - length($te)); |
bb365837 |
173 | |
7a315204 |
174 | $test = $OVER{$test} if exists $OVER{$test}; |
175 | |
2f6bec1d |
176 | open(SCRIPT,"<$test") or die "Can't run $test.\n"; |
177 | $_ = <SCRIPT>; |
178 | close(SCRIPT) unless ($type eq 'deparse'); |
6537fe72 |
179 | if (/#!.*\bperl.*-\w*([tT])/) { |
180 | $switch = qq{"-$1"}; |
2f6bec1d |
181 | } |
182 | else { |
183 | $switch = ''; |
184 | } |
6ee623d5 |
185 | |
b326da91 |
186 | my $test_executable; # for 'compile' tests |
485988ae |
187 | my $file_opts = ""; |
188 | if ($type eq 'deparse') { |
189 | # Look for #line directives which change the filename |
190 | while (<SCRIPT>) { |
191 | $file_opts .= ",-f$3$4" |
192 | if /^#\s*line\s+(\d+)\s+((\w+)|"([^"]+)")/; |
193 | } |
194 | close(SCRIPT); |
195 | } |
7a315204 |
196 | |
7a315204 |
197 | my $utf = $with_utf ? '-I../lib -Mutf8' : ''; |
4343e7c3 |
198 | my $testswitch = '-I. -MTestInit'; # -T will strict . from @INC |
485988ae |
199 | if ($type eq 'deparse') { |
200 | my $deparse = |
201 | "./perl $testswitch $switch -I../lib -MO=-qq,Deparse,". |
202 | "-l$deparse_opts$file_opts ". |
7a315204 |
203 | "$test > $test.dp ". |
204 | "&& ./perl $testswitch $switch -I../lib $test.dp |"; |
485988ae |
205 | open(RESULTS, $deparse) |
206 | or print "can't deparse '$deparse': $!.\n"; |
207 | } |
208 | elsif ($type eq 'perl') { |
a7da9a42 |
209 | my $perl = $ENV{PERL} || './perl'; |
210 | my $run = "$perl $testswitch $switch $utf $test |"; |
be24517c |
211 | open(RESULTS,$run) or print "can't run '$run': $!.\n"; |
d638aca2 |
212 | } |
213 | else { |
b326da91 |
214 | my $compile; |
215 | my $pl2c = "$testswitch -I../lib ../utils/perlcc --testsuite " . |
9d2bbe64 |
216 | # -O9 for good measure, -fcog is broken ATM |
217 | "$switch -Wb=-O9,-fno-cog -L .. " . |
b326da91 |
218 | "-I \".. ../lib/CORE\" $args $utf $test -o "; |
219 | |
220 | if( $^O eq 'MSWin32' ) { |
221 | $test_executable = "$test.exe"; |
222 | # hopefully unused name... |
223 | open HACK, "> xweghyz.pl"; |
224 | print HACK <<EOT; |
225 | #!./perl |
226 | |
227 | open HACK, '.\\perl $pl2c $test_executable |'; |
228 | # cl.exe prints the name of the .c file on stdout (\%^\$^#) |
229 | while(<HACK>) {m/^\w+\.[cC]\$/ && next;print} |
230 | open HACK, '$test_executable |'; |
231 | while(<HACK>) {print} |
232 | EOT |
233 | close HACK; |
234 | $compile = 'xweghyz.pl |'; |
235 | } |
236 | else { |
237 | $test_executable = "$test.plc"; |
238 | $compile = "./perl $pl2c $test_executable && $test_executable |"; |
239 | } |
240 | unlink $test_executable if -f $test_executable; |
be24517c |
241 | open(RESULTS, $compile) |
242 | or print "can't compile '$compile': $!.\n"; |
6ee623d5 |
243 | } |
d638aca2 |
244 | |
b326da91 |
245 | $ok = 0; |
246 | $next = 0; |
bb365837 |
247 | while (<RESULTS>) { |
248 | if ($verbose) { |
249 | print $_; |
250 | } |
251 | unless (/^#/) { |
809908f7 |
252 | if (/^1\.\.([0-9]+)( todo ([\d ]+))?/) { |
bb365837 |
253 | $max = $1; |
809908f7 |
254 | %todo = map { $_ => 1 } split / /, $3 if $3; |
bb365837 |
255 | $totmax += $max; |
256 | $files += 1; |
257 | $next = 1; |
258 | $ok = 1; |
259 | } |
260 | else { |
2fe373ce |
261 | if (/^(not )?ok (\d+)[^#]*(\s*#.*)?/ && |
595ae481 |
262 | $2 == $next) |
37ce32a7 |
263 | { |
264 | my($not, $num, $extra) = ($1, $2, $3); |
265 | my($istodo) = $extra =~ /^\s*#\s*TODO/ if $extra; |
809908f7 |
266 | $istodo = 1 if $todo{$num}; |
37ce32a7 |
267 | |
268 | if( $not && !$istodo ) { |
269 | $ok = 0; |
270 | $next = $num; |
271 | last; |
272 | } |
273 | else { |
274 | $next = $next + 1; |
275 | } |
d667a7e6 |
276 | } |
277 | elsif (/^Bail out!\s*(.*)/i) { # magic words |
278 | die "FAILED--Further testing stopped" . ($1 ? ": $1\n" : ".\n"); |
bb365837 |
279 | } |
280 | else { |
281 | $ok = 0; |
282 | } |
8d063cd8 |
283 | } |
284 | } |
285 | } |
bb365837 |
286 | close RESULTS; |
485988ae |
287 | if ($type eq 'deparse') { |
288 | unlink "./$test.dp"; |
289 | } |
211f317f |
290 | if ($ENV{PERL_3LOG}) { |
291 | my $tpp = $test; |
a7da9a42 |
292 | $tpp =~ s:^../::; |
211f317f |
293 | $tpp =~ s:/:_:g; |
294 | $tpp =~ s:\.t$::; |
a7da9a42 |
295 | rename("perl.3log", "perl.3log.$tpp") || |
296 | die "rename: perl3.log to perl.3log.$tpp: $!\n"; |
211f317f |
297 | } |
bb365837 |
298 | $next = $next - 1; |
b326da91 |
299 | # test if the compiler compiled something |
300 | if( $type eq 'compile' && !-e "$test_executable" ) { |
301 | $ok = 0; |
302 | print "Test did not compile\n"; |
303 | } |
304 | if ($ok && $next == $max ) { |
bb365837 |
305 | if ($max) { |
306 | print "ok\n"; |
307 | $good = $good + 1; |
308 | } |
309 | else { |
310 | print "skipping test on this platform\n"; |
311 | $files -= 1; |
312 | } |
bcce72a7 |
313 | } |
bb365837 |
314 | else { |
315 | $next += 1; |
316 | print "FAILED at test $next\n"; |
317 | $bad = $bad + 1; |
318 | $_ = $test; |
319 | if (/^base/) { |
320 | die "Failed a basic test--cannot continue.\n"; |
321 | } |
8d063cd8 |
322 | } |
323 | } |
8d063cd8 |
324 | |
bb365837 |
325 | if ($bad == 0) { |
326 | if ($ok) { |
327 | print "All tests successful.\n"; |
328 | # XXX add mention of 'perlbug -ok' ? |
329 | } |
330 | else { |
331 | die "FAILED--no tests were run for some reason.\n"; |
332 | } |
8d063cd8 |
333 | } |
bb365837 |
334 | else { |
ba1398cf |
335 | $pct = $files ? sprintf("%.2f", ($files - $bad) / $files * 100) : "0.00"; |
bb365837 |
336 | if ($bad == 1) { |
e824fb2c |
337 | warn "Failed 1 test script out of $files, $pct% okay.\n"; |
bb365837 |
338 | } |
339 | else { |
e824fb2c |
340 | warn "Failed $bad test scripts out of $files, $pct% okay.\n"; |
bb365837 |
341 | } |
4e4732c1 |
342 | warn <<'SHRDLU_1'; |
f7d228c6 |
343 | ### Since not all tests were successful, you may want to run some of |
344 | ### them individually and examine any diagnostic messages they produce. |
345 | ### See the INSTALL document's section on "make test". |
4e4732c1 |
346 | SHRDLU_1 |
347 | warn <<'SHRDLU_2' if $good / $total > 0.8; |
f7d228c6 |
348 | ### You have a good chance to get more information by running |
349 | ### ./perl harness |
350 | ### in the 't' directory since most (>=80%) of the tests succeeded. |
4e4732c1 |
351 | SHRDLU_2 |
352 | if (eval {require Config; import Config; 1}) { |
e6af294e |
353 | if ($Config{usedl} && (my $p = $Config{ldlibpthname})) { |
4e4732c1 |
354 | warn <<SHRDLU_3; |
f7d228c6 |
355 | ### You may have to set your dynamic library search path, |
356 | ### $p, to point to the build directory: |
4e4732c1 |
357 | SHRDLU_3 |
358 | if (exists $ENV{$p} && $ENV{$p} ne '') { |
359 | warn <<SHRDLU_4a; |
f7d228c6 |
360 | ### setenv $p `pwd`:\$$p; cd t; ./perl harness |
361 | ### $p=`pwd`:\$$p; export $p; cd t; ./perl harness |
362 | ### export $p=`pwd`:\$$p; cd t; ./perl harness |
4e4732c1 |
363 | SHRDLU_4a |
364 | } else { |
365 | warn <<SHRDLU_4b; |
f7d228c6 |
366 | ### setenv $p `pwd`; cd t; ./perl harness |
367 | ### $p=`pwd`; export $p; cd t; ./perl harness |
368 | ### export $p=`pwd`; cd t; ./perl harness |
4e4732c1 |
369 | SHRDLU_4b |
370 | } |
371 | warn <<SHRDLU_5; |
f7d228c6 |
372 | ### for csh-style shells, like tcsh; or for traditional/modern |
373 | ### Bourne-style shells, like bash, ksh, and zsh, respectively. |
4e4732c1 |
374 | SHRDLU_5 |
375 | } |
afd33fa9 |
376 | } |
bb365837 |
377 | } |
378 | ($user,$sys,$cuser,$csys) = times; |
379 | print sprintf("u=%g s=%g cu=%g cs=%g scripts=%d tests=%d\n", |
380 | $user,$sys,$cuser,$csys,$files,$totmax); |
6ee623d5 |
381 | } |
3e6e8be7 |
382 | exit ($bad != 0); |