This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Pod::Html -- fixes extra gaps in raw text
[perl5.git] / t / TEST
1 #!./perl
2
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
6 $| = 1;
7
8 # Cheesy version of Getopt::Std.  Maybe we should replace it with that.
9 if ($#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     }
16 }
17
18 chdir 't' if -f 't/TEST';
19
20 die "You need to run \"make test\" first to set things up.\n"
21   unless -e 'perl' or -e 'perl.exe';
22
23 if ($ENV{PERL_3LOG}) {
24     unless (-x 'perl.third') {
25         unless (-x '../perl.third') {
26             die "You need to run \"make perl.third first.\n";
27         }
28         else {
29             print "Symlinking ../perl.third as perl.third...\n";
30             die "Failed to symlink: $!\n"
31                 unless symlink("../perl.third", "perl.third");
32             die "Symlinked but no executable perl.third: $!\n"
33                 unless -x 'perl.third';
34         }
35     }
36 }
37
38 # check leakage for embedders
39 $ENV{PERL_DESTRUCT_LEVEL} = 2 unless exists $ENV{PERL_DESTRUCT_LEVEL};
40
41 $ENV{EMXSHELL} = 'sh';        # For OS/2
42
43 if ($#ARGV == -1) {
44     @ARGV = split(/[ \n]/,
45       `echo base/*.t comp/*.t cmd/*.t run/*.t io/*.t; echo op/*.t pragma/*.t lib/*.t pod/*.t camel-III/*.t`);
46 }
47
48 # %infinite = ( 'comp/require.t', 1, 'op/bop.t', 1, 'lib/hostname.t', 1 );
49
50 _testprogs('perl', @ARGV);
51 _testprogs('compile', @ARGV) if (-e "../testcompile");
52
53 sub _testprogs {
54     $type = shift @_;
55     @tests = @_;
56
57
58     print <<'EOT' if ($type eq 'compile');
59 --------------------------------------------------------------------------------
60 TESTING COMPILER
61 --------------------------------------------------------------------------------
62 EOT
63
64     $ENV{PERLCC_TIMEOUT} = 120
65           if ($type eq 'compile' && !$ENV{PERLCC_TIMEOUT});
66
67     $bad = 0;
68     $good = 0;
69     $total = @tests;
70     $files  = 0;
71     $totmax = 0;
72     $maxlen = 0;
73     foreach (@tests) {
74         $len = length;
75         $maxlen = $len if $len > $maxlen;
76     }
77     # +3 : we want three dots between the test name and the "ok"
78     # -2 : the .t suffix
79     $dotdotdot = $maxlen + 3 - 2;
80     while ($test = shift @tests) {
81
82         if ( $infinite{$test} && $type eq 'compile' ) {
83             print STDERR "$test creates infinite loop! Skipping.\n";
84             next;
85         }
86         if ($test =~ /^$/) {
87             next;
88         }
89         $te = $test;
90         chop($te);
91         print "$te" . '.' x ($dotdotdot - length($te));
92
93         open(SCRIPT,"<$test") or die "Can't run $test.\n";
94         $_ = <SCRIPT>;
95         close(SCRIPT);
96         if (/#!.*perl(.*)$/) {
97             $switch = $1;
98             if ($^O eq 'VMS') {
99                 # Must protect uppercase switches with "" on command line
100                 $switch =~ s/-([A-Z]\S*)/"-$1"/g;
101             }
102         }
103         else {
104             $switch = '';
105         }
106
107         my $utf = $with_utf ? '-I../lib -Mutf8'
108                             : '';
109         my $testswitch = '-I. -MTestInit'; # -T will strict . from @INC
110         if ($type eq 'perl') {
111             my $run = "./perl $testswitch $switch $utf $test |";
112             open(RESULTS,$run) or print "can't run '$run': $!.\n";
113         }
114         else {
115             my $compile =
116                 "./perl $testswitch -I../lib ../utils/perlcc -o ".
117                 "./$test.plc $utf ./$test ".
118                 " && ./$test.plc |";
119             open(RESULTS, $compile)
120                 or print "can't compile '$compile': $!.\n";
121             unlink "./$test.plc";
122         }
123
124         $ok = 0;
125         $next = 0;
126         while (<RESULTS>) {
127             if ($verbose) {
128                 print $_;
129             }
130             unless (/^#/) {
131                 if (/^1\.\.([0-9]+)/) {
132                     $max = $1;
133                     $totmax += $max;
134                     $files += 1;
135                     $next = 1;
136                     $ok = 1;
137                 }
138                 else {
139                     if (/^(not )?ok (\d+)(\s*#.*)?/ &&
140                         $2 == $next)
141                     {
142                         my($not, $num, $extra) = ($1, $2, $3);
143                         my($istodo) = $extra =~ /^\s*#\s*TODO/ if $extra;
144
145                         if( $not && !$istodo ) {
146                             $ok = 0;
147                             $next = $num;
148                             last;
149                         }
150                         else {
151                             $next = $next + 1;
152                         }
153                     }
154                     elsif (/^Bail out!\s*(.*)/i) { # magic words
155                         die "FAILED--Further testing stopped" . ($1 ? ": $1\n" : ".\n");
156                     }
157                     else {
158                         $ok = 0;
159                     }
160                 }
161             }
162         }
163         close RESULTS;
164         if ($ENV{PERL_3LOG}) {
165             my $tpp = $test;
166             $tpp =~ s:/:_:g;
167             $tpp =~ s:\.t$::;
168             rename("perl.3log", "perl.3log.$tpp");
169         }
170         $next = $next - 1;
171         if ($ok && $next == $max) {
172             if ($max) {
173                 print "ok\n";
174                 $good = $good + 1;
175             }
176             else {
177                 print "skipping test on this platform\n";
178                 $files -= 1;
179             }
180         }
181         else {
182             $next += 1;
183             print "FAILED at test $next\n";
184             $bad = $bad + 1;
185             $_ = $test;
186             if (/^base/) {
187                 die "Failed a basic test--cannot continue.\n";
188             }
189         }
190     }
191
192     if ($bad == 0) {
193         if ($ok) {
194             print "All tests successful.\n";
195             # XXX add mention of 'perlbug -ok' ?
196         }
197         else {
198             die "FAILED--no tests were run for some reason.\n";
199         }
200     }
201     else {
202         $pct = $files ? sprintf("%.2f", ($files - $bad) / $files * 100) : "0.00";
203         if ($bad == 1) {
204             warn "Failed 1 test script out of $files, $pct% okay.\n";
205         }
206         else {
207             warn "Failed $bad test scripts out of $files, $pct% okay.\n";
208         }
209         warn <<'SHRDLU';
210    ### Since not all tests were successful, you may want to run some
211    ### of them individually and examine any diagnostic messages they
212    ### produce.  See the INSTALL document's section on "make test".
213    ### If you are testing the compiler, then ignore this message
214    ### and run
215    ###      ./perl harness
216    ### in the directory ./t.
217 SHRDLU
218         warn <<'SHRDLU' if $good / $total > 0.8;
219    ###
220    ### Since most tests were successful, you have a good chance to
221    ### get information with better granularity by running
222    ###     ./perl harness
223    ### in directory ./t.
224 SHRDLU
225     }
226     ($user,$sys,$cuser,$csys) = times;
227     print sprintf("u=%g  s=%g  cu=%g  cs=%g  scripts=%d  tests=%d\n",
228         $user,$sys,$cuser,$csys,$files,$totmax);
229 }
230 exit ($bad != 0);