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