Adding todo tests
[p5sagit/p5-mst-13.2.git] / t / TEST
CommitLineData
8d063cd8 1#!./perl
2
8d063cd8 3# This is written in a peculiar style, since we're trying to avoid
4# most of the constructs we'll be testing for.
5
a687059c 6$| = 1;
7
5d9a6404 8# Cheesy version of Getopt::Std. Maybe we should replace it with that.
9if ($#ARGV >= 0) {
10 foreach my $idx (0..$#ARGV) {
11 next unless $ARGV[$idx] =~ /^-(\w+)$/;
12 $verbose = 1 if $1 eq 'v';
13 $with_utf= 1 if $1 eq 'utf8';
14 splice(@ARGV, $idx, 1);
15 }
8d063cd8 16}
17
378cc40b 18chdir 't' if -f 't/TEST';
19
3e6e8be7 20die "You need to run \"make test\" first to set things up.\n"
4633a7c4 21 unless -e 'perl' or -e 'perl.exe';
22
3fb91a5e 23# check leakage for embedders
24$ENV{PERL_DESTRUCT_LEVEL} = 2 unless exists $ENV{PERL_DESTRUCT_LEVEL};
25
4633a7c4 26$ENV{EMXSHELL} = 'sh'; # For OS/2
748a9306 27
3e6e8be7 28if ($#ARGV == -1) {
29 @ARGV = split(/[ \n]/,
ec947e58 30 `echo base/*.t comp/*.t cmd/*.t run/*.t io/*.t; echo op/*.t pragma/*.t lib/*.t`);
8d063cd8 31}
32
6ee623d5 33%infinite = ( 'comp/require.t', 1, 'op/bop.t', 1, 'lib/hostname.t', 1 );
34
35_testprogs('perl', @ARGV);
36_testprogs('compile', @ARGV) if (-e "../testcompile");
37
bb365837 38sub _testprogs {
39 $type = shift @_;
40 @tests = @_;
6ee623d5 41
42
bb365837 43 print <<'EOT' if ($type eq 'compile');
6ee623d5 44--------------------------------------------------------------------------------
45TESTING COMPILER
46--------------------------------------------------------------------------------
bb365837 47EOT
48
9636a016 49 $ENV{PERLCC_TIMEOUT} = 120
50 if ($type eq 'compile' && !$ENV{PERLCC_TIMEOUT});
ef712cf7 51
bb365837 52 $bad = 0;
53 $good = 0;
54 $total = @tests;
55 $files = 0;
56 $totmax = 0;
088b5126 57 $maxlen = 0;
58 foreach (@tests) {
59 $len = length;
60 $maxlen = $len if $len > $maxlen;
61 }
62 # +3 : we want three dots between the test name and the "ok"
63 # -2 : the .t suffix
64 $dotdotdot = $maxlen + 3 - 2;
bb365837 65 while ($test = shift @tests) {
66
67 if ( $infinite{$test} && $type eq 'compile' ) {
68 print STDERR "$test creates infinite loop! Skipping.\n";
69 next;
6ee623d5 70 }
bb365837 71 if ($test =~ /^$/) {
72 next;
6ee623d5 73 }
bb365837 74 $te = $test;
75 chop($te);
088b5126 76 print "$te" . '.' x ($dotdotdot - length($te));
bb365837 77
d638aca2 78 open(SCRIPT,"<$test") or die "Can't run $test.\n";
79 $_ = <SCRIPT>;
80 close(SCRIPT);
81 if (/#!.*perl(.*)$/) {
82 $switch = $1;
83 if ($^O eq 'VMS') {
84 # Must protect uppercase switches with "" on command line
85 $switch =~ s/-([A-Z]\S*)/"-$1"/g;
55497cff 86 }
135863df 87 }
bb365837 88 else {
d638aca2 89 $switch = '';
90 }
6ee623d5 91
5d9a6404 92 my $utf = $with_utf ? '-I../lib -Mutf8'
93 : '';
d638aca2 94 if ($type eq 'perl') {
5d9a6404 95 my $run = "./perl$switch $utf $test |";
be24517c 96 open(RESULTS,$run) or print "can't run '$run': $!.\n";
d638aca2 97 }
98 else {
be24517c 99 my $compile =
5d9a6404 100 "./perl -I../lib ../utils/perlcc -o ./$test.plc $utf ./$test "
be24517c 101 ." && ./$test.plc |";
102 open(RESULTS, $compile)
103 or print "can't compile '$compile': $!.\n";
104 unlink "./$test.plc";
6ee623d5 105 }
d638aca2 106
bb365837 107 $ok = 0;
108 $next = 0;
109 while (<RESULTS>) {
110 if ($verbose) {
111 print $_;
112 }
113 unless (/^#/) {
114 if (/^1\.\.([0-9]+)/) {
115 $max = $1;
116 $totmax += $max;
117 $files += 1;
118 $next = 1;
119 $ok = 1;
120 }
121 else {
37ce32a7 122 if (/^(not )?ok (\d+)(\s*#.*)?/ &&
123 $2 == $next)
124 {
125 my($not, $num, $extra) = ($1, $2, $3);
126 my($istodo) = $extra =~ /^\s*#\s*TODO/ if $extra;
127
128 if( $not && !$istodo ) {
129 $ok = 0;
130 $next = $num;
131 last;
132 }
133 else {
134 $next = $next + 1;
135 }
d667a7e6 136 }
137 elsif (/^Bail out!\s*(.*)/i) { # magic words
138 die "FAILED--Further testing stopped" . ($1 ? ": $1\n" : ".\n");
bb365837 139 }
140 else {
141 $ok = 0;
142 }
8d063cd8 143 }
144 }
145 }
bb365837 146 close RESULTS;
147 $next = $next - 1;
148 if ($ok && $next == $max) {
149 if ($max) {
150 print "ok\n";
151 $good = $good + 1;
152 }
153 else {
154 print "skipping test on this platform\n";
155 $files -= 1;
156 }
bcce72a7 157 }
bb365837 158 else {
159 $next += 1;
160 print "FAILED at test $next\n";
161 $bad = $bad + 1;
162 $_ = $test;
163 if (/^base/) {
164 die "Failed a basic test--cannot continue.\n";
165 }
8d063cd8 166 }
167 }
8d063cd8 168
bb365837 169 if ($bad == 0) {
170 if ($ok) {
171 print "All tests successful.\n";
172 # XXX add mention of 'perlbug -ok' ?
173 }
174 else {
175 die "FAILED--no tests were run for some reason.\n";
176 }
8d063cd8 177 }
bb365837 178 else {
ba1398cf 179 $pct = $files ? sprintf("%.2f", ($files - $bad) / $files * 100) : "0.00";
bb365837 180 if ($bad == 1) {
e824fb2c 181 warn "Failed 1 test script out of $files, $pct% okay.\n";
bb365837 182 }
183 else {
e824fb2c 184 warn "Failed $bad test scripts out of $files, $pct% okay.\n";
bb365837 185 }
186 warn <<'SHRDLU';
f46c10df 187 ### Since not all tests were successful, you may want to run some
188 ### of them individually and examine any diagnostic messages they
189 ### produce. See the INSTALL document's section on "make test".
6ee623d5 190 ### If you are testing the compiler, then ignore this message
191 ### and run
192 ### ./perl harness
193 ### in the directory ./t.
f46c10df 194SHRDLU
bb365837 195 warn <<'SHRDLU' if $good / $total > 0.8;
3e6e8be7 196 ###
197 ### Since most tests were successful, you have a good chance to
198 ### get information with better granularity by running
6ee623d5 199 ### ./perl harness
3e6e8be7 200 ### in directory ./t.
201SHRDLU
bb365837 202 }
203 ($user,$sys,$cuser,$csys) = times;
204 print sprintf("u=%g s=%g cu=%g cs=%g scripts=%d tests=%d\n",
205 $user,$sys,$cuser,$csys,$files,$totmax);
6ee623d5 206}
3e6e8be7 207exit ($bad != 0);