This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
manually apply patch with a dependency on unapplied patch
[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
bb365837
GS
47sub _testprogs {
48 $type = shift @_;
49 @tests = @_;
6ee623d5
GS
50
51
bb365837 52 print <<'EOT' if ($type eq 'compile');
6ee623d5
GS
53--------------------------------------------------------------------------------
54TESTING COMPILER
55--------------------------------------------------------------------------------
bb365837
GS
56EOT
57
58 $bad = 0;
59 $good = 0;
60 $total = @tests;
61 $files = 0;
62 $totmax = 0;
63 while ($test = shift @tests) {
64
65 if ( $infinite{$test} && $type eq 'compile' ) {
66 print STDERR "$test creates infinite loop! Skipping.\n";
67 next;
6ee623d5 68 }
bb365837
GS
69 if ($test =~ /^$/) {
70 next;
6ee623d5 71 }
bb365837
GS
72 $te = $test;
73 chop($te);
74 print "$te" . '.' x (18 - length($te));
75 if ($sharpbang) {
8e169608 76 eval { chmod 0555, $test } unless -x $test;
bb365837
GS
77
78 if ($type eq 'perl') {
8e169608
GS
79 unless (open(RESULTS, "./$test |")) {
80 print "$test not executable, " unless -x $test;
81 print "can't run.\n";
82 }
83 }
bb365837 84 else {
8e169608
GS
85 open(RESULTS, "./perl -I../lib ../utils/perlcc ./$test "
86 ."-run -verbose dcf -log ../compilelog |")
87 or print "can't compile.\n";
55497cff 88 }
135863df 89 }
bb365837
GS
90 else {
91 open(SCRIPT,"$test") or die "Can't run $test.\n";
92 $_ = <SCRIPT>;
93 close(SCRIPT);
94 if (/#!..perl(.*)/) {
95 $switch = $1;
96 if ($^O eq 'VMS') {
97 # Must protect uppercase switches with "" on command line
98 $switch =~ s/-([A-Z]\S*)/"-$1"/g;
99 }
100 }
101 else {
102 $switch = '';
103 }
6ee623d5 104
bb365837 105 if ($type eq 'perl') {
6ee623d5 106 open(RESULTS,"./perl$switch $test |") || (print "can't run.\n");
bb365837
GS
107 }
108 else {
109 open(RESULTS, "./perl -I../lib ../utils/perlcc ./$test -run -verbose dcf -log ../compilelog |") or print "can't compile.\n";
110 }
6ee623d5 111 }
bb365837
GS
112 $ok = 0;
113 $next = 0;
114 while (<RESULTS>) {
115 if ($verbose) {
116 print $_;
117 }
118 unless (/^#/) {
119 if (/^1\.\.([0-9]+)/) {
120 $max = $1;
121 $totmax += $max;
122 $files += 1;
123 $next = 1;
124 $ok = 1;
125 }
126 else {
127 $next = $1, $ok = 0, last if /^not ok ([0-9]*)/;
128 if (/^ok (\d+)(\s*#.*)?$/ && $1 == $next) {
129 $next = $next + 1;
130 }
131 else {
132 $ok = 0;
133 }
8d063cd8
LW
134 }
135 }
136 }
bb365837
GS
137 close RESULTS;
138 $next = $next - 1;
139 if ($ok && $next == $max) {
140 if ($max) {
141 print "ok\n";
142 $good = $good + 1;
143 }
144 else {
145 print "skipping test on this platform\n";
146 $files -= 1;
147 }
bcce72a7 148 }
bb365837
GS
149 else {
150 $next += 1;
151 print "FAILED at test $next\n";
152 $bad = $bad + 1;
153 $_ = $test;
154 if (/^base/) {
155 die "Failed a basic test--cannot continue.\n";
156 }
8d063cd8
LW
157 }
158 }
8d063cd8 159
bb365837
GS
160 if ($bad == 0) {
161 if ($ok) {
162 print "All tests successful.\n";
163 # XXX add mention of 'perlbug -ok' ?
164 }
165 else {
166 die "FAILED--no tests were run for some reason.\n";
167 }
8d063cd8 168 }
bb365837
GS
169 else {
170 $pct = sprintf("%.2f", $good / $total * 100);
171 if ($bad == 1) {
172 warn "Failed 1 test script out of $total, $pct% okay.\n";
173 }
174 else {
175 warn "Failed $bad test scripts out of $total, $pct% okay.\n";
176 }
177 warn <<'SHRDLU';
f46c10df
CS
178 ### Since not all tests were successful, you may want to run some
179 ### of them individually and examine any diagnostic messages they
180 ### produce. See the INSTALL document's section on "make test".
6ee623d5
GS
181 ### If you are testing the compiler, then ignore this message
182 ### and run
183 ### ./perl harness
184 ### in the directory ./t.
f46c10df 185SHRDLU
bb365837 186 warn <<'SHRDLU' if $good / $total > 0.8;
3e6e8be7
MB
187 ###
188 ### Since most tests were successful, you have a good chance to
189 ### get information with better granularity by running
6ee623d5 190 ### ./perl harness
3e6e8be7
MB
191 ### in directory ./t.
192SHRDLU
bb365837
GS
193 }
194 ($user,$sys,$cuser,$csys) = times;
195 print sprintf("u=%g s=%g cu=%g cs=%g scripts=%d tests=%d\n",
196 $user,$sys,$cuser,$csys,$files,$totmax);
6ee623d5 197}
3e6e8be7 198exit ($bad != 0);