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