Commit | Line | Data |
8ebc5c01 |
1 | #!./perl |
2 | |
3 | BEGIN { |
4 | chdir 't' if -d 't'; |
5 | @INC = '../lib'; |
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 ? |
49 | `MCR $^X $switch $tmpfile` : |
68dc0745 |
50 | $Is_MSWin32 ? |
51 | `.\\perl -I../lib $switch $tmpfile 2>&1` : |
44a8e56a |
52 | `sh -c './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 |
9d116dd7 |
58 | $results =~ s/Syntax/syntax/; # non-standard yacc |
8ebc5c01 |
59 | $expected =~ s/\n+$//; |
60 | my $prefix = ($results =~ s/^PREFIX\n//) ; |
61 | if ( $results =~ s/^SKIPPED\n//) { |
62 | print "$results\n" ; |
63 | } |
64 | elsif (($prefix and $results !~ /^\Q$expected/) or |
65 | (!$prefix and $results ne $expected)){ |
66 | print STDERR "PROG: $switch\n$prog\n"; |
67 | print STDERR "EXPECTED:\n$expected\n"; |
68 | print STDERR "GOT:\n$results\n"; |
69 | print "not "; |
70 | } |
71 | print "ok ", ++$i, "\n"; |
72 | foreach (@temps) |
73 | { unlink $_ if $_ } |
74 | } |
75 | |
76 | __END__ |
77 | |
78 | # Error - not predeclaring a sub |
79 | Fred 1,2 ; |
80 | sub Fred {} |
81 | EXPECT |
82 | Number found where operator expected at - line 3, near "Fred 1" |
83 | (Do you need to predeclare Fred?) |
84 | syntax error at - line 3, near "Fred 1" |
85 | Execution of - aborted due to compilation errors. |
86 | ######## |
87 | |
88 | # Error - not predeclaring a sub in time |
89 | Fred 1,2 ; |
90 | use subs qw( Fred ) ; |
91 | sub Fred {} |
92 | EXPECT |
93 | Number found where operator expected at - line 3, near "Fred 1" |
94 | (Do you need to predeclare Fred?) |
95 | syntax error at - line 3, near "Fred 1" |
68dc0745 |
96 | BEGIN not safe after errors--compilation aborted at - line 4. |
8ebc5c01 |
97 | ######## |
98 | |
99 | # AOK |
100 | use subs qw( Fred) ; |
101 | Fred 1,2 ; |
102 | sub Fred { print $_[0] + $_[1], "\n" } |
103 | EXPECT |
104 | 3 |
105 | ######## |
106 | |
107 | # override a built-in function |
108 | use subs qw( open ) ; |
109 | open 1,2 ; |
110 | sub open { print $_[0] + $_[1], "\n" } |
111 | EXPECT |
112 | 3 |
113 | ######## |
114 | |
115 | --FILE-- abc |
116 | Fred 1,2 ; |
117 | 1; |
118 | --FILE-- |
119 | use subs qw( Fred ) ; |
120 | require "./abc" ; |
121 | sub Fred { print $_[0] + $_[1], "\n" } |
122 | EXPECT |
123 | 3 |
124 | ######## |
125 | |
126 | # check that it isn't affected by block scope |
127 | { |
128 | use subs qw( Fred ) ; |
129 | } |
130 | Fred 1, 2; |
131 | sub Fred { print $_[0] + $_[1], "\n" } |
132 | EXPECT |
133 | 3 |