safety check for vms/test.com
[p5sagit/p5-mst-13.2.git] / vms / test.com
1 $!  Test.Com - DCL driver for perl5 regression tests
2 $!
3 $!  Version 1.1   4-Dec-1995
4 $!  Charles Bailey  bailey@newman.upenn.edu
5 $!
6 $!  A little basic setup
7 $   On Error Then Goto wrapup
8 $   olddef = F$Environment("Default")
9 $   oldmsg = F$Environment("Message")
10 $   If F$Search("t.dir").nes.""
11 $   Then
12 $       Set Default [.t]
13 $   Else
14 $       If F$TrnLNm("Perl_Root").nes.""
15 $       Then 
16 $           Set Default Perl_Root:[t]
17 $       Else
18 $           Write Sys$Error "Can't find test directory"
19 $           Exit 44
20 $       EndIf
21 $   EndIf
22 $   Set Message /NoFacility/NoSeverity/NoIdentification/NoText
23 $!
24 $   exe = ".Exe"
25 $   If p1.nes."" Then exe = p1
26 $   If F$Extract(0,1,exe) .nes. "."
27 $   Then
28 $     Write Sys$Error ""
29 $     Write Sys$Error "The first parameter passed to Test.Com must be the file type used for the"
30 $     Write Sys$Error "images produced when you built Perl (i.e. "".Exe"", unless you edited"
31 $     Write Sys$Error "Descrip.MMS or used the AXE=1 macro in the MM[SK] command line."
32 $     Write Sys$Error ""
33 $     Exit 44
34 $   EndIf
35 $!
36 $!  "debug" perl if second parameter is nonblank
37 $!
38 $   dbg = ""
39 $   ndbg = ""
40 $   if p2.nes."" then dbg  = "dbg"
41 $   if p2.nes."" then ndbg = "ndbg"
42 $!
43 $!  Pick up a copy of perl to use for the tests
44 $   If F$Search("Perl.").nes."" Then Delete/Log/NoConfirm Perl.;*
45 $   Copy/Log/NoConfirm [-]'ndbg'Perl'exe' []Perl.
46 $!
47 $!  Pick up a copy of vmspipe.com to use for the tests
48 $   If F$Search("VMSPIPE.COM").nes."" then Delete/Log/Noconfirm VMSPIPE.COM;*
49 $   Copy/Log/NoConfirm [-]VMSPIPE.COM []
50 $!
51 $!  This may be set for the C compiler in descrip.mms, but it confuses the File::Find tests
52 $   if f$trnlnm("sys") .nes. "" then DeAssign sys
53 $!
54 $!  And do it
55 $   Show Process/Accounting
56 $   testdir = "Directory/NoHead/NoTrail/Column=1"
57 $   PerlShr_filespec = f$parse("Sys$Disk:[-]''dbg'PerlShr''exe'")
58 $   Define 'dbg'Perlshr 'PerlShr_filespec'
59 $   if f$mode() .nes. "INTERACTIVE" then Define PERL_SKIP_TTY_TEST 1
60 $   MCR Sys$Disk:[]Perl. "-I[-.lib]" - "''p3'" "''p4'" "''p5'" "''p6'"
61 $   Deck/Dollar=$$END-OF-TEST$$
62 #
63 # The bulk of the below code is scheduled for deletion.  test.com
64 # will shortly use t/TEST.
65 #
66
67 use Config;
68 use File::Spec;
69
70 $| = 1;
71
72 # Let tests know they're running in the perl core.  Useful for modules
73 # which live dual lives on CPAN.
74 $ENV{PERL_CORE} = 1;
75
76 @ARGV = grep($_,@ARGV);  # remove empty elements due to "''p1'" syntax
77
78 if (lc($ARGV[0]) eq '-v') {
79     $verbose = 1;
80     shift;
81 }
82
83 chdir 't' if -f 't/TEST';
84
85 if ($ARGV[0] eq '') {
86     foreach (<[.*]*.t>, <[-.ext...]*.t>, <[-.lib...]*.t>) {
87       $_ = File::Spec->abs2rel($_);
88       s/\[([a-z]+)/[.$1/;      # hmm, abs2rel doesn't do subdirs of the cwd
89       ($fname = $_) =~ s/.*\]//;
90       push(@ARGV,$_);
91     }
92 }
93
94 $bad = 0;
95 $good = 0;
96 $extra_skip = 0;
97 $total = @ARGV;
98 while ($test = shift) {
99     if ($test =~ /^$/) {
100         next;
101     }
102     $te = $test;
103     chop($te);
104     $te .= '.' x (40 - length($te));
105         open(script,"$test") || die "Can't run $test.\n";
106         $_ = <script>;
107         close(script);
108         if (/#!.*\bperl.*-\w*([tT])/) {
109             $switch = qq{"-$1"};
110         } else {
111             $switch = '';
112         }
113         open(results,"\$ MCR Sys\$Disk:[]Perl. \"-I[-.lib]\" $switch $test 2>&1|") || (print "can't run.\n");
114     $ok = 0;
115     $next = 0;
116     $pending_not = 0;
117     while (<results>) {
118         if ($verbose) {
119             print "$te$_";
120             $te = '';
121         }
122         unless (/^#/) {
123             if (/^1\.\.([0-9]+)( todo ([\d ]+))?/) {
124                 $max = $1;
125                 %todo = map { $_ => 1 } split / /, $3 if $3;
126                 $totmax += $max;
127                 $files += 1;
128                 $next = 1;
129                 $ok = 1;
130             } else {
131                 # our 'echo' substitute produces one more \n than Unix'
132                 next if /^\s*$/;
133
134
135                 if (/^(not )?ok (\d+)[^#]*(\s*#.*)?/ &&
136                     $2 == $next)
137                 {
138                     my($not, $num, $extra) = ($1, $2, $3);
139                     my($istodo) = $extra =~ /^\s*#\s*TODO/ if $extra;
140                     $istodo = 1 if $todo{$num};
141
142                     if( $not && !$istodo ) {
143                         $ok = 0;
144                         $next = $num;
145                         last;
146                     }
147                     elsif( $pending_not ) {
148                         $next = $num;
149                         $ok = 0;
150                     }
151                     else {
152                         $next = $next + 1;
153                     }
154                 }
155                 elsif(/^not $/) {
156                     # VMS has this problem.  It sometimes adds newlines
157                     # between prints.  This sometimes means you get
158                     # "not \nok 42"
159                     $pending_not = 1;
160                 }
161                 elsif (/^Bail out!\s*(.*)/i) { # magic words
162                     die "FAILED--Further testing stopped" . ($1 ? ": $1\n" : ".\n");
163                 }
164                 else {
165                     $ok = 0;
166                 }
167
168             }
169         }
170     }
171     $next = $next - 1;
172     if ($ok && $next == $max) {
173         if ($max) {
174             print "${te}ok\n";
175             $good = $good + 1;
176         } else {
177             print "${te}skipping test on this platform\n";
178             $files -= 1;
179             $extra_skip = $extra_skip + 1;
180         }
181     } else {
182         $next += 1;
183         print "${te}FAILED on 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     } else {
196         die "FAILED--no tests were run for some reason.\n";
197     }
198 } else {
199     # $pct = sprintf("%.2f", $good / $total * 100);
200     $gtotal = $total - $extra_skip;
201     if ($gtotal <= 0) { $gtotal = $total; }
202     $pct = sprintf("%.2f", $good / $gtotal * 100);
203     if ($bad == 1) {
204         warn "Failed 1 test, $pct% okay.\n";
205    } else {
206          if ($extra_skip > 0) {
207              warn "Total tests: $total, Passed $good, Skipped $extra_skip.\n";
208              warn "Failed $bad/$gtotal tests, $pct% okay.\n";
209          }
210          else {
211              warn "Total tests: $total, Passed $good.\n";
212              warn "Failed $bad/$gtotal tests, $pct% okay.\n";
213          }
214     }
215 }
216 ($user,$sys,$cuser,$csys) = times;
217 print sprintf("u=%g  s=%g  cu=%g  cs=%g  scripts=%d  tests=%d\n",
218     $user,$sys,$cuser,$csys,$files,$totmax);
219 $$END-OF-TEST$$
220 $ wrapup:
221 $   deassign 'dbg'Perlshr
222 $   Show Process/Accounting
223 $   Set Default &olddef
224 $   Set Message 'oldmsg'
225 $   Exit