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+)$/; |
5d9a6404 MS |
12 | $verbose = 1 if $1 eq 'v'; |
13 | $with_utf= 1 if $1 eq 'utf8'; | |
485988ae RH |
14 | if ($1 =~ /^deparse(,.+)?$/) { |
15 | $deparse = 1; | |
16 | $deparse_opts = $1; | |
17 | } | |
5d9a6404 MS |
18 | splice(@ARGV, $idx, 1); |
19 | } | |
8d063cd8 LW |
20 | } |
21 | ||
378cc40b LW |
22 | chdir 't' if -f 't/TEST'; |
23 | ||
3e6e8be7 | 24 | die "You need to run \"make test\" first to set things up.\n" |
4633a7c4 LW |
25 | unless -e 'perl' or -e 'perl.exe'; |
26 | ||
09187cb1 JH |
27 | if ($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 GS |
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 MS |
47 | |
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: $!"; | |
57 | foreach my $f (readdir DIR) { | |
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) { | |
68 | foreach my $dir (qw(base comp cmd run io op pragma lib pod)) { | |
69 | _find_tests($dir); | |
70 | } | |
8d063cd8 LW |
71 | } |
72 | ||
595ae481 | 73 | # %infinite = ( 'comp/require.t', 1, 'op/bop.t', 1, 'lib/hostname.t', 1 ); |
24c841ba | 74 | %infinite = (); |
6ee623d5 | 75 | |
485988ae RH |
76 | if ($deparse) { |
77 | _testprogs('deparse', @ARGV); | |
78 | } else { | |
79 | _testprogs('perl', @ARGV); | |
80 | _testprogs('compile', @ARGV) if (-e "../testcompile"); | |
81 | } | |
6ee623d5 | 82 | |
bb365837 GS |
83 | sub _testprogs { |
84 | $type = shift @_; | |
85 | @tests = @_; | |
6ee623d5 GS |
86 | |
87 | ||
bb365837 | 88 | print <<'EOT' if ($type eq 'compile'); |
6ee623d5 GS |
89 | -------------------------------------------------------------------------------- |
90 | TESTING COMPILER | |
91 | -------------------------------------------------------------------------------- | |
bb365837 GS |
92 | EOT |
93 | ||
485988ae RH |
94 | print <<'EOT' if ($type eq 'deparse'); |
95 | -------------------------------------------------------------------------------- | |
96 | TESTING DEPARSER | |
97 | -------------------------------------------------------------------------------- | |
98 | EOT | |
99 | ||
595ae481 | 100 | $ENV{PERLCC_TIMEOUT} = 120 |
9636a016 | 101 | if ($type eq 'compile' && !$ENV{PERLCC_TIMEOUT}); |
ef712cf7 | 102 | |
bb365837 GS |
103 | $bad = 0; |
104 | $good = 0; | |
105 | $total = @tests; | |
106 | $files = 0; | |
107 | $totmax = 0; | |
088b5126 GS |
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 GS |
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 GS |
122 | if ($test =~ /^$/) { |
123 | next; | |
6ee623d5 | 124 | } |
485988ae RH |
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 GS |
135 | $te = $test; |
136 | chop($te); | |
088b5126 | 137 | print "$te" . '.' x ($dotdotdot - length($te)); |
bb365837 | 138 | |
d638aca2 GS |
139 | open(SCRIPT,"<$test") or die "Can't run $test.\n"; |
140 | $_ = <SCRIPT>; | |
485988ae | 141 | close(SCRIPT) unless ($type eq 'deparse'); |
d638aca2 GS |
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 GS |
150 | $switch = ''; |
151 | } | |
6ee623d5 | 152 | |
485988ae RH |
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 MS |
162 | my $utf = $with_utf ? '-I../lib -Mutf8' |
163 | : ''; | |
4343e7c3 | 164 | my $testswitch = '-I. -MTestInit'; # -T will strict . from @INC |
485988ae RH |
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 GS |
177 | } |
178 | else { | |
be24517c | 179 | my $compile = |
4343e7c3 MS |
180 | "./perl $testswitch -I../lib ../utils/perlcc -o ". |
181 | "./$test.plc $utf ./$test ". | |
182 | " && ./$test.plc |"; | |
be24517c JH |
183 | open(RESULTS, $compile) |
184 | or print "can't compile '$compile': $!.\n"; | |
185 | unlink "./$test.plc"; | |
6ee623d5 | 186 | } |
d638aca2 | 187 | |
bb365837 GS |
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 GS |
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 MS |
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 MS |
210 | |
211 | if( $not && !$istodo ) { | |
212 | $ok = 0; | |
213 | $next = $num; | |
214 | last; | |
215 | } | |
216 | else { | |
217 | $next = $next + 1; | |
218 | } | |
d667a7e6 A |
219 | } |
220 | elsif (/^Bail out!\s*(.*)/i) { # magic words | |
221 | die "FAILED--Further testing stopped" . ($1 ? ": $1\n" : ".\n"); | |
bb365837 GS |
222 | } |
223 | else { | |
224 | $ok = 0; | |
225 | } | |
8d063cd8 LW |
226 | } |
227 | } | |
228 | } | |
bb365837 | 229 | close RESULTS; |
485988ae RH |
230 | if ($type eq 'deparse') { |
231 | unlink "./$test.dp"; | |
232 | } | |
211f317f JH |
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 GS |
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 GS |
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 LW |
258 | } |
259 | } | |
8d063cd8 | 260 | |
bb365837 GS |
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 GS |
274 | } |
275 | else { | |
e824fb2c | 276 | warn "Failed $bad test scripts out of $files, $pct% okay.\n"; |
bb365837 GS |
277 | } |
278 | warn <<'SHRDLU'; | |
f46c10df CS |
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 NIS |
282 | ### If you are testing the compiler, then ignore this message |
283 | ### and run | |
6ee623d5 GS |
284 | ### ./perl harness |
285 | ### in the directory ./t. | |
f46c10df | 286 | SHRDLU |
bb365837 | 287 | warn <<'SHRDLU' if $good / $total > 0.8; |
3e6e8be7 MB |
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 MB |
292 | ### in directory ./t. |
293 | SHRDLU | |
bb365837 GS |
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 | 299 | exit ($bad != 0); |