Commit | Line | Data |
8ebc5c01 |
1 | #!./perl |
2 | |
3 | BEGIN { |
4 | chdir 't' if -d 't'; |
20822f61 |
5 | @INC = '../lib'; |
8ebc5c01 |
6 | $ENV{PERL5LIB} = '../lib'; |
0642d82a |
7 | require './test.pl'; |
8ebc5c01 |
8 | } |
9 | |
10 | $| = 1; |
11 | undef $/; |
12 | my @prgs = split "\n########\n", <DATA>; |
13 | print "1..", scalar @prgs, "\n"; |
14 | |
44a8e56a |
15 | my $Is_VMS = $^O eq 'VMS'; |
68dc0745 |
16 | my $Is_MSWin32 = $^O eq 'MSWin32'; |
2986a63f |
17 | my $Is_NetWare = $^O eq 'NetWare'; |
8ebc5c01 |
18 | my $i = 0 ; |
8ebc5c01 |
19 | |
20 | for (@prgs){ |
21 | my $switch = ""; |
22 | my @temps = () ; |
23 | if (s/^\s*-\w+//){ |
24 | $switch = $&; |
25 | } |
26 | my($prog,$expected) = split(/\nEXPECT\n/, $_); |
27 | if ( $prog =~ /--FILE--/) { |
28 | my(@files) = split(/\n--FILE--\s*([^\s\n]*)\s*\n/, $prog) ; |
29 | shift @files ; |
30 | die "Internal error test $i didn't split into pairs, got " . |
31 | scalar(@files) . "[" . join("%%%%", @files) ."]\n" |
32 | if @files % 2 ; |
33 | while (@files > 2) { |
34 | my $filename = shift @files ; |
35 | my $code = shift @files ; |
36 | push @temps, $filename ; |
37 | open F, ">$filename" or die "Cannot open $filename: $!\n" ; |
38 | print F $code ; |
39 | close F ; |
40 | } |
41 | shift @files ; |
42 | $prog = shift @files ; |
43 | } |
f89542f7 |
44 | my $tmpfile = tempfile(); |
44a8e56a |
45 | open TEST, ">$tmpfile"; |
46 | print TEST $prog,"\n"; |
8ebc5c01 |
47 | close TEST; |
44a8e56a |
48 | my $results = $Is_VMS ? |
be708cc0 |
49 | `./perl $switch $tmpfile 2>&1` : |
68dc0745 |
50 | $Is_MSWin32 ? |
be708cc0 |
51 | `.\\perl -I../lib $switch $tmpfile 2>&1` : |
2986a63f |
52 | $Is_NetWare ? |
be708cc0 |
53 | `perl -I../lib $switch $tmpfile 2>&1` : |
648cac19 |
54 | `./perl $switch $tmpfile 2>&1`; |
8ebc5c01 |
55 | my $status = $?; |
8ebc5c01 |
56 | $results =~ s/\n+$//; |
44a8e56a |
57 | # allow expected output to be written as if $prog is on STDIN |
0642d82a |
58 | $results =~ s/tmp\d+[A-Z][A-Z]?/-/g; |
44a8e56a |
59 | $results =~ s/\n%[A-Z]+-[SIWEF]-.*$// if $Is_VMS; # clip off DCL status msg |
f0ec1f9a |
60 | # bison says 'parse error' instead of 'syntax error', |
d91e2bdb |
61 | # various yaccs may or may not capitalize 'syntax'. |
2a8ee232 |
62 | $results =~ s/^(syntax|parse) error/syntax error/mig; |
8ebc5c01 |
63 | $expected =~ s/\n+$//; |
64 | my $prefix = ($results =~ s/^PREFIX\n//) ; |
65 | if ( $results =~ s/^SKIPPED\n//) { |
66 | print "$results\n" ; |
67 | } |
68 | elsif (($prefix and $results !~ /^\Q$expected/) or |
69 | (!$prefix and $results ne $expected)){ |
70 | print STDERR "PROG: $switch\n$prog\n"; |
71 | print STDERR "EXPECTED:\n$expected\n"; |
72 | print STDERR "GOT:\n$results\n"; |
73 | print "not "; |
74 | } |
75 | print "ok ", ++$i, "\n"; |
76 | foreach (@temps) |
77 | { unlink $_ if $_ } |
78 | } |
79 | |
80 | __END__ |
81 | |
82 | # Error - not predeclaring a sub |
83 | Fred 1,2 ; |
84 | sub Fred {} |
85 | EXPECT |
86 | Number found where operator expected at - line 3, near "Fred 1" |
87 | (Do you need to predeclare Fred?) |
88 | syntax error at - line 3, near "Fred 1" |
89 | Execution of - aborted due to compilation errors. |
90 | ######## |
91 | |
92 | # Error - not predeclaring a sub in time |
93 | Fred 1,2 ; |
94 | use subs qw( Fred ) ; |
95 | sub Fred {} |
96 | EXPECT |
97 | Number found where operator expected at - line 3, near "Fred 1" |
98 | (Do you need to predeclare Fred?) |
99 | syntax error at - line 3, near "Fred 1" |
68dc0745 |
100 | BEGIN not safe after errors--compilation aborted at - line 4. |
8ebc5c01 |
101 | ######## |
102 | |
103 | # AOK |
104 | use subs qw( Fred) ; |
105 | Fred 1,2 ; |
106 | sub Fred { print $_[0] + $_[1], "\n" } |
107 | EXPECT |
108 | 3 |
109 | ######## |
110 | |
111 | # override a built-in function |
112 | use subs qw( open ) ; |
113 | open 1,2 ; |
114 | sub open { print $_[0] + $_[1], "\n" } |
115 | EXPECT |
116 | 3 |
117 | ######## |
118 | |
55a105fd |
119 | # override a built-in function, call after definition |
120 | use subs qw( open ) ; |
121 | sub open { print $_[0] + $_[1], "\n" } |
122 | open 1,2 ; |
123 | EXPECT |
124 | 3 |
125 | ######## |
126 | |
127 | # override a built-in function, call with () |
128 | use subs qw( open ) ; |
129 | open (1,2) ; |
130 | sub open { print $_[0] + $_[1], "\n" } |
131 | EXPECT |
132 | 3 |
133 | ######## |
134 | |
135 | # override a built-in function, call with () after definition |
136 | use subs qw( open ) ; |
137 | sub open { print $_[0] + $_[1], "\n" } |
138 | open (1,2) ; |
139 | EXPECT |
140 | 3 |
141 | ######## |
142 | |
8ebc5c01 |
143 | --FILE-- abc |
144 | Fred 1,2 ; |
145 | 1; |
146 | --FILE-- |
147 | use subs qw( Fred ) ; |
148 | require "./abc" ; |
149 | sub Fred { print $_[0] + $_[1], "\n" } |
150 | EXPECT |
151 | 3 |
152 | ######## |
153 | |
154 | # check that it isn't affected by block scope |
155 | { |
156 | use subs qw( Fred ) ; |
157 | } |
158 | Fred 1, 2; |
159 | sub Fred { print $_[0] + $_[1], "\n" } |
160 | EXPECT |
161 | 3 |