Commit | Line | Data |
8ebc5c01 |
1 | #!./perl |
2 | |
3 | BEGIN { |
4 | chdir 't' if -d 't'; |
20822f61 |
5 | @INC = '../lib'; |
8ebc5c01 |
6 | $ENV{PERL5LIB} = '../lib'; |
e5e1b98b |
7 | require Config; import Config; |
3401e594 |
8 | $ENV{PERL_DESTRUCT_LEVEL} = 0 unless $ENV{PERL_DESTRUCT_LEVEL} > 3; |
8ebc5c01 |
9 | } |
10 | |
11 | $| = 1; |
12 | |
e5e1b98b |
13 | my $Is_VMS = $^O eq 'VMS'; |
68dc0745 |
14 | my $Is_MSWin32 = $^O eq 'MSWin32'; |
8ebc5c01 |
15 | my $tmpfile = "tmp0000"; |
16 | my $i = 0 ; |
17 | 1 while -f ++$tmpfile; |
44a8e56a |
18 | END { if ($tmpfile) { 1 while unlink $tmpfile} } |
8ebc5c01 |
19 | |
20 | my @prgs = () ; |
599cee73 |
21 | my @w_files = () ; |
8ebc5c01 |
22 | |
599cee73 |
23 | if (@ARGV) |
b3704311 |
24 | { print "ARGV = [@ARGV]\n" ; @w_files = map { s#^#./pragma/warn/#; $_ } @ARGV } |
599cee73 |
25 | else |
b3704311 |
26 | { @w_files = sort glob("pragma/warn/*") } |
599cee73 |
27 | |
3789aae2 |
28 | my $files = 0; |
29 | foreach my $file (@w_files) { |
599cee73 |
30 | |
8593bda5 |
31 | next if /(~|\.orig|,v)$/; |
d8b8f155 |
32 | |
3789aae2 |
33 | open F, "<$file" or die "Cannot open $file: $!\n" ; |
34 | my $line = 0; |
8ebc5c01 |
35 | while (<F>) { |
3789aae2 |
36 | $line++; |
8ebc5c01 |
37 | last if /^__END__/ ; |
38 | } |
39 | |
40 | { |
41 | local $/ = undef; |
3789aae2 |
42 | $files++; |
43 | @prgs = (@prgs, $file, split "\n########\n", <F>) ; |
8ebc5c01 |
44 | } |
45 | close F ; |
46 | } |
47 | |
48 | undef $/; |
49 | |
3789aae2 |
50 | print "1..", scalar(@prgs)-$files, "\n"; |
8ebc5c01 |
51 | |
52 | |
53 | for (@prgs){ |
3789aae2 |
54 | unless (/\n/) |
55 | { |
56 | print "# From $_\n"; |
57 | next; |
58 | } |
8ebc5c01 |
59 | my $switch = ""; |
60 | my @temps = () ; |
61 | if (s/^\s*-\w+//){ |
62 | $switch = $&; |
3937c24e |
63 | $switch =~ s/(-\S*[A-Z]\S*)/"$1"/ if $Is_VMS; # protect uc switches |
8ebc5c01 |
64 | } |
65 | my($prog,$expected) = split(/\nEXPECT\n/, $_); |
66 | if ( $prog =~ /--FILE--/) { |
67 | my(@files) = split(/\n--FILE--\s*([^\s\n]*)\s*\n/, $prog) ; |
68 | shift @files ; |
69 | die "Internal error test $i didn't split into pairs, got " . |
70 | scalar(@files) . "[" . join("%%%%", @files) ."]\n" |
71 | if @files % 2 ; |
72 | while (@files > 2) { |
73 | my $filename = shift @files ; |
74 | my $code = shift @files ; |
75 | push @temps, $filename ; |
76 | open F, ">$filename" or die "Cannot open $filename: $!\n" ; |
77 | print F $code ; |
78 | close F ; |
79 | } |
80 | shift @files ; |
81 | $prog = shift @files ; |
82 | } |
44a8e56a |
83 | open TEST, ">$tmpfile"; |
84 | print TEST $prog,"\n"; |
8ebc5c01 |
85 | close TEST; |
44a8e56a |
86 | my $results = $Is_VMS ? |
f0963acb |
87 | `./perl "-I../lib" $switch $tmpfile 2>&1` : |
68dc0745 |
88 | $Is_MSWin32 ? |
89 | `.\\perl -I../lib $switch $tmpfile 2>&1` : |
0453d815 |
90 | `./perl -I../lib $switch $tmpfile 2>&1`; |
8ebc5c01 |
91 | my $status = $?; |
8ebc5c01 |
92 | $results =~ s/\n+$//; |
44a8e56a |
93 | # allow expected output to be written as if $prog is on STDIN |
94 | $results =~ s/tmp\d+/-/g; |
95 | $results =~ s/\n%[A-Z]+-[SIWEF]-.*$// if $Is_VMS; # clip off DCL status msg |
f0ec1f9a |
96 | # bison says 'parse error' instead of 'syntax error', |
2c88fa88 |
97 | # various yaccs may or may not capitalize 'syntax'. |
2a8ee232 |
98 | $results =~ s/^(syntax|parse) error/syntax error/mig; |
d33b2eba |
99 | # allow all tests to run when there are leaks |
100 | $results =~ s/Scalars leaked: \d+\n//g; |
8ebc5c01 |
101 | $expected =~ s/\n+$//; |
f0963acb |
102 | my $prefix = ($results =~ s#^PREFIX(\n|$)##) ; |
e5e1b98b |
103 | # any special options? (OPTIONS foo bar zap) |
104 | my $option_regex = 0; |
105 | if ($expected =~ s/^OPTIONS? (.+)\n//) { |
106 | foreach my $option (split(' ', $1)) { |
107 | if ($option eq 'regex') { # allow regular expressions |
108 | $option_regex = 1; |
109 | } else { |
110 | die "$0: Unknown OPTION '$option'\n"; |
111 | } |
112 | } |
113 | } |
8ebc5c01 |
114 | if ( $results =~ s/^SKIPPED\n//) { |
115 | print "$results\n" ; |
116 | } |
e5e1b98b |
117 | elsif (($prefix && (( $option_regex && $results !~ /^$expected/) || |
118 | (!$option_regex && $results !~ /^\Q$expected/))) or |
119 | (!$prefix && (( $option_regex && $results !~ /^$expected/) || |
120 | (!$option_regex && $results ne $expected)))) { |
8ebc5c01 |
121 | print STDERR "PROG: $switch\n$prog\n"; |
122 | print STDERR "EXPECTED:\n$expected\n"; |
123 | print STDERR "GOT:\n$results\n"; |
124 | print "not "; |
125 | } |
126 | print "ok ", ++$i, "\n"; |
127 | foreach (@temps) |
128 | { unlink $_ if $_ } |
129 | } |