This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
integrate cfgperl contents into mainline
[perl5.git] / t / UTEST
CommitLineData
a0ed51b3
LW
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
GS
58 $ENV{PERLCC_TIMEOUT} = 120
59 if ($type eq 'compile' && !$ENV{PERLCC_TIMEOUT});
ef712cf7 60
a0ed51b3
LW
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') {
82 open(RESULTS, "./$test |") || (print "can't run.\n"); }
83 else {
84 open(RESULTS, "./perl -I../lib ../utils/perlcc ./$test -run -verbose dcf -log ../compilelog |") or print "can't compile.\n";
85 }
86 }
87 else {
88 open(SCRIPT,"$test") or die "Can't run $test.\n";
89 $_ = <SCRIPT>;
90 close(SCRIPT);
91 if (/#!..perl(.*)/) {
92 $switch = $1;
93 if ($^O eq 'VMS') {
94 # Must protect uppercase switches with "" on command line
95 $switch =~ s/-([A-Z]\S*)/"-$1"/g;
96 }
97 }
98 else {
99 $switch = '';
100 }
101
102 if ($type eq 'perl') {
103 open(RESULTS,"./perl$switch -I../lib -Mutf8 $test |") || (print "can't run.\n");
104 }
105 else {
106 open(RESULTS, "./perl -I../lib ../utils/perlcc -Mutf8 ./$test -run -verbose dcf -log ../compilelog |") or print "can't compile.\n";
107 }
108 }
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 {
124 $next = $1, $ok = 0, last if /^not ok ([0-9]*)/;
125 if (/^ok (\d+)(\s*#.*)?$/ && $1 == $next) {
126 $next = $next + 1;
127 }
128 else {
129 $ok = 0;
130 }
131 }
132 }
133 }
134 close RESULTS;
135 $next = $next - 1;
136 if ($ok && $next == $max) {
137 if ($max) {
138 print "ok\n";
139 $good = $good + 1;
140 }
141 else {
142 print "skipping test on this platform\n";
143 $files -= 1;
144 }
145 }
146 else {
147 $next += 1;
148 print "FAILED at test $next\n";
149 $bad = $bad + 1;
150 $_ = $test;
151 if (/^base/) {
152 die "Failed a basic test--cannot continue.\n";
153 }
154 }
155 }
156
157 if ($bad == 0) {
158 if ($ok) {
159 print "All tests successful.\n";
160 # XXX add mention of 'perlbug -ok' ?
161 }
162 else {
163 die "FAILED--no tests were run for some reason.\n";
164 }
165 }
166 else {
167 $pct = sprintf("%.2f", $good / $total * 100);
168 if ($bad == 1) {
169 warn "Failed 1 test script out of $total, $pct% okay.\n";
170 }
171 else {
172 warn "Failed $bad test scripts out of $total, $pct% okay.\n";
173 }
174 warn <<'SHRDLU';
175 ### Since not all tests were successful, you may want to run some
176 ### of them individually and examine any diagnostic messages they
177 ### produce. See the INSTALL document's section on "make test".
178 ### If you are testing the compiler, then ignore this message
179 ### and run
180 ### ./perl harness
181 ### in the directory ./t.
182SHRDLU
183 warn <<'SHRDLU' if $good / $total > 0.8;
184 ###
185 ### Since most tests were successful, you have a good chance to
186 ### get information with better granularity by running
187 ### ./perl harness
188 ### in directory ./t.
189SHRDLU
190 }
191 ($user,$sys,$cuser,$csys) = times;
192 print sprintf("u=%g s=%g cu=%g cs=%g scripts=%d tests=%d\n",
193 $user,$sys,$cuser,$csys,$files,$totmax);
194}
195exit ($bad != 0);