Ignore backup files in strict.t and warning.t
[p5sagit/p5-mst-13.2.git] / t / pragma / strict.t
1 #!./perl 
2
3 BEGIN {
4     chdir 't' if -d 't';
5     @INC = '../lib';
6     $ENV{PERL5LIB} = '../lib';
7 }
8
9 $| = 1;
10
11 my $Is_VMS = $^O eq 'VMS';
12 my $tmpfile = "tmp0000";
13 my $i = 0 ;
14 1 while -f ++$tmpfile;
15 END { if ($tmpfile) { 1 while unlink $tmpfile; } }
16
17 my @prgs = () ;
18
19 foreach (sort glob("pragma/strict-*")) {
20
21     next if /(~|\.orig)$/;
22
23     open F, "<$_" or die "Cannot open $_: $!\n" ;
24     while (<F>) {
25         last if /^__END__/ ;
26     }
27
28     {
29         local $/ = undef;
30         @prgs = (@prgs, split "\n########\n", <F>) ;
31     }
32     close F ;
33 }
34
35 undef $/;
36
37 print "1..", scalar @prgs, "\n";
38  
39  
40 for (@prgs){
41     my $switch = "";
42     my @temps = () ;
43     if (s/^\s*-\w+//){
44         $switch = $&;
45     }
46     my($prog,$expected) = split(/\nEXPECT\n/, $_);
47     if ( $prog =~ /--FILE--/) {
48         my(@files) = split(/\n--FILE--\s*([^\s\n]*)\s*\n/, $prog) ;
49         shift @files ;
50         die "Internal error test $i didn't split into pairs, got " . 
51                 scalar(@files) . "[" . join("%%%%", @files) ."]\n"
52             if @files % 2 ;
53         while (@files > 2) {
54             my $filename = shift @files ;
55             my $code = shift @files ;
56             push @temps, $filename ;
57             open F, ">$filename" or die "Cannot open $filename: $!\n" ;
58             print F $code ;
59             close F ;
60         }
61         shift @files ;
62         $prog = shift @files ;
63     }
64     open TEST, ">$tmpfile";
65     print TEST $prog,"\n";
66     close TEST;
67     my $results = $Is_VMS ?
68                   `MCR $^X $switch $tmpfile` :
69                   `sh -c './perl $switch $tmpfile' 2>&1`;
70     my $status = $?;
71     $results =~ s/\n+$//;
72     # allow expected output to be written as if $prog is on STDIN
73     $results =~ s/tmp\d+/-/g;
74     $results =~ s/\n%[A-Z]+-[SIWEF]-.*$// if $Is_VMS;  # clip off DCL status msg
75     $expected =~ s/\n+$//;
76     my $prefix = ($results =~ s/^PREFIX\n//) ;
77     if ( $results =~ s/^SKIPPED\n//) {
78         print "$results\n" ;
79     }
80     elsif (($prefix and $results !~ /^\Q$expected/) or
81            (!$prefix and $results ne $expected)){
82         print STDERR "PROG: $switch\n$prog\n";
83         print STDERR "EXPECTED:\n$expected\n";
84         print STDERR "GOT:\n$results\n";
85         print "not ";
86     }
87     print "ok ", ++$i, "\n";
88     foreach (@temps) 
89         { unlink $_ if $_ } 
90 }