source: trunk/essentials/dev-lang/perl/t/lib/strict/vars

Last change on this file was 3181, checked in by bird, 19 years ago

perl 5.8.8

File size: 8.3 KB
Line 
1Check strict vars functionality
2
3__END__
4
5# no strict, should build & run ok.
6Fred ;
7my $fred ;
8$b = "fred" ;
9$a = $$b ;
10EXPECT
11
12########
13
14use strict qw(subs refs) ;
15$fred ;
16EXPECT
17
18########
19
20use strict ;
21no strict 'vars' ;
22$fred ;
23EXPECT
24
25########
26
27# strict vars - no error
28use strict 'vars' ;
29use vars qw( $freddy) ;
30BEGIN { *freddy = \$joe::shmoe; }
31$freddy = 2 ;
32EXPECT
33
34########
35
36# strict vars - no error
37use strict 'vars' ;
38use vars qw( $freddy) ;
39local $abc::joe ;
40my $fred ;
41my $b = \$fred ;
42$Fred::ABC = 1 ;
43$freddy = 2 ;
44EXPECT
45
46########
47
48# strict vars - error
49use strict ;
50$fred ;
51EXPECT
52Global symbol "$fred" requires explicit package name at - line 4.
53Execution of - aborted due to compilation errors.
54########
55
56# strict vars - error
57use strict 'vars' ;
58<$fred> ;
59EXPECT
60Global symbol "$fred" requires explicit package name at - line 4.
61Execution of - aborted due to compilation errors.
62########
63
64# strict vars - error
65use strict 'vars' ;
66local $fred ;
67EXPECT
68Global symbol "$fred" requires explicit package name at - line 4.
69Execution of - aborted due to compilation errors.
70########
71
72# Check compile time scope of strict vars pragma
73use strict 'vars' ;
74{
75 no strict ;
76 $joe = 1 ;
77}
78$joe = 1 ;
79EXPECT
80Variable "$joe" is not imported at - line 8.
81Global symbol "$joe" requires explicit package name at - line 8.
82Execution of - aborted due to compilation errors.
83########
84
85# Check compile time scope of strict vars pragma
86no strict;
87{
88 use strict 'vars' ;
89 $joe = 1 ;
90}
91$joe = 1 ;
92EXPECT
93Global symbol "$joe" requires explicit package name at - line 6.
94Execution of - aborted due to compilation errors.
95########
96
97--FILE-- abc
98$joe = 1 ;
991;
100--FILE--
101use strict 'vars' ;
102require "./abc";
103EXPECT
104
105########
106
107--FILE-- abc
108use strict 'vars' ;
1091;
110--FILE--
111require "./abc";
112$joe = 1 ;
113EXPECT
114
115########
116
117--FILE-- abc
118use strict 'vars' ;
119$joe = 1 ;
1201;
121--FILE--
122$joe = 1 ;
123require "./abc";
124EXPECT
125Variable "$joe" is not imported at ./abc line 2.
126Global symbol "$joe" requires explicit package name at ./abc line 2.
127Compilation failed in require at - line 2.
128########
129
130--FILE-- abc.pm
131use strict 'vars' ;
132$joe = 1 ;
1331;
134--FILE--
135$joe = 1 ;
136use abc;
137EXPECT
138Variable "$joe" is not imported at abc.pm line 2.
139Global symbol "$joe" requires explicit package name at abc.pm line 2.
140Compilation failed in require at - line 2.
141BEGIN failed--compilation aborted at - line 2.
142########
143
144--FILE-- abc.pm
145package Burp;
146use strict;
147$a = 1;$f = 1;$k = 1; # just to get beyond the limit...
148$b = 1;$g = 1;$l = 1;
149$c = 1;$h = 1;$m = 1;
150$d = 1;$i = 1;$n = 1;
151$e = 1;$j = 1;$o = 1;
152$p = 0b12;
153--FILE--
154use abc;
155EXPECT
156Global symbol "$f" requires explicit package name at abc.pm line 3.
157Global symbol "$k" requires explicit package name at abc.pm line 3.
158Global symbol "$g" requires explicit package name at abc.pm line 4.
159Global symbol "$l" requires explicit package name at abc.pm line 4.
160Global symbol "$c" requires explicit package name at abc.pm line 5.
161Global symbol "$h" requires explicit package name at abc.pm line 5.
162Global symbol "$m" requires explicit package name at abc.pm line 5.
163Global symbol "$d" requires explicit package name at abc.pm line 6.
164Global symbol "$i" requires explicit package name at abc.pm line 6.
165Global symbol "$n" requires explicit package name at abc.pm line 6.
166Global symbol "$e" requires explicit package name at abc.pm line 7.
167Global symbol "$j" requires explicit package name at abc.pm line 7.
168Global symbol "$o" requires explicit package name at abc.pm line 7.
169Global symbol "$p" requires explicit package name at abc.pm line 8.
170Illegal binary digit '2' at abc.pm line 8, at end of line
171abc.pm has too many errors.
172Compilation failed in require at - line 1.
173BEGIN failed--compilation aborted at - line 1.
174########
175
176# Check scope of pragma with eval
177no strict ;
178eval {
179 $joe = 1 ;
180};
181print STDERR $@;
182$joe = 1 ;
183EXPECT
184
185########
186
187# Check scope of pragma with eval
188no strict ;
189eval {
190 use strict 'vars' ;
191 $joe = 1 ;
192};
193print STDERR $@;
194$joe = 1 ;
195EXPECT
196Global symbol "$joe" requires explicit package name at - line 6.
197Execution of - aborted due to compilation errors.
198########
199
200# Check scope of pragma with eval
201use strict 'vars' ;
202eval {
203 $joe = 1 ;
204};
205print STDERR $@;
206$joe = 1 ;
207EXPECT
208Global symbol "$joe" requires explicit package name at - line 5.
209Global symbol "$joe" requires explicit package name at - line 8.
210Execution of - aborted due to compilation errors.
211########
212
213# Check scope of pragma with eval
214use strict 'vars' ;
215eval {
216 no strict ;
217 $joe = 1 ;
218};
219print STDERR $@;
220$joe = 1 ;
221EXPECT
222Variable "$joe" is not imported at - line 9.
223Global symbol "$joe" requires explicit package name at - line 9.
224Execution of - aborted due to compilation errors.
225########
226
227# Check scope of pragma with eval
228no strict ;
229eval '
230 $joe = 1 ;
231'; print STDERR $@ ;
232$joe = 1 ;
233EXPECT
234
235########
236
237# Check scope of pragma with eval
238no strict ;
239eval q[