This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
back out problematic change#1105, tweak perlsub.pod
[perl5.git] / t / TEST
CommitLineData
8d063cd8
LW
1#!./perl
2
f46c10df 3# Last change: Fri Jan 10 09:57:03 WET 1997
8d063cd8
LW
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
a687059c
LW
8$| = 1;
9
3e6e8be7 10if ($#ARGV >= 0 && $ARGV[0] eq '-v') {
8d063cd8
LW
11 $verbose = 1;
12 shift;
13}
14
378cc40b
LW
15chdir 't' if -f 't/TEST';
16
3e6e8be7 17die "You need to run \"make test\" first to set things up.\n"
4633a7c4
LW
18 unless -e 'perl' or -e 'perl.exe';
19
7b8d334a 20#$ENV{PERL_DESTRUCT_LEVEL} = '2';
4633a7c4 21$ENV{EMXSHELL} = 'sh'; # For OS/2
748a9306 22
3e6e8be7
MB
23if ($#ARGV == -1) {
24 @ARGV = split(/[ \n]/,
25 `echo base/*.t comp/*.t cmd/*.t io/*.t; echo op/*.t pragma/*.t lib/*.t`);
8d063cd8
LW
26}
27
3e6e8be7 28if ($^O eq 'os2' || $^O eq 'qnx') {
ff68c719
PP
29 $sharpbang = 0;
30}
31else {
32 open(CONFIG, "../config.sh");
33 while (<CONFIG>) {
34 if (/sharpbang='(.*)'/) {
35 $sharpbang = ($1 eq '#!');
36 last;
37 }
135863df 38 }
ff68c719 39 close(CONFIG);
135863df 40}
ff68c719 41
6ee623d5
GS
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{
49 $type = shift @_;
50 @tests = @_;
51
52
53 print "
54--------------------------------------------------------------------------------
55TESTING COMPILER
56--------------------------------------------------------------------------------
57" if ($type eq 'compile');
58
59 $bad = 0;
60 $good = 0;
61 $total = @tests;
62 $files = 0;
63 $totmax = 0;
64while ($test = shift @tests) {
65
66 if ( $infinite{$test} && $type eq 'compile' ) {
67 print STDERR "$test creates infinite loop! Skipping.\n";
68 next;
69 }
fe14fcc3 70 if ($test =~ /^$/) {
378cc40b
LW
71 next;
72 }
fe14fcc3
LW
73 $te = $test;
74 chop($te);
55497cff 75 print "$te" . '.' x (18 - length($te));
135863df 76 if ($sharpbang) {
3e6e8be7 77 -x $test || (print "isn't executable.\n");
6ee623d5
GS
78
79 if ($type eq 'perl')
80 { open(RESULTS, "./$test |") || (print "can't run.\n"); }
81 else
82 {
83 open(RESULTS, "./perl -I../lib ../utils/perlcc ./$test -run -verbose dcf -log ../compilelog |")
84 || (print "can't compile.\n");
85 }
135863df 86 } else {
3e6e8be7
MB
87 open(SCRIPT,"$test") || die "Can't run $test.\n";
88 $_ = <SCRIPT>;
89 close(SCRIPT);
135863df
AB
90 if (/#!..perl(.*)/) {
91 $switch = $1;
55497cff
PP
92 if ($^O eq 'VMS') {
93 # Must protect uppercase switches with "" on command line
94 $switch =~ s/-([A-Z]\S*)/"-$1"/g;
95 }
135863df
AB
96 } else {
97 $switch = '';
98 }
6ee623d5
GS
99
100 if ($type eq 'perl')
101 {
102 open(RESULTS,"./perl$switch $test |") || (print "can't run.\n");
103 }
104 else
105 {
106 open(RESULTS, "./perl -I../lib ../utils/perlcc ./$test -run -verbose dcf -log ../compilelog |")
107 || (print "can't compile.\n");
108 }
135863df 109 }
8d063cd8 110 $ok = 0;
378cc40b 111 $next = 0;
3e6e8be7 112 while (<RESULTS>) {
8d063cd8
LW
113 if ($verbose) {
114 print $_;
115 }
116 unless (/^#/) {
117 if (/^1\.\.([0-9]+)/) {
118 $max = $1;
2b317908
LW
119 $totmax += $max;
120 $files += 1;
8d063cd8
LW
121 $next = 1;
122 $ok = 1;
123 } else {
7e1cf235 124 $next = $1, $ok = 0, last if /^not ok ([0-9]*)/;
fac76ed7 125 if (/^ok (\d+)(\s*#.*)?$/ && $1 == $next) {
8d063cd8
LW
126 $next = $next + 1;
127 } else {
128 $ok = 0;
129 }
130 }
131 }
132 }
133 $next = $next - 1;
134 if ($ok && $next == $max) {
bcce72a7
PP
135 if ($max) {
136 print "ok\n";
137 $good = $good + 1;
138 } else {
139 print "skipping test on this platform\n";
140 $files -= 1;
141 }
8d063cd8
LW
142 } else {
143 $next += 1;
3e6e8be7 144 print "FAILED at test $next\n";
8d063cd8
LW
145 $bad = $bad + 1;
146 $_ = $test;
147 if (/^base/) {
378cc40b 148 die "Failed a basic test--cannot continue.\n";
8d063cd8
LW
149 }
150 }
151}
152
153if ($bad == 0) {
154 if ($ok) {
155 print "All tests successful.\n";
3e6e8be7 156 # XXX add mention of 'perlbug -ok' ?
8d063cd8 157 } else {
378cc40b 158 die "FAILED--no tests were run for some reason.\n";
8d063cd8
LW
159 }
160} else {
79072805 161 $pct = sprintf("%.2f", $good / $total * 100);
8d063cd8 162 if ($bad == 1) {
f46c10df 163 warn "Failed 1 test script out of $total, $pct% okay.\n";
8d063cd8 164 } else {
f46c10df 165 warn "Failed $bad test scripts out of $total, $pct% okay.\n";
8d063cd8 166 }
f46c10df
CS
167 warn <<'SHRDLU';
168 ### Since not all tests were successful, you may want to run some
169 ### of them individually and examine any diagnostic messages they
170 ### produce. See the INSTALL document's section on "make test".
6ee623d5
GS
171 ### If you are testing the compiler, then ignore this message
172 ### and run
173 ### ./perl harness
174 ### in the directory ./t.
f46c10df 175SHRDLU
3e6e8be7
MB
176 warn <<'SHRDLU' if $good / $total > 0.8;
177 ###
178 ### Since most tests were successful, you have a good chance to
179 ### get information with better granularity by running
6ee623d5 180 ### ./perl harness
3e6e8be7
MB
181 ### in directory ./t.
182SHRDLU
8d063cd8
LW
183}
184($user,$sys,$cuser,$csys) = times;
f46c10df 185print sprintf("u=%g s=%g cu=%g cs=%g scripts=%d tests=%d\n",
2b317908 186 $user,$sys,$cuser,$csys,$files,$totmax);
6ee623d5 187}
3e6e8be7 188exit ($bad != 0);