Integrate mainline
[p5sagit/p5-mst-13.2.git] / t / UTEST
CommitLineData
a0ed51b3 1#!./perl
2
3# Last change: Fri Jan 10 09:57:03 WET 1997
4
5# This is written in a peculiar style, since we're trying to avoid
6# most of the constructs we'll be testing for.
7
8$| = 1;
9
10if ($#ARGV >= 0 && $ARGV[0] eq '-v') {
11 $verbose = 1;
12 shift;
13}
14
15chdir 't' if -f 't/TEST';
16
17die "You need to run \"make test\" first to set things up.\n"
18 unless -e 'perl' or -e 'perl.exe';
19
20#$ENV{PERL_DESTRUCT_LEVEL} = '2';
21$ENV{EMXSHELL} = 'sh'; # For OS/2
22
23if ($#ARGV == -1) {
24 @ARGV = split(/[ \n]/,
25 `echo base/*.t comp/*.t cmd/*.t io/*.t; echo op/*.t pragma/*.t lib/*.t`);
26}
27
28if ($^O eq 'os2' || $^O eq 'qnx') {
29 $sharpbang = 0;
30}
31else {
32 open(CONFIG, "../config.sh");
33 while (<CONFIG>) {
34 if (/sharpbang='(.*)'/) {
35 $sharpbang = ($1 eq '#!');
36 last;
37 }
38 }
39 close(CONFIG);
40}
41
42%infinite = ( 'comp/require.t', 1, 'op/bop.t', 1, 'lib/hostname.t', 1 );
43
44_testprogs('perl', @ARGV);
45_testprogs('compile', @ARGV) if (-e "../testcompile");
46
47sub _testprogs {
48 $type = shift @_;
49 @tests = @_;
50
51
52 print <<'EOT' if ($type eq 'compile');
53--------------------------------------------------------------------------------
54TESTING COMPILER
55--------------------------------------------------------------------------------
56EOT
57
9636a016 58 $ENV{PERLCC_TIMEOUT} = 120
59 if ($type eq 'compile' && !$ENV{PERLCC_TIMEOUT});
ef712cf7 60
a0ed51b3 61 $bad = 0;
62 $good = 0;
63 $total = @tests;
64 $files = 0;
65 $totmax = 0;
66 while ($test = shift @tests) {
67
68 if ( $infinite{$test} && $type eq 'compile' ) {
69 print STDERR "$test creates infinite loop! Skipping.\n";
70 next;
71 }
72 if ($test =~ /^$/) {
73 next;
74 }
75 $te = $test;
76 chop($te);
77 print "$te" . '.' x (18 - length($te));
78 if (0) {
79 -x $test || (print "isn't executable.\n");
80
81 if ($type eq 'perl') {
3e2f796a 82 my $run = "./$test |";
83 open(RESULTS, $run) || (print "can't run '$run': $!\n");
84 }
a0ed51b3 85 else {
3e2f796a 86 my $compile =
87 "./perl -I../lib ../utils/perlcc -o ./$test.plc ./$test "
88 ." && ./$test.plc |";
89 open(RESULTS, $compile)
90 or print "can't compile '$compile': $!.\n";
91 unlink "./$test.plc";
a0ed51b3 92 }
93 }
94 else {
95 open(SCRIPT,"$test") or die "Can't run $test.\n";
96 $_ = <SCRIPT>;
97 close(SCRIPT);
98 if (/#!..perl(.*)/) {
99 $switch = $1;
100 if ($^O eq 'VMS') {
101 # Must protect uppercase switches with "" on command line
102 $switch =~ s/-([A-Z]\S*)/"-$1"/g;
103 }
104 }
105 else {
106 $switch = '';
107 }
108
109 if ($type eq 'perl') {
3e2f796a 110 my $run = "./perl$switch -I../lib -Mutf8 $test |";
111 open(RESULTS, $run) or
112 print "can't run '$run': $!.\n";
a0ed51b3 113 }
114 else {
3e2f796a 115 my $compile = "./perl -I../lib ../utils/perlcc -Mutf8 ./$test -run -verbose dcf -log ../compilelog |";
116 open(RESULTS, $compile) or
117 print "can't compile '$compile': $!.\n";
a0ed51b3 118 }
119 }
120 $ok = 0;
121 $next = 0;
122 while (<RESULTS>) {
123 if ($verbose) {
124 print $_;
125 }
126 unless (/^#/) {
127 if (/^1\.\.([0-9]+)/) {
128 $max = $1;
129 $totmax += $max;
130 $files += 1;
131 $next = 1;
132 $ok = 1;
133 }
134 else {
135 $next = $1, $ok = 0, last if /^not ok ([0-9]*)/;
136 if (/^ok (\d+)(\s*#.*)?$/ && $1 == $next) {
137 $next = $next + 1;
d667a7e6 138 }
139 elsif (/^Bail out!\s*(.*)/i) { # magic words
140 die "FAILED--Further testing stopped" . ($1 ? ": $1\n" : ".\n");
a0ed51b3 141 }
142 else {
143 $ok = 0;
144 }
145 }
146 }
147 }
148 close RESULTS;
149 $next = $next - 1;
150 if ($ok && $next == $max) {
151 if ($max) {
152 print "ok\n";
153 $good = $good + 1;
154 }
155 else {
156 print "skipping test on this platform\n";
157 $files -= 1;
158 }
159 }
160 else {
161 $next += 1;
162 print "FAILED at test $next\n";
163 $bad = $bad + 1;
164 $_ = $test;
165 if (/^base/) {
166 die "Failed a basic test--cannot continue.\n";
167 }
168 }
169 }
170
171 if ($bad == 0) {
172 if ($ok) {
173 print "All tests successful.\n";
174 # XXX add mention of 'perlbug -ok' ?
175 }
176 else {
177 die "FAILED--no tests were run for some reason.\n";
178 }
179 }
180 else {
181 $pct = sprintf("%.2f", $good / $total * 100);
182 if ($bad == 1) {
183 warn "Failed 1 test script out of $total, $pct% okay.\n";
184 }
185 else {
186 warn "Failed $bad test scripts out of $total, $pct% okay.\n";
187 }
188 warn <<'SHRDLU';
189 ### Since not all tests were successful, you may want to run some
190 ### of them individually and examine any diagnostic messages they
191 ### produce. See the INSTALL document's section on "make test".
192 ### If you are testing the compiler, then ignore this message
193 ### and run
194 ### ./perl harness
195 ### in the directory ./t.
196SHRDLU
197 warn <<'SHRDLU' if $good / $total > 0.8;
198 ###
199 ### Since most tests were successful, you have a good chance to
200 ### get information with better granularity by running
201 ### ./perl harness
202 ### in directory ./t.
203SHRDLU
204 }
205 ($user,$sys,$cuser,$csys) = times;
206 print sprintf("u=%g s=%g cu=%g cs=%g scripts=%d tests=%d\n",
207 $user,$sys,$cuser,$csys,$files,$totmax);
208}
209exit ($bad != 0);