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