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 GS |
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' ; | |
f180df80 | 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 | |
34ee6772 BF |
86 | use strict 'vars' ; |
87 | use utf8; | |
88 | use open qw( :utf8 :std ); | |
89 | { | |
90 | no strict ; | |
91 | $jòè = 1 ; | |
92 | } | |
93 | $jòè = 1 ; | |
94 | EXPECT | |
95 | Variable "$jòè" is not imported at - line 10. | |
96 | Global symbol "$jòè" requires explicit package name at - line 10. | |
97 | Execution of - aborted due to compilation errors. | |
98 | ######## | |
99 | ||
100 | # Check compile time scope of strict vars pragma | |
8ebc5c01 | 101 | no strict; |
102 | { | |
103 | use strict 'vars' ; | |
104 | $joe = 1 ; | |
105 | } | |
106 | $joe = 1 ; | |
107 | EXPECT | |
2c4aebbd | 108 | Global symbol "$joe" requires explicit package name at - line 6. |
8ebc5c01 | 109 | Execution of - aborted due to compilation errors. |
110 | ######## | |
111 | ||
112 | --FILE-- abc | |
113 | $joe = 1 ; | |
114 | 1; | |
115 | --FILE-- | |
116 | use strict 'vars' ; | |
117 | require "./abc"; | |
118 | EXPECT | |
119 | ||
120 | ######## | |
121 | ||
122 | --FILE-- abc | |
123 | use strict 'vars' ; | |
124 | 1; | |
125 | --FILE-- | |
126 | require "./abc"; | |
127 | $joe = 1 ; | |
128 | EXPECT | |
129 | ||
130 | ######## | |
131 | ||
132 | --FILE-- abc | |
133 | use strict 'vars' ; | |
134 | $joe = 1 ; | |
135 | 1; | |
136 | --FILE-- | |
137 | $joe = 1 ; | |
138 | require "./abc"; | |
139 | EXPECT | |
140 | Variable "$joe" is not imported at ./abc line 2. | |
2c4aebbd | 141 | Global symbol "$joe" requires explicit package name at ./abc line 2. |
7a2e2cd6 | 142 | Compilation failed in require at - line 2. |
8ebc5c01 | 143 | ######## |
144 | ||
34ee6772 BF |
145 | --FILE-- abc |
146 | use strict 'vars' ; | |
147 | use utf8; | |
148 | use open qw( :utf8 :std ); | |
149 | $jòè = 1 ; | |
150 | 1; | |
151 | --FILE-- | |
152 | use utf8; | |
153 | use open qw( :utf8 :std ); | |
154 | $jòè = 1 ; | |
155 | require "./abc"; | |
156 | EXPECT | |
157 | Variable "$jòè" is not imported at ./abc line 4. | |
158 | Global symbol "$jòè" requires explicit package name at ./abc line 4. | |
159 | Compilation failed in require at - line 4. | |
160 | ######## | |
161 | ||
8ebc5c01 | 162 | --FILE-- abc.pm |
163 | use strict 'vars' ; | |
164 | $joe = 1 ; | |
165 | 1; | |
166 | --FILE-- | |
167 | $joe = 1 ; | |
168 | use abc; | |
169 | EXPECT | |
170 | Variable "$joe" is not imported at abc.pm line 2. | |
2c4aebbd | 171 | Global symbol "$joe" requires explicit package name at abc.pm line 2. |
7a2e2cd6 | 172 | Compilation failed in require at - line 2. |
8ebc5c01 | 173 | BEGIN failed--compilation aborted at - line 2. |
174 | ######## | |
175 | ||
c7d6bfb2 | 176 | --FILE-- abc.pm |
34ee6772 BF |
177 | use strict 'vars' ; |
178 | use utf8; | |
179 | use open qw( :utf8 :std ); | |
180 | $jòè = 1 ; | |
181 | 1; | |
182 | --FILE-- | |
183 | use utf8; | |
184 | use open qw( :utf8 :std ); | |
185 | $jòè = 1 ; | |
186 | use abc; | |
187 | EXPECT | |
188 | Variable "$jòè" is not imported at abc.pm line 4. | |
189 | Global symbol "$jòè" requires explicit package name at abc.pm line 4. | |
190 | Compilation failed in require at - line 4. | |
191 | BEGIN failed--compilation aborted at - line 4. | |
192 | ######## | |
193 | ||
194 | --FILE-- abc.pm | |
c7d6bfb2 GS |
195 | package Burp; |
196 | use strict; | |
197 | $a = 1;$f = 1;$k = 1; # just to get beyond the limit... | |
198 | $b = 1;$g = 1;$l = 1; | |
199 | $c = 1;$h = 1;$m = 1; | |
200 | $d = 1;$i = 1;$n = 1; | |
201 | $e = 1;$j = 1;$o = 1; | |
202 | $p = 0b12; | |
203 | --FILE-- | |
204 | use abc; | |
205 | EXPECT | |
206 | Global symbol "$f" requires explicit package name at abc.pm line 3. | |
207 | Global symbol "$k" requires explicit package name at abc.pm line 3. | |
208 | Global symbol "$g" requires explicit package name at abc.pm line 4. | |
209 | Global symbol "$l" requires explicit package name at abc.pm line 4. | |
210 | Global symbol "$c" requires explicit package name at abc.pm line 5. | |
211 | Global symbol "$h" requires explicit package name at abc.pm line 5. | |
212 | Global symbol "$m" requires explicit package name at abc.pm line 5. | |
213 | Global symbol "$d" requires explicit package name at abc.pm line 6. | |
214 | Global symbol "$i" requires explicit package name at abc.pm line 6. | |
215 | Global symbol "$n" requires explicit package name at abc.pm line 6. | |
216 | Global symbol "$e" requires explicit package name at abc.pm line 7. | |
217 | Global symbol "$j" requires explicit package name at abc.pm line 7. | |
218 | Global symbol "$o" requires explicit package name at abc.pm line 7. | |
219 | Global symbol "$p" requires explicit package name at abc.pm line 8. | |
220 | Illegal binary digit '2' at abc.pm line 8, at end of line | |
221 | abc.pm has too many errors. | |
7f01dc7a JH |
222 | Compilation failed in require at - line 1. |
223 | BEGIN failed--compilation aborted at - line 1. | |
c7d6bfb2 GS |
224 | ######## |
225 | ||
8ebc5c01 | 226 | # Check scope of pragma with eval |
227 | no strict ; | |
228 | eval { | |
229 | $joe = 1 ; | |
230 | }; | |
231 | print STDERR $@; | |
232 | $joe = 1 ; | |
233 | EXPECT | |
234 | ||
235 | ######## | |
236 | ||
237 | # Check scope of pragma with eval | |
238 | no strict ; | |
239 | eval { | |
240 | use strict 'vars' ; | |
241 | $joe = 1 ; | |
242 | }; | |
243 | print STDERR $@; | |
244 | $joe = 1 ; | |
245 | EXPECT | |
2c4aebbd | 246 | Global symbol "$joe" requires explicit package name at - line 6. |
8ebc5c01 | 247 | Execution of - aborted due to compilation errors. |
248 | ######## | |
249 | ||
250 | # Check scope of pragma with eval | |
251 | use strict 'vars' ; | |
252 | eval { | |
253 | $joe = 1 ; | |
254 | }; | |
255 | print STDERR $@; | |
256 | $joe = 1 ; | |
257 | EXPECT | |
2c4aebbd | 258 | Global symbol "$joe" requires explicit package name at - line 5. |
5a844595 | 259 | Global symbol "$joe" requires explicit package name at - line 8. |
8ebc5c01 | 260 | Execution of - aborted due to compilation errors. |
261 | ######## | |
262 | ||
263 | # Check scope of pragma with eval | |
264 | use strict 'vars' ; | |
265 | eval { | |
266 | no strict ; | |
267 | $joe = 1 ; | |
268 | }; | |
269 | print STDERR $@; | |
270 | $joe = 1 ; | |
271 | EXPECT | |
272 | Variable "$joe" is not imported at - line 9. | |
2c4aebbd | 273 | Global symbol "$joe" requires explicit package name at - line 9. |
8ebc5c01 | 274 | Execution of - aborted due to compilation errors. |
275 | ######## | |
276 | ||
277 | # Check scope of pragma with eval | |
34ee6772 BF |
278 | use strict 'vars' ; |
279 | use utf8; | |
280 | use open qw( :utf8 :std ); | |
281 | eval { | |
282 | no strict ; | |
283 | $jòè = 1 ; | |
284 | }; | |
285 | print STDERR $@; | |
286 | $jòè = 1 ; | |
287 | EXPECT | |
288 | Variable "$jòè" is not imported at - line 11. | |
289 | Global symbol "$jòè" requires explicit package name at - line 11. | |
290 | Execution of - aborted due to compilation errors. | |
291 | ######## | |
292 | ||
293 | # Check scope of pragma with eval | |
8ebc5c01 | 294 | no strict ; |
295 | eval ' | |
296 | $joe = 1 ; | |
297 | '; print STDERR $@ ; | |
298 | $joe = 1 ; | |
299 | EXPECT | |
300 | ||
301 | ######## | |
302 | ||
303 | # Check scope of pragma with eval | |
304 | no strict ; | |
305 | eval q[ | |
306 | use strict 'vars' ; | |
307 | $joe = 1 ; | |
308 | ]; print STDERR $@; | |
309 | EXPECT | |
2c4aebbd | 310 | Global symbol "$joe" requires explicit package name at (eval 1) line 3. |
8ebc5c01 | 311 | ######## |
312 | ||
313 | # Check scope of pragma with eval | |
314 | use strict 'vars' ; | |
315 | eval ' | |
316 | $joe = 1 ; | |
317 | '; print STDERR $@ ; | |
318 | EXPECT | |
2c4aebbd | 319 | Global symbol "$joe" requires explicit package name at (eval 1) line 2. |
8ebc5c01 | 320 | ######## |
321 | ||
322 | # Check scope of pragma with eval | |
323 | use strict 'vars' ; | |
324 | eval ' | |
325 | no strict ; | |
326 | $joe = 1 ; | |
327 | '; print STDERR $@; | |
328 | $joe = 1 ; | |
329 | EXPECT | |
2c4aebbd | 330 | Global symbol "$joe" requires explicit package name at - line 8. |
8ebc5c01 | 331 | Execution of - aborted due to compilation errors. |
5a844595 GS |
332 | ######## |
333 | ||
334 | # Check if multiple evals produce same errors | |
335 | use strict 'vars'; | |
336 | my $ret = eval q{ print $x; }; | |
337 | print $@; | |
338 | print "ok 1\n" unless defined $ret; | |
339 | $ret = eval q{ print $x; }; | |
340 | print $@; | |
341 | print "ok 2\n" unless defined $ret; | |
342 | EXPECT | |
343 | Global symbol "$x" requires explicit package name at (eval 1) line 1. | |
344 | ok 1 | |
345 | Global symbol "$x" requires explicit package name at (eval 2) line 1. | |
346 | ok 2 | |
77ca0c92 LW |
347 | ######## |
348 | ||
349 | # strict vars with outer our - no error | |
350 | use strict 'vars' ; | |
351 | our $freddy; | |
352 | local $abc::joe ; | |
353 | my $fred ; | |
354 | my $b = \$fred ; | |
355 | $Fred::ABC = 1 ; | |
356 | $freddy = 2 ; | |
357 | EXPECT | |
358 | ||
359 | ######## | |
360 | ||
361 | # strict vars with inner our - no error | |
362 | use strict 'vars' ; | |
363 | sub foo { | |
364 | our $fred; | |
365 | $fred; | |
366 | } | |
367 | EXPECT | |
368 | ||
369 | ######## | |
370 | ||
371 | # strict vars with outer our, inner use - no error | |
372 | use strict 'vars' ; | |
373 | our $fred; | |
374 | sub foo { | |
375 | $fred; | |
376 | } | |
377 | EXPECT | |
378 | ||
379 | ######## | |
380 | ||
381 | # strict vars with nested our - no error | |
382 | use strict 'vars' ; | |
383 | our $fred; | |
384 | sub foo { | |
385 | our $fred; | |
386 | $fred; | |
387 | } | |
388 | $fred ; | |
389 | EXPECT | |
390 | ||
391 | ######## | |
392 | ||
393 | # strict vars with elapsed our - error | |
394 | use strict 'vars' ; | |
395 | sub foo { | |
396 | our $fred; | |
397 | $fred; | |
398 | } | |
399 | $fred ; | |
400 | EXPECT | |
401 | Variable "$fred" is not imported at - line 8. | |
402 | Global symbol "$fred" requires explicit package name at - line 8. | |
403 | Execution of - aborted due to compilation errors. | |
404 | ######## | |
405 | ||
34ee6772 BF |
406 | # strict vars with elapsed our - error |
407 | use strict 'vars' ; | |
408 | use utf8; | |
409 | use open qw( :utf8 :std ); | |
410 | sub fòò { | |
411 | our $frèd; | |
412 | $frèd; | |
413 | } | |
414 | $frèd ; | |
415 | EXPECT | |
416 | Variable "$frèd" is not imported at - line 10. | |
417 | Global symbol "$frèd" requires explicit package name at - line 10. | |
418 | Execution of - aborted due to compilation errors. | |
419 | ######## | |
420 | ||
77ca0c92 LW |
421 | # nested our with local - no error |
422 | $fred = 1; | |
423 | use strict 'vars'; | |
424 | { | |
425 | local our $fred = 2; | |
426 | print $fred,"\n"; | |
427 | } | |
428 | print our $fred,"\n"; | |
429 | EXPECT | |
430 | 2 | |
431 | 1 | |
f472eb5c GS |
432 | ######## |
433 | ||
434 | # "nailed" our declaration visibility across package boundaries | |
435 | use strict 'vars'; | |
436 | our $foo; | |
437 | $foo = 20; | |
438 | package Foo; | |
439 | print $foo, "\n"; | |
440 | EXPECT | |
441 | 20 | |
442 | ######## | |
443 | ||
444 | # multiple our declarations in same scope, different packages, no warning | |
445 | use strict 'vars'; | |
446 | use warnings; | |
447 | our $foo; | |
448 | ${foo} = 10; | |
449 | package Foo; | |
450 | our $foo = 20; | |
451 | print $foo, "\n"; | |
452 | EXPECT | |
453 | 20 | |
454 | ######## | |
455 | ||
7f73a9f1 | 456 | # multiple our declarations in same scope, same package, warning |
f472eb5c GS |
457 | use strict 'vars'; |
458 | use warnings; | |
459 | our $foo; | |
460 | ${foo} = 10; | |
461 | our $foo; | |
462 | EXPECT | |
7f73a9f1 | 463 | "our" variable $foo redeclared at - line 7. |
33633739 GS |
464 | ######## |
465 | ||
466 | # multiple our declarations in same scope, same package, warning | |
467 | use strict 'vars'; | |
468 | use warnings; | |
5ce0178e GS |
469 | { our $x = 1 } |
470 | { our $x = 0 } | |
33633739 GS |
471 | our $foo; |
472 | { | |
473 | our $foo; | |
7f73a9f1 | 474 | our $foo; |
33633739 GS |
475 | package Foo; |
476 | our $foo; | |
477 | } | |
478 | EXPECT | |
5ce0178e | 479 | "our" variable $foo redeclared at - line 9. |
cc507455 | 480 | (Did you mean "local" instead of "our"?) |
7f73a9f1 | 481 | "our" variable $foo redeclared at - line 10. |
8593bda5 GS |
482 | ######## |
483 | ||
f558d5af JH |
484 | --FILE-- abc |
485 | ok | |
486 | --FILE-- | |
487 | # check if our variables are introduced correctly in readline() | |
488 | package Foo; | |
489 | use strict 'vars'; | |
490 | our $FH; | |
491 | open $FH, "abc" or die "Can't open 'abc': $!"; | |
492 | print <$FH>; | |
493 | close $FH; | |
494 | EXPECT | |
495 | ok | |
496 | ######## | |
497 | ||
8593bda5 GS |
498 | # Make sure the strict vars failure still occurs |
499 | # now that the `@i should be written as \@i' failure does not occur | |
500 | # 20000522 mjd@plover.com (MJD) | |
501 | use strict 'vars'; | |
502 | no warnings; | |
503 | "@i_like_crackers"; | |
504 | EXPECT | |
505 | Global symbol "@i_like_crackers" requires explicit package name at - line 7. | |
506 | Execution of - aborted due to compilation errors. | |
d7aacf4e RGS |
507 | ######## |
508 | ||
509 | # [perl #21914] New bug > 5.8.0. Used to dump core. | |
510 | use strict 'vars'; | |
511 | @k = <$k>; | |
512 | EXPECT | |
513 | Global symbol "@k" requires explicit package name at - line 4. | |
514 | Global symbol "$k" requires explicit package name at - line 4. | |
515 | Execution of - aborted due to compilation errors. | |
35d90494 RGS |
516 | ######## |
517 | # [perl #26910] hints not propagated into (?{...}) | |
518 | use strict 'vars'; | |
519 | qr/(?{$foo++})/; | |
520 | EXPECT | |
521 | Global symbol "$foo" requires explicit package name at (re_eval 1) line 1. | |
522 | Compilation failed in regexp at - line 3. | |
413ff9f6 | 523 | ######## |
34ee6772 BF |
524 | # Regex compilation errors weren't UTF-8 clean. |
525 | use strict 'vars'; | |
526 | use utf8; | |
527 | use open qw( :utf8 :std ); | |
528 | qr/(?{$fòò++})/; | |
529 | EXPECT | |
530 | Global symbol "$fòò" requires explicit package name at (re_eval 1) line 1. | |
531 | Compilation failed in regexp at - line 5. | |
532 | ######## | |
93f09d7b | 533 | # [perl #73712] 'Variable is not imported' should be suppressible |
413ff9f6 FC |
534 | $dweck; |
535 | use strict 'vars'; | |
536 | no warnings; | |
537 | eval q/$dweck/; | |
538 | EXPECT |