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