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
1 #!./perl
2
3 # Last change: Fri Jan 10 09:57:03 WET 1997
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
10 if ($#ARGV >= 0 && $ARGV[0] eq '-v') {
11     $verbose = 1;
12     shift;
13 }
14
15 chdir 't' if -f 't/TEST';
16
17 die "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
25 if ($#ARGV == -1) {
26     @ARGV = split(/[ \n]/,
27       `echo base/*.t comp/*.t cmd/*.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
35 sub _testprogs {
36     $type = shift @_;
37     @tests = @_;
38
39
40     print <<'EOT' if ($type eq 'compile');
41 --------------------------------------------------------------------------------
42 TESTING COMPILER
43 --------------------------------------------------------------------------------
44 EOT
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;
56         }
57         if ($test =~ /^$/) {
58             next;
59         }
60         $te = $test;
61         chop($te);
62         print "$te" . '.' x (18 - length($te));
63
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;
72             }
73         }
74         else {
75             $switch = '';
76         }
77
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";
85         }
86
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                     }
109                 }
110             }
111         }
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             }
123         }
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             }
132         }
133     }
134
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         }
143     }
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';
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".
156    ### If you are testing the compiler, then ignore this message 
157    ### and run 
158    ###      ./perl harness
159    ### in the directory ./t.
160 SHRDLU
161         warn <<'SHRDLU' if $good / $total > 0.8;
162    ###
163    ### Since most tests were successful, you have a good chance to
164    ### get information with better granularity by running
165    ###     ./perl harness 
166    ### in directory ./t.
167 SHRDLU
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);
172 }
173 exit ($bad != 0);