Commit | Line | Data |
---|---|---|
b82b06b8 FC |
1 | #!perl |
2 | ||
3 | # Basic tests for $[ as a variable | |
41e1edf5 | 4 | # plus miscellaneous bug fix tests |
b82b06b8 | 5 | |
36b2db7e | 6 | no warnings 'deprecated'; |
b82b06b8 FC |
7 | use Test::More tests => 7; |
8 | ||
9 | sub outside_base_scope { return "${'['}" } | |
10 | ||
11 | $[ = 3; | |
12 | my $base = \$[; | |
13 | is "$$base", 3, 'retval of $['; | |
14 | is outside_base_scope, 0, 'retval of $[ outside its scope'; | |
15 | ||
16 | ${'['} = 3; | |
17 | pass('run-time $[ = 3 assignment (in $[ = 3 scope)'); | |
18 | { | |
19 | $[ = 0; | |
20 | ${'['} = 0; | |
21 | pass('run-time $[ = 0 assignment (in $[ = 3 scope)'); | |
22 | } | |
23 | ||
24 | eval { ${'['} = 1 }; my $f = __FILE__; my $l = __LINE__; | |
25 | is $@, "That use of \$[ is unsupported at $f line $l.\n", | |
26 | "error when setting $[ to integer other than current base at run-time"; | |
27 | ||
28 | $[ = 6.7; | |
29 | is "$[", 6, '$[ is an integer'; | |
30 | ||
31 | eval { my $x = 45; $[ = \$x }; $l = __LINE__; | |
32 | is $@, "That use of \$[ is unsupported at $f line $l.\n", | |
33 | 'error when setting $[ to ref'; | |
34 | ||
41e1edf5 FC |
35 | sub foo { my $x; $x = wait } # compilation of this routine used to crash |
36 | ||
b82b06b8 | 37 | 1; |