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