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) { |
11 | next unless $ARGV[$idx] =~ /^-(\w+)$/; |
12 | $verbose = 1 if $1 eq 'v'; |
13 | $with_utf= 1 if $1 eq 'utf8'; |
14 | splice(@ARGV, $idx, 1); |
15 | } |
8d063cd8 |
16 | } |
17 | |
378cc40b |
18 | chdir 't' if -f 't/TEST'; |
19 | |
3e6e8be7 |
20 | die "You need to run \"make test\" first to set things up.\n" |
4633a7c4 |
21 | unless -e 'perl' or -e 'perl.exe'; |
22 | |
09187cb1 |
23 | if ($ENV{PERL_3LOG}) { |
24 | unless (-x 'perl.third') { |
25 | unless (-x '../perl.third') { |
26 | die "You need to run \"make perl.third first.\n"; |
27 | } |
28 | else { |
29 | print "Symlinking ../perl.third as perl.third...\n"; |
30 | die "Failed to symlink: $!\n" |
31 | unless symlink("../perl.third", "perl.third"); |
32 | die "Symlinked but no executable perl.third: $!\n" |
33 | unless -x 'perl.third'; |
34 | } |
35 | } |
36 | } |
37 | |
3fb91a5e |
38 | # check leakage for embedders |
39 | $ENV{PERL_DESTRUCT_LEVEL} = 2 unless exists $ENV{PERL_DESTRUCT_LEVEL}; |
40 | |
4633a7c4 |
41 | $ENV{EMXSHELL} = 'sh'; # For OS/2 |
748a9306 |
42 | |
3e6e8be7 |
43 | if ($#ARGV == -1) { |
44 | @ARGV = split(/[ \n]/, |
595ae481 |
45 | `echo base/*.t comp/*.t cmd/*.t run/*.t io/*.t; echo op/*.t pragma/*.t lib/*.t pod/*.t camel-III/*.t`); |
8d063cd8 |
46 | } |
47 | |
595ae481 |
48 | # %infinite = ( 'comp/require.t', 1, 'op/bop.t', 1, 'lib/hostname.t', 1 ); |
6ee623d5 |
49 | |
50 | _testprogs('perl', @ARGV); |
595ae481 |
51 | _testprogs('compile', @ARGV) if (-e "../testcompile"); |
6ee623d5 |
52 | |
bb365837 |
53 | sub _testprogs { |
54 | $type = shift @_; |
55 | @tests = @_; |
6ee623d5 |
56 | |
57 | |
bb365837 |
58 | print <<'EOT' if ($type eq 'compile'); |
6ee623d5 |
59 | -------------------------------------------------------------------------------- |
60 | TESTING COMPILER |
61 | -------------------------------------------------------------------------------- |
bb365837 |
62 | EOT |
63 | |
595ae481 |
64 | $ENV{PERLCC_TIMEOUT} = 120 |
9636a016 |
65 | if ($type eq 'compile' && !$ENV{PERLCC_TIMEOUT}); |
ef712cf7 |
66 | |
bb365837 |
67 | $bad = 0; |
68 | $good = 0; |
69 | $total = @tests; |
70 | $files = 0; |
71 | $totmax = 0; |
088b5126 |
72 | $maxlen = 0; |
73 | foreach (@tests) { |
74 | $len = length; |
75 | $maxlen = $len if $len > $maxlen; |
76 | } |
77 | # +3 : we want three dots between the test name and the "ok" |
78 | # -2 : the .t suffix |
79 | $dotdotdot = $maxlen + 3 - 2; |
bb365837 |
80 | while ($test = shift @tests) { |
81 | |
82 | if ( $infinite{$test} && $type eq 'compile' ) { |
595ae481 |
83 | print STDERR "$test creates infinite loop! Skipping.\n"; |
bb365837 |
84 | next; |
6ee623d5 |
85 | } |
bb365837 |
86 | if ($test =~ /^$/) { |
87 | next; |
6ee623d5 |
88 | } |
bb365837 |
89 | $te = $test; |
90 | chop($te); |
088b5126 |
91 | print "$te" . '.' x ($dotdotdot - length($te)); |
bb365837 |
92 | |
d638aca2 |
93 | open(SCRIPT,"<$test") or die "Can't run $test.\n"; |
94 | $_ = <SCRIPT>; |
95 | close(SCRIPT); |
96 | if (/#!.*perl(.*)$/) { |
97 | $switch = $1; |
98 | if ($^O eq 'VMS') { |
99 | # Must protect uppercase switches with "" on command line |
100 | $switch =~ s/-([A-Z]\S*)/"-$1"/g; |
55497cff |
101 | } |
135863df |
102 | } |
bb365837 |
103 | else { |
d638aca2 |
104 | $switch = ''; |
105 | } |
6ee623d5 |
106 | |
5d9a6404 |
107 | my $utf = $with_utf ? '-I../lib -Mutf8' |
108 | : ''; |
4343e7c3 |
109 | my $testswitch = '-I. -MTestInit'; # -T will strict . from @INC |
d638aca2 |
110 | if ($type eq 'perl') { |
595ae481 |
111 | my $run = "./perl $testswitch $switch $utf $test |"; |
be24517c |
112 | open(RESULTS,$run) or print "can't run '$run': $!.\n"; |
d638aca2 |
113 | } |
114 | else { |
be24517c |
115 | my $compile = |
4343e7c3 |
116 | "./perl $testswitch -I../lib ../utils/perlcc -o ". |
117 | "./$test.plc $utf ./$test ". |
118 | " && ./$test.plc |"; |
be24517c |
119 | open(RESULTS, $compile) |
120 | or print "can't compile '$compile': $!.\n"; |
121 | unlink "./$test.plc"; |
6ee623d5 |
122 | } |
d638aca2 |
123 | |
bb365837 |
124 | $ok = 0; |
125 | $next = 0; |
126 | while (<RESULTS>) { |
127 | if ($verbose) { |
128 | print $_; |
129 | } |
130 | unless (/^#/) { |
131 | if (/^1\.\.([0-9]+)/) { |
132 | $max = $1; |
133 | $totmax += $max; |
134 | $files += 1; |
135 | $next = 1; |
136 | $ok = 1; |
137 | } |
138 | else { |
37ce32a7 |
139 | if (/^(not )?ok (\d+)(\s*#.*)?/ && |
595ae481 |
140 | $2 == $next) |
37ce32a7 |
141 | { |
142 | my($not, $num, $extra) = ($1, $2, $3); |
143 | my($istodo) = $extra =~ /^\s*#\s*TODO/ if $extra; |
144 | |
145 | if( $not && !$istodo ) { |
146 | $ok = 0; |
147 | $next = $num; |
148 | last; |
149 | } |
150 | else { |
151 | $next = $next + 1; |
152 | } |
d667a7e6 |
153 | } |
154 | elsif (/^Bail out!\s*(.*)/i) { # magic words |
155 | die "FAILED--Further testing stopped" . ($1 ? ": $1\n" : ".\n"); |
bb365837 |
156 | } |
157 | else { |
158 | $ok = 0; |
159 | } |
8d063cd8 |
160 | } |
161 | } |
162 | } |
bb365837 |
163 | close RESULTS; |
211f317f |
164 | if ($ENV{PERL_3LOG}) { |
165 | my $tpp = $test; |
166 | $tpp =~ s:/:_:g; |
167 | $tpp =~ s:\.t$::; |
168 | rename("perl.3log", "perl.3log.$tpp"); |
169 | } |
bb365837 |
170 | $next = $next - 1; |
171 | if ($ok && $next == $max) { |
172 | if ($max) { |
173 | print "ok\n"; |
174 | $good = $good + 1; |
175 | } |
176 | else { |
177 | print "skipping test on this platform\n"; |
178 | $files -= 1; |
179 | } |
bcce72a7 |
180 | } |
bb365837 |
181 | else { |
182 | $next += 1; |
183 | print "FAILED at test $next\n"; |
184 | $bad = $bad + 1; |
185 | $_ = $test; |
186 | if (/^base/) { |
187 | die "Failed a basic test--cannot continue.\n"; |
188 | } |
8d063cd8 |
189 | } |
190 | } |
8d063cd8 |
191 | |
bb365837 |
192 | if ($bad == 0) { |
193 | if ($ok) { |
194 | print "All tests successful.\n"; |
195 | # XXX add mention of 'perlbug -ok' ? |
196 | } |
197 | else { |
198 | die "FAILED--no tests were run for some reason.\n"; |
199 | } |
8d063cd8 |
200 | } |
bb365837 |
201 | else { |
ba1398cf |
202 | $pct = $files ? sprintf("%.2f", ($files - $bad) / $files * 100) : "0.00"; |
bb365837 |
203 | if ($bad == 1) { |
e824fb2c |
204 | warn "Failed 1 test script out of $files, $pct% okay.\n"; |
bb365837 |
205 | } |
206 | else { |
e824fb2c |
207 | warn "Failed $bad test scripts out of $files, $pct% okay.\n"; |
bb365837 |
208 | } |
209 | warn <<'SHRDLU'; |
f46c10df |
210 | ### Since not all tests were successful, you may want to run some |
211 | ### of them individually and examine any diagnostic messages they |
212 | ### produce. See the INSTALL document's section on "make test". |
595ae481 |
213 | ### If you are testing the compiler, then ignore this message |
214 | ### and run |
6ee623d5 |
215 | ### ./perl harness |
216 | ### in the directory ./t. |
f46c10df |
217 | SHRDLU |
bb365837 |
218 | warn <<'SHRDLU' if $good / $total > 0.8; |
3e6e8be7 |
219 | ### |
220 | ### Since most tests were successful, you have a good chance to |
221 | ### get information with better granularity by running |
595ae481 |
222 | ### ./perl harness |
3e6e8be7 |
223 | ### in directory ./t. |
224 | SHRDLU |
bb365837 |
225 | } |
226 | ($user,$sys,$cuser,$csys) = times; |
227 | print sprintf("u=%g s=%g cu=%g cs=%g scripts=%d tests=%d\n", |
228 | $user,$sys,$cuser,$csys,$files,$totmax); |
6ee623d5 |
229 | } |
3e6e8be7 |
230 | exit ($bad != 0); |