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 | } |
35d88760 |
92 | close MANI; |
7a315204 |
93 | } else { |
94 | warn "$0: cannot open $mani: $!\n"; |
95 | } |
6990bd83 |
96 | _find_tests('pod') unless $core; |
97 | _find_tests('x2p') unless $core; |
98 | _find_tests('japh') unless $core; |
8d063cd8 |
99 | } |
100 | |
7a315204 |
101 | # Tests known to cause infinite loops for the perlcc tests. |
595ae481 |
102 | # %infinite = ( 'comp/require.t', 1, 'op/bop.t', 1, 'lib/hostname.t', 1 ); |
24c841ba |
103 | %infinite = (); |
6ee623d5 |
104 | |
485988ae |
105 | if ($deparse) { |
f193aa2f |
106 | _testprogs('deparse', '', @ARGV); |
107 | } |
108 | elsif( $compile || $byte_compile ) { |
109 | _testprogs('compile', '', @ARGV) if $compile; |
110 | _testprogs('compile', '-B', @ARGV) if $byte_compile; |
111 | } |
112 | else { |
113 | _testprogs('compile', '', @ARGV) if -e "../testcompile"; |
114 | _testprogs('perl', '', @ARGV); |
485988ae |
115 | } |
6ee623d5 |
116 | |
bb365837 |
117 | sub _testprogs { |
118 | $type = shift @_; |
f193aa2f |
119 | $args = shift; |
bb365837 |
120 | @tests = @_; |
6ee623d5 |
121 | |
bb365837 |
122 | print <<'EOT' if ($type eq 'compile'); |
7a315204 |
123 | ------------------------------------------------------------------------------ |
6ee623d5 |
124 | TESTING COMPILER |
7a315204 |
125 | ------------------------------------------------------------------------------ |
bb365837 |
126 | EOT |
127 | |
485988ae |
128 | print <<'EOT' if ($type eq 'deparse'); |
7a315204 |
129 | ------------------------------------------------------------------------------ |
485988ae |
130 | TESTING DEPARSER |
7a315204 |
131 | ------------------------------------------------------------------------------ |
485988ae |
132 | EOT |
133 | |
595ae481 |
134 | $ENV{PERLCC_TIMEOUT} = 120 |
9636a016 |
135 | if ($type eq 'compile' && !$ENV{PERLCC_TIMEOUT}); |
ef712cf7 |
136 | |
bb365837 |
137 | $bad = 0; |
138 | $good = 0; |
139 | $total = @tests; |
140 | $files = 0; |
141 | $totmax = 0; |
73ddec28 |
142 | |
143 | foreach (@tests) { |
144 | $name{$_} = File::Spec->catdir('t',$_) unless exists $name{$_}; |
145 | } |
908801fe |
146 | my $maxlen = 0; |
73ddec28 |
147 | foreach (@name{@tests}) { |
148 | s/\.\w+\z/./; |
149 | my $len = length ; |
150 | $maxlen = $len if $len > $maxlen; |
088b5126 |
151 | } |
908801fe |
152 | # + 3 : we want three dots between the test name and the "ok" |
73ddec28 |
153 | $dotdotdot = $maxlen + 3 ; |
bb365837 |
154 | while ($test = shift @tests) { |
155 | |
156 | if ( $infinite{$test} && $type eq 'compile' ) { |
595ae481 |
157 | print STDERR "$test creates infinite loop! Skipping.\n"; |
bb365837 |
158 | next; |
6ee623d5 |
159 | } |
bb365837 |
160 | if ($test =~ /^$/) { |
161 | next; |
6ee623d5 |
162 | } |
485988ae |
163 | if ($type eq 'deparse') { |
164 | if ($test eq "comp/redef.t") { |
165 | # Redefinition happens at compile time |
166 | next; |
167 | } |
168 | elsif ($test eq "lib/switch.t") { |
169 | # B::Deparse doesn't support source filtering |
170 | next; |
171 | } |
172 | } |
73ddec28 |
173 | $te = $name{$test}; |
088b5126 |
174 | print "$te" . '.' x ($dotdotdot - length($te)); |
bb365837 |
175 | |
7a315204 |
176 | $test = $OVER{$test} if exists $OVER{$test}; |
177 | |
2f6bec1d |
178 | open(SCRIPT,"<$test") or die "Can't run $test.\n"; |
179 | $_ = <SCRIPT>; |
180 | close(SCRIPT) unless ($type eq 'deparse'); |
6537fe72 |
181 | if (/#!.*\bperl.*-\w*([tT])/) { |
182 | $switch = qq{"-$1"}; |
2f6bec1d |
183 | } |
184 | else { |
185 | $switch = ''; |
186 | } |
6ee623d5 |
187 | |
b326da91 |
188 | my $test_executable; # for 'compile' tests |
485988ae |
189 | my $file_opts = ""; |
190 | if ($type eq 'deparse') { |
191 | # Look for #line directives which change the filename |
192 | while (<SCRIPT>) { |
193 | $file_opts .= ",-f$3$4" |
194 | if /^#\s*line\s+(\d+)\s+((\w+)|"([^"]+)")/; |
195 | } |
196 | close(SCRIPT); |
197 | } |
7a315204 |
198 | |
7a315204 |
199 | my $utf = $with_utf ? '-I../lib -Mutf8' : ''; |
4343e7c3 |
200 | my $testswitch = '-I. -MTestInit'; # -T will strict . from @INC |
485988ae |
201 | if ($type eq 'deparse') { |
202 | my $deparse = |
203 | "./perl $testswitch $switch -I../lib -MO=-qq,Deparse,". |
204 | "-l$deparse_opts$file_opts ". |
7a315204 |
205 | "$test > $test.dp ". |
206 | "&& ./perl $testswitch $switch -I../lib $test.dp |"; |
485988ae |
207 | open(RESULTS, $deparse) |
208 | or print "can't deparse '$deparse': $!.\n"; |
209 | } |
210 | elsif ($type eq 'perl') { |
a7da9a42 |
211 | my $perl = $ENV{PERL} || './perl'; |
212 | my $run = "$perl $testswitch $switch $utf $test |"; |
be24517c |
213 | open(RESULTS,$run) or print "can't run '$run': $!.\n"; |
d638aca2 |
214 | } |
215 | else { |
b326da91 |
216 | my $compile; |
217 | my $pl2c = "$testswitch -I../lib ../utils/perlcc --testsuite " . |
9d2bbe64 |
218 | # -O9 for good measure, -fcog is broken ATM |
219 | "$switch -Wb=-O9,-fno-cog -L .. " . |
b326da91 |
220 | "-I \".. ../lib/CORE\" $args $utf $test -o "; |
221 | |
222 | if( $^O eq 'MSWin32' ) { |
223 | $test_executable = "$test.exe"; |
224 | # hopefully unused name... |
225 | open HACK, "> xweghyz.pl"; |
226 | print HACK <<EOT; |
227 | #!./perl |
228 | |
229 | open HACK, '.\\perl $pl2c $test_executable |'; |
230 | # cl.exe prints the name of the .c file on stdout (\%^\$^#) |
231 | while(<HACK>) {m/^\w+\.[cC]\$/ && next;print} |
232 | open HACK, '$test_executable |'; |
233 | while(<HACK>) {print} |
234 | EOT |
235 | close HACK; |
236 | $compile = 'xweghyz.pl |'; |
237 | } |
238 | else { |
239 | $test_executable = "$test.plc"; |
240 | $compile = "./perl $pl2c $test_executable && $test_executable |"; |
241 | } |
242 | unlink $test_executable if -f $test_executable; |
be24517c |
243 | open(RESULTS, $compile) |
244 | or print "can't compile '$compile': $!.\n"; |
6ee623d5 |
245 | } |
d638aca2 |
246 | |
b326da91 |
247 | $ok = 0; |
248 | $next = 0; |
bb365837 |
249 | while (<RESULTS>) { |
250 | if ($verbose) { |
251 | print $_; |
252 | } |
253 | unless (/^#/) { |
809908f7 |
254 | if (/^1\.\.([0-9]+)( todo ([\d ]+))?/) { |
bb365837 |
255 | $max = $1; |
809908f7 |
256 | %todo = map { $_ => 1 } split / /, $3 if $3; |
bb365837 |
257 | $totmax += $max; |
258 | $files += 1; |
259 | $next = 1; |
260 | $ok = 1; |
261 | } |
262 | else { |
2fe373ce |
263 | if (/^(not )?ok (\d+)[^#]*(\s*#.*)?/ && |
595ae481 |
264 | $2 == $next) |
37ce32a7 |
265 | { |
266 | my($not, $num, $extra) = ($1, $2, $3); |
267 | my($istodo) = $extra =~ /^\s*#\s*TODO/ if $extra; |
809908f7 |
268 | $istodo = 1 if $todo{$num}; |
37ce32a7 |
269 | |
270 | if( $not && !$istodo ) { |
271 | $ok = 0; |
272 | $next = $num; |
273 | last; |
274 | } |
275 | else { |
276 | $next = $next + 1; |
277 | } |
d667a7e6 |
278 | } |
279 | elsif (/^Bail out!\s*(.*)/i) { # magic words |
280 | die "FAILED--Further testing stopped" . ($1 ? ": $1\n" : ".\n"); |
bb365837 |
281 | } |
282 | else { |
283 | $ok = 0; |
284 | } |
8d063cd8 |
285 | } |
286 | } |
287 | } |
bb365837 |
288 | close RESULTS; |
485988ae |
289 | if ($type eq 'deparse') { |
290 | unlink "./$test.dp"; |
291 | } |
211f317f |
292 | if ($ENV{PERL_3LOG}) { |
293 | my $tpp = $test; |
a7da9a42 |
294 | $tpp =~ s:^../::; |
211f317f |
295 | $tpp =~ s:/:_:g; |
296 | $tpp =~ s:\.t$::; |
a7da9a42 |
297 | rename("perl.3log", "perl.3log.$tpp") || |
298 | die "rename: perl3.log to perl.3log.$tpp: $!\n"; |
211f317f |
299 | } |
bb365837 |
300 | $next = $next - 1; |
b326da91 |
301 | # test if the compiler compiled something |
302 | if( $type eq 'compile' && !-e "$test_executable" ) { |
303 | $ok = 0; |
304 | print "Test did not compile\n"; |
305 | } |
306 | if ($ok && $next == $max ) { |
bb365837 |
307 | if ($max) { |
308 | print "ok\n"; |
309 | $good = $good + 1; |
310 | } |
311 | else { |
312 | print "skipping test on this platform\n"; |
313 | $files -= 1; |
314 | } |
bcce72a7 |
315 | } |
bb365837 |
316 | else { |
317 | $next += 1; |
318 | print "FAILED at test $next\n"; |
319 | $bad = $bad + 1; |
320 | $_ = $test; |
321 | if (/^base/) { |
322 | die "Failed a basic test--cannot continue.\n"; |
323 | } |
8d063cd8 |
324 | } |
325 | } |
8d063cd8 |
326 | |
bb365837 |
327 | if ($bad == 0) { |
328 | if ($ok) { |
329 | print "All tests successful.\n"; |
330 | # XXX add mention of 'perlbug -ok' ? |
331 | } |
332 | else { |
333 | die "FAILED--no tests were run for some reason.\n"; |
334 | } |
8d063cd8 |
335 | } |
bb365837 |
336 | else { |
ba1398cf |
337 | $pct = $files ? sprintf("%.2f", ($files - $bad) / $files * 100) : "0.00"; |
bb365837 |
338 | if ($bad == 1) { |
e824fb2c |
339 | warn "Failed 1 test script out of $files, $pct% okay.\n"; |
bb365837 |
340 | } |
341 | else { |
e824fb2c |
342 | warn "Failed $bad test scripts out of $files, $pct% okay.\n"; |
bb365837 |
343 | } |
4e4732c1 |
344 | warn <<'SHRDLU_1'; |
f7d228c6 |
345 | ### Since not all tests were successful, you may want to run some of |
346 | ### them individually and examine any diagnostic messages they produce. |
347 | ### See the INSTALL document's section on "make test". |
4e4732c1 |
348 | SHRDLU_1 |
349 | warn <<'SHRDLU_2' if $good / $total > 0.8; |
f7d228c6 |
350 | ### You have a good chance to get more information by running |
351 | ### ./perl harness |
352 | ### in the 't' directory since most (>=80%) of the tests succeeded. |
4e4732c1 |
353 | SHRDLU_2 |
354 | if (eval {require Config; import Config; 1}) { |
e6af294e |
355 | if ($Config{usedl} && (my $p = $Config{ldlibpthname})) { |
4e4732c1 |
356 | warn <<SHRDLU_3; |
f7d228c6 |
357 | ### You may have to set your dynamic library search path, |
358 | ### $p, to point to the build directory: |
4e4732c1 |
359 | SHRDLU_3 |
360 | if (exists $ENV{$p} && $ENV{$p} ne '') { |
361 | warn <<SHRDLU_4a; |
f7d228c6 |
362 | ### setenv $p `pwd`:\$$p; cd t; ./perl harness |
363 | ### $p=`pwd`:\$$p; export $p; cd t; ./perl harness |
364 | ### export $p=`pwd`:\$$p; cd t; ./perl harness |
4e4732c1 |
365 | SHRDLU_4a |
366 | } else { |
367 | warn <<SHRDLU_4b; |
f7d228c6 |
368 | ### setenv $p `pwd`; cd t; ./perl harness |
369 | ### $p=`pwd`; export $p; cd t; ./perl harness |
370 | ### export $p=`pwd`; cd t; ./perl harness |
4e4732c1 |
371 | SHRDLU_4b |
372 | } |
373 | warn <<SHRDLU_5; |
f7d228c6 |
374 | ### for csh-style shells, like tcsh; or for traditional/modern |
375 | ### Bourne-style shells, like bash, ksh, and zsh, respectively. |
4e4732c1 |
376 | SHRDLU_5 |
377 | } |
afd33fa9 |
378 | } |
bb365837 |
379 | } |
380 | ($user,$sys,$cuser,$csys) = times; |
381 | print sprintf("u=%g s=%g cu=%g cs=%g scripts=%d tests=%d\n", |
382 | $user,$sys,$cuser,$csys,$files,$totmax); |
6ee623d5 |
383 | } |
3e6e8be7 |
384 | exit ($bad != 0); |