[inseparable changes from patch from perl5.003_20 to perl5.003_21]
[p5sagit/p5-mst-13.2.git] / t / pragma / warning.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/warn-*")) {
20
21     open F, "<$_" or die "Cannot open $_: $!\n" ;
22     while (<F>) {
23         last if /^__END__/ ;
24     }
25
26     {
27         local $/ = undef;
28         @prgs = (@prgs, split "\n########\n", <F>) ;
29     }
30     close F ;
31 }
32
33 undef $/;
34
35 print "1..", scalar @prgs, "\n";
36  
37  
38 for (@prgs){
39     my $switch = "";
40     my @temps = () ;
41     if (s/^\s*-\w+//){
42         $switch = $&;
43         $switch =~ s/(-\S*[A-Z]\S*)/"-$1"/ if $Is_VMS; # protect uc switches
44     }
45     my($prog,$expected) = split(/\nEXPECT\n/, $_);
46     if ( $prog =~ /--FILE--/) {
47         my(@files) = split(/\n--FILE--\s*([^\s\n]*)\s*\n/, $prog) ;
48         shift @files ;
49         die "Internal error test $i didn't split into pairs, got " . 
50                 scalar(@files) . "[" . join("%%%%", @files) ."]\n"
51             if @files % 2 ;
52         while (@files > 2) {
53             my $filename = shift @files ;
54             my $code = shift @files ;
55             push @temps, $filename ;
56             open F, ">$filename" or die "Cannot open $filename: $!\n" ;
57             print F $code ;
58             close F ;
59         }
60         shift @files ;
61         $prog = shift @files ;
62     }
63     open TEST, ">$tmpfile";
64     print TEST $prog,"\n";
65     close TEST;
66     my $results = $Is_VMS ?
67                   `MCR $^X $switch $tmpfile` :
68                   `sh -c './perl $switch $tmpfile' 2>&1`;
69     my $status = $?;
70     $results =~ s/\n+$//;
71     # allow expected output to be written as if $prog is on STDIN
72     $results =~ s/tmp\d+/-/g;
73     $results =~ s/\n%[A-Z]+-[SIWEF]-.*$// if $Is_VMS;  # clip off DCL status msg
74     $expected =~ s/\n+$//;
75     my $prefix = ($results =~ s/^PREFIX\n//) ;
76     if ( $results =~ s/^SKIPPED\n//) {
77         print "$results\n" ;
78     }
79     elsif (($prefix and $results !~ /^\Q$expected/) or
80            (!$prefix and $results ne $expected)){
81         print STDERR "PROG: $switch\n$prog\n";
82         print STDERR "EXPECTED:\n$expected\n";
83         print STDERR "GOT:\n$results\n";
84         print "not ";
85     }
86     print "ok ", ++$i, "\n";
87     foreach (@temps) 
88         { unlink $_ if $_ } 
89 }