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