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