Commit | Line | Data |
8ebc5c01 |
1 | Check strict vars functionality |
2 | |
3 | __END__ |
4 | |
5 | # no strict, should build & run ok. |
6 | Fred ; |
7 | my $fred ; |
8 | $b = "fred" ; |
9 | $a = $$b ; |
10 | EXPECT |
11 | |
12 | ######## |
13 | |
14 | use strict qw(subs refs) ; |
15 | $fred ; |
16 | EXPECT |
17 | |
18 | ######## |
19 | |
20 | use strict ; |
21 | no strict 'vars' ; |
22 | $fred ; |
23 | EXPECT |
24 | |
25 | ######## |
26 | |
27 | # strict vars - no error |
28 | use strict 'vars' ; |
29 | use vars qw( $freddy) ; |
39bac7f7 |
30 | BEGIN { *freddy = \$joe::shmoe; } |
31 | $freddy = 2 ; |
32 | EXPECT |
33 | |
34 | ######## |
35 | |
36 | # strict vars - no error |
37 | use strict 'vars' ; |
38 | use vars qw( $freddy) ; |
8ebc5c01 |
39 | local $abc::joe ; |
40 | my $fred ; |
41 | my $b = \$fred ; |
42 | $Fred::ABC = 1 ; |
43 | $freddy = 2 ; |
44 | EXPECT |
45 | |
46 | ######## |
47 | |
48 | # strict vars - error |
49 | use strict ; |
50 | $fred ; |
51 | EXPECT |
2c4aebbd |
52 | Global symbol "$fred" requires explicit package name at - line 4. |
8ebc5c01 |
53 | Execution of - aborted due to compilation errors. |
54 | ######## |
55 | |
56 | # strict vars - error |
57 | use strict 'vars' ; |
92d29cee |
58 | <$fred> ; |
8ebc5c01 |
59 | EXPECT |
2c4aebbd |
60 | Global symbol "$fred" requires explicit package name at - line 4. |
8ebc5c01 |
61 | Execution of - aborted due to compilation errors. |
62 | ######## |
63 | |
64 | # strict vars - error |
65 | use strict 'vars' ; |
66 | local $fred ; |
67 | EXPECT |
2c4aebbd |
68 | Global symbol "$fred" requires explicit package name at - line 4. |
8ebc5c01 |
69 | Execution of - aborted due to compilation errors. |
70 | ######## |
71 | |
72 | # Check compile time scope of strict vars pragma |
73 | use strict 'vars' ; |
74 | { |
75 | no strict ; |
76 | $joe = 1 ; |
77 | } |
78 | $joe = 1 ; |
79 | EXPECT |
80 | Variable "$joe" is not imported at - line 8. |
2c4aebbd |
81 | Global symbol "$joe" requires explicit package name at - line 8. |
8ebc5c01 |
82 | Execution of - aborted due to compilation errors. |
83 | ######## |
84 | |
85 | # Check compile time scope of strict vars pragma |
86 | no strict; |
87 | { |
88 | use strict 'vars' ; |
89 | $joe = 1 ; |
90 | } |
91 | $joe = 1 ; |
92 | EXPECT |
2c4aebbd |
93 | Global symbol "$joe" requires explicit package name at - line 6. |
8ebc5c01 |
94 | Execution of - aborted due to compilation errors. |
95 | ######## |
96 | |
97 | --FILE-- abc |
98 | $joe = 1 ; |
99 | 1; |
100 | --FILE-- |
101 | use strict 'vars' ; |
102 | require "./abc"; |
103 | EXPECT |
104 | |
105 | ######## |
106 | |
107 | --FILE-- abc |
108 | use strict 'vars' ; |
109 | 1; |
110 | --FILE-- |
111 | require "./abc"; |
112 | $joe = 1 ; |
113 | EXPECT |
114 | |
115 | ######## |
116 | |
117 | --FILE-- abc |
118 | use strict 'vars' ; |
119 | $joe = 1 ; |
120 | 1; |
121 | --FILE-- |
122 | $joe = 1 ; |
123 | require "./abc"; |
124 | EXPECT |
125 | Variable "$joe" is not imported at ./abc line 2. |
2c4aebbd |
126 | Global symbol "$joe" requires explicit package name at ./abc line 2. |
7a2e2cd6 |
127 | Compilation failed in require at - line 2. |
8ebc5c01 |
128 | ######## |
129 | |
130 | --FILE-- abc.pm |
131 | use strict 'vars' ; |
132 | $joe = 1 ; |
133 | 1; |
134 | --FILE-- |
135 | $joe = 1 ; |
136 | use abc; |
137 | EXPECT |
138 | Variable "$joe" is not imported at abc.pm line 2. |
2c4aebbd |
139 | Global symbol "$joe" requires explicit package name at abc.pm line 2. |
7a2e2cd6 |
140 | Compilation failed in require at - line 2. |
8ebc5c01 |
141 | BEGIN failed--compilation aborted at - line 2. |
142 | ######## |
143 | |
c7d6bfb2 |
144 | --FILE-- abc.pm |
145 | package Burp; |
146 | use 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-- |
8f58c2e7 |
154 | # known scalar leak |
155 | BEGIN { $ENV{PERL_DESTRUCT_LEVEL} = 0 unless $ENV{PERL_DESTRUCT_LEVEL} > 3; } |
c7d6bfb2 |
156 | use abc; |
157 | EXPECT |
158 | Global symbol "$f" requires explicit package name at abc.pm line 3. |
159 | Global symbol "$k" requires explicit package name at abc.pm line 3. |
160 | Global symbol "$g" requires explicit package name at abc.pm line 4. |
161 | Global symbol "$l" requires explicit package name at abc.pm line 4. |
162 | Global symbol "$c" requires explicit package name at abc.pm line 5. |
163 | Global symbol "$h" requires explicit package name at abc.pm line 5. |
164 | Global symbol "$m" requires explicit package name at abc.pm line 5. |
165 | Global symbol "$d" requires explicit package name at abc.pm line 6. |
166 | Global symbol "$i" requires explicit package name at abc.pm line 6. |
167 | Global symbol "$n" requires explicit package name at abc.pm line 6. |
168 | Global symbol "$e" requires explicit package name at abc.pm line 7. |
169 | Global symbol "$j" requires explicit package name at abc.pm line 7. |
170 | Global symbol "$o" requires explicit package name at abc.pm line 7. |
171 | Global symbol "$p" requires explicit package name at abc.pm line 8. |
172 | Illegal binary digit '2' at abc.pm line 8, at end of line |
173 | abc.pm has too many errors. |
8f58c2e7 |
174 | Compilation failed in require at - line 3. |
175 | BEGIN failed--compilation aborted at - line 3. |
c7d6bfb2 |
176 | ######## |
177 | |
8ebc5c01 |
178 | # Check scope of pragma with eval |
179 | no strict ; |
180 | eval { |
181 | $joe = 1 ; |
182 | }; |
183 | print STDERR $@; |
184 | $joe = 1 ; |
185 | EXPECT |
186 | |
187 | ######## |
188 | |
189 | # Check scope of pragma with eval |
190 | no strict ; |
191 | eval { |
192 | use strict 'vars' ; |
193 | $joe = 1 ; |
194 | }; |
195 | print STDERR $@; |
196 | $joe = 1 ; |
197 | EXPECT |
2c4aebbd |
198 | Global symbol "$joe" requires explicit package name at - line 6. |
8ebc5c01 |
199 | Execution of - aborted due to compilation errors. |
200 | ######## |
201 | |
202 | # Check scope of pragma with eval |
203 | use strict 'vars' ; |
204 | eval { |
205 | $joe = 1 ; |
206 | }; |
207 | print STDERR $@; |
208 | $joe = 1 ; |
209 | EXPECT |
2c4aebbd |
210 | Global symbol "$joe" requires explicit package name at - line 5. |
5a844595 |
211 | Global symbol "$joe" requires explicit package name at - line 8. |
8ebc5c01 |
212 | Execution of - aborted due to compilation errors. |
213 | ######## |
214 | |
215 | # Check scope of pragma with eval |
216 | use strict 'vars' ; |
217 | eval { |
218 | no strict ; |
219 | $joe = 1 ; |
220 | }; |
221 | print STDERR $@; |
222 | $joe = 1 ; |
223 | EXPECT |
224 | Variable "$joe" is not imported at - line 9. |
2c4aebbd |
225 | Global symbol "$joe" requires explicit package name at - line 9. |
8ebc5c01 |
226 | Execution of - aborted due to compilation errors. |
227 | ######## |
228 | |
229 | # Check scope of pragma with eval |
230 | no strict ; |
231 | eval ' |
232 | $joe = 1 ; |
233 | '; print STDERR $@ ; |
234 | $joe = 1 ; |
235 | EXPECT |
236 | |
237 | ######## |
238 | |
239 | # Check scope of pragma with eval |
240 | no strict ; |
241 | eval q[ |
242 | use strict 'vars' ; |
243 | $joe = 1 ; |
244 | ]; print STDERR $@; |
245 | EXPECT |
2c4aebbd |
246 | Global symbol "$joe" requires explicit package name at (eval 1) line 3. |
8ebc5c01 |
247 | ######## |
248 | |
249 | # Check scope of pragma with eval |
250 | use strict 'vars' ; |
251 | eval ' |
252 | $joe = 1 ; |
253 | '; print STDERR $@ ; |
254 | EXPECT |
2c4aebbd |
255 | Global symbol "$joe" requires explicit package name at (eval 1) line 2. |
8ebc5c01 |
256 | ######## |
257 | |
258 | # Check scope of pragma with eval |
259 | use strict 'vars' ; |
260 | eval ' |
261 | no strict ; |
262 | $joe = 1 ; |
263 | '; print STDERR $@; |
264 | $joe = 1 ; |
265 | EXPECT |
2c4aebbd |
266 | Global symbol "$joe" requires explicit package name at - line 8. |
8ebc5c01 |
267 | Execution of - aborted due to compilation errors. |
5a844595 |
268 | ######## |
269 | |
270 | # Check if multiple evals produce same errors |
271 | use strict 'vars'; |
272 | my $ret = eval q{ print $x; }; |
273 | print $@; |
274 | print "ok 1\n" unless defined $ret; |
275 | $ret = eval q{ print $x; }; |
276 | print $@; |
277 | print "ok 2\n" unless defined $ret; |
278 | EXPECT |
279 | Global symbol "$x" requires explicit package name at (eval 1) line 1. |
280 | ok 1 |
281 | Global symbol "$x" requires explicit package name at (eval 2) line 1. |
282 | ok 2 |
77ca0c92 |
283 | ######## |
284 | |
285 | # strict vars with outer our - no error |
286 | use strict 'vars' ; |
287 | our $freddy; |
288 | local $abc::joe ; |
289 | my $fred ; |
290 | my $b = \$fred ; |
291 | $Fred::ABC = 1 ; |
292 | $freddy = 2 ; |
293 | EXPECT |
294 | |
295 | ######## |
296 | |
297 | # strict vars with inner our - no error |
298 | use strict 'vars' ; |
299 | sub foo { |
300 | our $fred; |
301 | $fred; |
302 | } |
303 | EXPECT |
304 | |
305 | ######## |
306 | |
307 | # strict vars with outer our, inner use - no error |
308 | use strict 'vars' ; |
309 | our $fred; |
310 | sub foo { |
311 | $fred; |
312 | } |
313 | EXPECT |
314 | |
315 | ######## |
316 | |
317 | # strict vars with nested our - no error |
318 | use strict 'vars' ; |
319 | our $fred; |
320 | sub foo { |
321 | our $fred; |
322 | $fred; |
323 | } |
324 | $fred ; |
325 | EXPECT |
326 | |
327 | ######## |
328 | |
329 | # strict vars with elapsed our - error |
330 | use strict 'vars' ; |
331 | sub foo { |
332 | our $fred; |
333 | $fred; |
334 | } |
335 | $fred ; |
336 | EXPECT |
337 | Variable "$fred" is not imported at - line 8. |
338 | Global symbol "$fred" requires explicit package name at - line 8. |
339 | Execution of - aborted due to compilation errors. |
340 | ######## |
341 | |
342 | # nested our with local - no error |
343 | $fred = 1; |
344 | use strict 'vars'; |
345 | { |
346 | local our $fred = 2; |
347 | print $fred,"\n"; |
348 | } |
349 | print our $fred,"\n"; |
350 | EXPECT |
351 | 2 |
352 | 1 |
f472eb5c |
353 | ######## |
354 | |
355 | # "nailed" our declaration visibility across package boundaries |
356 | use strict 'vars'; |
357 | our $foo; |
358 | $foo = 20; |
359 | package Foo; |
360 | print $foo, "\n"; |
361 | EXPECT |
362 | 20 |
363 | ######## |
364 | |
365 | # multiple our declarations in same scope, different packages, no warning |
366 | use strict 'vars'; |
367 | use warnings; |
368 | our $foo; |
369 | ${foo} = 10; |
370 | package Foo; |
371 | our $foo = 20; |
372 | print $foo, "\n"; |
373 | EXPECT |
374 | 20 |
375 | ######## |
376 | |
377 | # multiple our declarations in same scope, same package, warning |
378 | use strict 'vars'; |
379 | use warnings; |
380 | our $foo; |
381 | ${foo} = 10; |
382 | our $foo; |
383 | EXPECT |
384 | "our" variable $foo masks earlier declaration in same scope at - line 7. |
33633739 |
385 | ######## |
386 | |
387 | # multiple our declarations in same scope, same package, warning |
388 | use strict 'vars'; |
389 | use warnings; |
390 | our $foo; |
391 | { |
392 | our $foo; |
393 | package Foo; |
394 | our $foo; |
395 | } |
396 | EXPECT |
397 | "our" variable $foo redeclared at - line 7. |
cc507455 |
398 | (Did you mean "local" instead of "our"?) |
33633739 |
399 | Name "Foo::foo" used only once: possible typo at - line 9. |