I don't think trying to bracket the hires time with lores
[p5sagit/p5-mst-13.2.git] / lib / strict.t
CommitLineData
8ebc5c01 1#!./perl
2
3BEGIN {
4 chdir 't' if -d 't';
20822f61 5 @INC = '../lib';
8ebc5c01 6 $ENV{PERL5LIB} = '../lib';
7}
8
9$| = 1;
10
44a8e56a 11my $Is_VMS = $^O eq 'VMS';
68dc0745 12my $Is_MSWin32 = $^O eq 'MSWin32';
2986a63f 13my $Is_NetWare = $^O eq 'NetWare';
8ebc5c01 14my $tmpfile = "tmp0000";
15my $i = 0 ;
161 while -f ++$tmpfile;
44a8e56a 17END { if ($tmpfile) { 1 while unlink $tmpfile; } }
8ebc5c01 18
19my @prgs = () ;
20
8a6cb2cb 21foreach (sort glob($^O eq 'MacOS' ? ":lib::strict:*" : "lib/strict/*")) {
8ebc5c01 22
8593bda5 23 next if /(~|\.orig|,v)$/;
d8b8f155 24
8ebc5c01 25 open F, "<$_" or die "Cannot open $_: $!\n" ;
26 while (<F>) {
27 last if /^__END__/ ;
28 }
29
30 {
31 local $/ = undef;
32 @prgs = (@prgs, split "\n########\n", <F>) ;
33 }
34 close F ;
35}
36
37undef $/;
38
39print "1..", scalar @prgs, "\n";
40
41
42for (@prgs){
43 my $switch = "";
44 my @temps = () ;
45 if (s/^\s*-\w+//){
46 $switch = $&;
47 }
48 my($prog,$expected) = split(/\nEXPECT\n/, $_);
49 if ( $prog =~ /--FILE--/) {
50 my(@files) = split(/\n--FILE--\s*([^\s\n]*)\s*\n/, $prog) ;
51 shift @files ;
52 die "Internal error test $i didn't split into pairs, got " .
53 scalar(@files) . "[" . join("%%%%", @files) ."]\n"
54 if @files % 2 ;
55 while (@files > 2) {
56 my $filename = shift @files ;
57 my $code = shift @files ;
95e8664e 58 $code =~ s|\./abc|:abc|g if $^O eq 'MacOS';
8ebc5c01 59 push @temps, $filename ;
60 open F, ">$filename" or die "Cannot open $filename: $!\n" ;
61 print F $code ;
62 close F ;
63 }
64 shift @files ;
65 $prog = shift @files ;
95e8664e 66 $prog =~ s|\./abc|:abc|g if $^O eq 'MacOS';
8ebc5c01 67 }
44a8e56a 68 open TEST, ">$tmpfile";
69 print TEST $prog,"\n";
8ebc5c01 70 close TEST;
f0963acb 71 my $results = $Is_MSWin32 ?
be708cc0 72 `.\\perl -I../lib $switch $tmpfile 2>&1` :
2986a63f 73 $^O eq 'NetWare' ?
be708cc0 74 `perl -I../lib $switch $tmpfile 2>&1` :
75 $^O eq 'MacOS' ?
76 `$^X -I::lib -MMac::err=unix $switch $tmpfile` :
648cac19 77 `./perl $switch $tmpfile 2>&1`;
8ebc5c01 78 my $status = $?;
8ebc5c01 79 $results =~ s/\n+$//;
44a8e56a 80 # allow expected output to be written as if $prog is on STDIN
81 $results =~ s/tmp\d+/-/g;
82 $results =~ s/\n%[A-Z]+-[SIWEF]-.*$// if $Is_VMS; # clip off DCL status msg
8ebc5c01 83 $expected =~ s/\n+$//;
95e8664e 84 $expected =~ s|(\./)?abc\.pm|:abc.pm|g if $^O eq 'MacOS';
85 $expected =~ s|./abc|:abc|g if $^O eq 'MacOS';
8ebc5c01 86 my $prefix = ($results =~ s/^PREFIX\n//) ;
87 if ( $results =~ s/^SKIPPED\n//) {
88 print "$results\n" ;
89 }
90 elsif (($prefix and $results !~ /^\Q$expected/) or
91 (!$prefix and $results ne $expected)){
92 print STDERR "PROG: $switch\n$prog\n";
93 print STDERR "EXPECTED:\n$expected\n";
94 print STDERR "GOT:\n$results\n";
95 print "not ";
96 }
97 print "ok ", ++$i, "\n";
98 foreach (@temps)
99 { unlink $_ if $_ }
100}