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