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 | { | |
73ddec28 RB |
79 | $path = File::Spec->catdir($updir, $t); |
80 | push @ARGV, $path; | |
81 | $name{$path} = $t; | |
5a6e071d | 82 | } |
7a315204 JH |
83 | } |
84 | } | |
85 | } else { | |
86 | warn "$0: cannot open $mani: $!\n"; | |
87 | } | |
b695f709 | 88 | _find_tests('pod'); |
8d063cd8 LW |
89 | } |
90 | ||
7a315204 | 91 | # Tests known to cause infinite loops for the perlcc tests. |
595ae481 | 92 | # %infinite = ( 'comp/require.t', 1, 'op/bop.t', 1, 'lib/hostname.t', 1 ); |
24c841ba | 93 | %infinite = (); |
6ee623d5 | 94 | |
485988ae RH |
95 | if ($deparse) { |
96 | _testprogs('deparse', @ARGV); | |
97 | } else { | |
98 | _testprogs('perl', @ARGV); | |
99 | _testprogs('compile', @ARGV) if (-e "../testcompile"); | |
100 | } | |
6ee623d5 | 101 | |
bb365837 GS |
102 | sub _testprogs { |
103 | $type = shift @_; | |
104 | @tests = @_; | |
6ee623d5 | 105 | |
bb365837 | 106 | print <<'EOT' if ($type eq 'compile'); |
7a315204 | 107 | ------------------------------------------------------------------------------ |
6ee623d5 | 108 | TESTING COMPILER |
7a315204 | 109 | ------------------------------------------------------------------------------ |
bb365837 GS |
110 | EOT |
111 | ||
485988ae | 112 | print <<'EOT' if ($type eq 'deparse'); |
7a315204 | 113 | ------------------------------------------------------------------------------ |
485988ae | 114 | TESTING DEPARSER |
7a315204 | 115 | ------------------------------------------------------------------------------ |
485988ae RH |
116 | EOT |
117 | ||
595ae481 | 118 | $ENV{PERLCC_TIMEOUT} = 120 |
9636a016 | 119 | if ($type eq 'compile' && !$ENV{PERLCC_TIMEOUT}); |
ef712cf7 | 120 | |
bb365837 GS |
121 | $bad = 0; |
122 | $good = 0; | |
123 | $total = @tests; | |
124 | $files = 0; | |
125 | $totmax = 0; | |
73ddec28 RB |
126 | |
127 | foreach (@tests) { | |
128 | $name{$_} = File::Spec->catdir('t',$_) unless exists $name{$_}; | |
129 | } | |
908801fe | 130 | my $maxlen = 0; |
73ddec28 RB |
131 | foreach (@name{@tests}) { |
132 | s/\.\w+\z/./; | |
133 | my $len = length ; | |
134 | $maxlen = $len if $len > $maxlen; | |
088b5126 | 135 | } |
908801fe | 136 | # + 3 : we want three dots between the test name and the "ok" |
73ddec28 | 137 | $dotdotdot = $maxlen + 3 ; |
bb365837 GS |
138 | while ($test = shift @tests) { |
139 | ||
140 | if ( $infinite{$test} && $type eq 'compile' ) { | |
595ae481 | 141 | print STDERR "$test creates infinite loop! Skipping.\n"; |
bb365837 | 142 | next; |
6ee623d5 | 143 | } |
bb365837 GS |
144 | if ($test =~ /^$/) { |
145 | next; | |
6ee623d5 | 146 | } |
485988ae RH |
147 | if ($type eq 'deparse') { |
148 | if ($test eq "comp/redef.t") { | |
149 | # Redefinition happens at compile time | |
150 | next; | |
151 | } | |
152 | elsif ($test eq "lib/switch.t") { | |
153 | # B::Deparse doesn't support source filtering | |
154 | next; | |
155 | } | |
156 | } | |
73ddec28 | 157 | $te = $name{$test}; |
088b5126 | 158 | print "$te" . '.' x ($dotdotdot - length($te)); |
bb365837 | 159 | |
7a315204 JH |
160 | $test = $OVER{$test} if exists $OVER{$test}; |
161 | ||
d638aca2 GS |
162 | open(SCRIPT,"<$test") or die "Can't run $test.\n"; |
163 | $_ = <SCRIPT>; | |
485988ae | 164 | close(SCRIPT) unless ($type eq 'deparse'); |
d638aca2 GS |
165 | if (/#!.*perl(.*)$/) { |
166 | $switch = $1; | |
167 | if ($^O eq 'VMS') { | |
168 | # Must protect uppercase switches with "" on command line | |
169 | $switch =~ s/-([A-Z]\S*)/"-$1"/g; | |
55497cff | 170 | } |
135863df | 171 | } |
bb365837 | 172 | else { |
d638aca2 GS |
173 | $switch = ''; |
174 | } | |
6ee623d5 | 175 | |
485988ae RH |
176 | my $file_opts = ""; |
177 | if ($type eq 'deparse') { | |
178 | # Look for #line directives which change the filename | |
179 | while (<SCRIPT>) { | |
180 | $file_opts .= ",-f$3$4" | |
181 | if /^#\s*line\s+(\d+)\s+((\w+)|"([^"]+)")/; | |
182 | } | |
183 | close(SCRIPT); | |
184 | } | |
7a315204 | 185 | |
7a315204 | 186 | my $utf = $with_utf ? '-I../lib -Mutf8' : ''; |
4343e7c3 | 187 | my $testswitch = '-I. -MTestInit'; # -T will strict . from @INC |
485988ae RH |
188 | if ($type eq 'deparse') { |
189 | my $deparse = | |
190 | "./perl $testswitch $switch -I../lib -MO=-qq,Deparse,". | |
191 | "-l$deparse_opts$file_opts ". | |
7a315204 JH |
192 | "$test > $test.dp ". |
193 | "&& ./perl $testswitch $switch -I../lib $test.dp |"; | |
485988ae RH |
194 | open(RESULTS, $deparse) |
195 | or print "can't deparse '$deparse': $!.\n"; | |
196 | } | |
197 | elsif ($type eq 'perl') { | |
a7da9a42 JH |
198 | my $perl = $ENV{PERL} || './perl'; |
199 | my $run = "$perl $testswitch $switch $utf $test |"; | |
be24517c | 200 | open(RESULTS,$run) or print "can't run '$run': $!.\n"; |
d638aca2 GS |
201 | } |
202 | else { | |
be24517c | 203 | my $compile = |
4343e7c3 | 204 | "./perl $testswitch -I../lib ../utils/perlcc -o ". |
7a315204 JH |
205 | "$test.plc $utf $test ". |
206 | " && $test.plc |"; | |
be24517c JH |
207 | open(RESULTS, $compile) |
208 | or print "can't compile '$compile': $!.\n"; | |
7a315204 | 209 | unlink "$test.plc"; |
6ee623d5 | 210 | } |
d638aca2 | 211 | |
bb365837 GS |
212 | $ok = 0; |
213 | $next = 0; | |
214 | while (<RESULTS>) { | |
215 | if ($verbose) { | |
216 | print $_; | |
217 | } | |
218 | unless (/^#/) { | |
809908f7 | 219 | if (/^1\.\.([0-9]+)( todo ([\d ]+))?/) { |
bb365837 | 220 | $max = $1; |
809908f7 | 221 | %todo = map { $_ => 1 } split / /, $3 if $3; |
bb365837 GS |
222 | $totmax += $max; |
223 | $files += 1; | |
224 | $next = 1; | |
225 | $ok = 1; | |
226 | } | |
227 | else { | |
2fe373ce | 228 | if (/^(not )?ok (\d+)[^#]*(\s*#.*)?/ && |
595ae481 | 229 | $2 == $next) |
37ce32a7 MS |
230 | { |
231 | my($not, $num, $extra) = ($1, $2, $3); | |
232 | my($istodo) = $extra =~ /^\s*#\s*TODO/ if $extra; | |
809908f7 | 233 | $istodo = 1 if $todo{$num}; |
37ce32a7 MS |
234 | |
235 | if( $not && !$istodo ) { | |
236 | $ok = 0; | |
237 | $next = $num; | |
238 | last; | |
239 | } | |
240 | else { | |
241 | $next = $next + 1; | |
242 | } | |
d667a7e6 A |
243 | } |
244 | elsif (/^Bail out!\s*(.*)/i) { # magic words | |
245 | die "FAILED--Further testing stopped" . ($1 ? ": $1\n" : ".\n"); | |
bb365837 GS |
246 | } |
247 | else { | |
248 | $ok = 0; | |
249 | } | |
8d063cd8 LW |
250 | } |
251 | } | |
252 | } | |
bb365837 | 253 | close RESULTS; |
485988ae RH |
254 | if ($type eq 'deparse') { |
255 | unlink "./$test.dp"; | |
256 | } | |
211f317f JH |
257 | if ($ENV{PERL_3LOG}) { |
258 | my $tpp = $test; | |
a7da9a42 | 259 | $tpp =~ s:^../::; |
211f317f JH |
260 | $tpp =~ s:/:_:g; |
261 | $tpp =~ s:\.t$::; | |
a7da9a42 JH |
262 | rename("perl.3log", "perl.3log.$tpp") || |
263 | die "rename: perl3.log to perl.3log.$tpp: $!\n"; | |
211f317f | 264 | } |
bb365837 GS |
265 | $next = $next - 1; |
266 | if ($ok && $next == $max) { | |
267 | if ($max) { | |
268 | print "ok\n"; | |
269 | $good = $good + 1; | |
270 | } | |
271 | else { | |
272 | print "skipping test on this platform\n"; | |
273 | $files -= 1; | |
274 | } | |
bcce72a7 | 275 | } |
bb365837 GS |
276 | else { |
277 | $next += 1; | |
278 | print "FAILED at test $next\n"; | |
279 | $bad = $bad + 1; | |
280 | $_ = $test; | |
281 | if (/^base/) { | |
282 | die "Failed a basic test--cannot continue.\n"; | |
283 | } | |
8d063cd8 LW |
284 | } |
285 | } | |
8d063cd8 | 286 | |
bb365837 GS |
287 | if ($bad == 0) { |
288 | if ($ok) { | |
289 | print "All tests successful.\n"; | |
290 | # XXX add mention of 'perlbug -ok' ? | |
291 | } | |
292 | else { | |
293 | die "FAILED--no tests were run for some reason.\n"; | |
294 | } | |
8d063cd8 | 295 | } |
bb365837 | 296 | else { |
ba1398cf | 297 | $pct = $files ? sprintf("%.2f", ($files - $bad) / $files * 100) : "0.00"; |
bb365837 | 298 | if ($bad == 1) { |
e824fb2c | 299 | warn "Failed 1 test script out of $files, $pct% okay.\n"; |
bb365837 GS |
300 | } |
301 | else { | |
e824fb2c | 302 | warn "Failed $bad test scripts out of $files, $pct% okay.\n"; |
bb365837 GS |
303 | } |
304 | warn <<'SHRDLU'; | |
f46c10df CS |
305 | ### Since not all tests were successful, you may want to run some |
306 | ### of them individually and examine any diagnostic messages they | |
307 | ### produce. See the INSTALL document's section on "make test". | |
595ae481 NIS |
308 | ### If you are testing the compiler, then ignore this message |
309 | ### and run | |
6ee623d5 GS |
310 | ### ./perl harness |
311 | ### in the directory ./t. | |
f46c10df | 312 | SHRDLU |
bb365837 | 313 | warn <<'SHRDLU' if $good / $total > 0.8; |
3e6e8be7 MB |
314 | ### |
315 | ### Since most tests were successful, you have a good chance to | |
316 | ### get information with better granularity by running | |
595ae481 | 317 | ### ./perl harness |
3e6e8be7 MB |
318 | ### in directory ./t. |
319 | SHRDLU | |
bb365837 GS |
320 | } |
321 | ($user,$sys,$cuser,$csys) = times; | |
322 | print sprintf("u=%g s=%g cu=%g cs=%g scripts=%d tests=%d\n", | |
323 | $user,$sys,$cuser,$csys,$files,$totmax); | |
6ee623d5 | 324 | } |
3e6e8be7 | 325 | exit ($bad != 0); |