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