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