[inseparable changes from patch from perl5.003_20 to perl5.003_21]
[p5sagit/p5-mst-13.2.git] / t / pragma / warning.t
CommitLineData
8ebc5c01 1#!./perl
2
3BEGIN {
4 chdir 't' if -d 't';
5 @INC = '../lib';
6 $ENV{PERL5LIB} = '../lib';
7}
8
9$| = 1;
10
44a8e56a 11my $Is_VMS = $^O eq 'VMS';
8ebc5c01 12my $tmpfile = "tmp0000";
13my $i = 0 ;
141 while -f ++$tmpfile;
44a8e56a 15END { if ($tmpfile) { 1 while unlink $tmpfile} }
8ebc5c01 16
17my @prgs = () ;
18
19foreach (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
33undef $/;
34
35print "1..", scalar @prgs, "\n";
36
37
38for (@prgs){
39 my $switch = "";
40 my @temps = () ;
41 if (s/^\s*-\w+//){
42 $switch = $&;
44a8e56a 43 $switch =~ s/(-\S*[A-Z]\S*)/"-$1"/ if $Is_VMS; # protect uc switches
8ebc5c01 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 }
44a8e56a 63 open TEST, ">$tmpfile";
64 print TEST $prog,"\n";
8ebc5c01 65 close TEST;
44a8e56a 66 my $results = $Is_VMS ?
67 `MCR $^X $switch $tmpfile` :
68 `sh -c './perl $switch $tmpfile' 2>&1`;
8ebc5c01 69 my $status = $?;
8ebc5c01 70 $results =~ s/\n+$//;
44a8e56a 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
8ebc5c01 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}