This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Test $x=wait under arybase
[perl5.git] / ext / arybase / t / arybase.t
1 #!perl
2
3 # Basic tests for $[ as a variable
4 # plus miscellaneous bug fix tests
5
6 use Test::More tests => 7;
7
8 sub outside_base_scope { return "${'['}" }
9
10 $[ = 3;
11 my $base = \$[;
12 is "$$base", 3, 'retval of $[';
13 is outside_base_scope, 0, 'retval of $[ outside its scope';
14
15 ${'['} = 3;
16 pass('run-time $[ = 3 assignment (in $[ = 3 scope)');
17 {
18   $[ = 0;
19   ${'['} = 0;
20   pass('run-time $[ = 0 assignment (in $[ = 3 scope)');
21 }
22
23 eval { ${'['} = 1 }; my $f = __FILE__; my $l = __LINE__;
24 is $@, "That use of \$[ is unsupported at $f line $l.\n",
25    "error when setting $[ to integer other than current base at run-time";
26
27 $[ = 6.7;
28 is "$[", 6, '$[ is an integer';
29
30 eval { my $x = 45; $[ = \$x }; $l = __LINE__;
31 is $@, "That use of \$[ is unsupported at $f line $l.\n",
32    'error when setting $[ to ref';
33
34 sub foo { my $x; $x = wait } # compilation of this routine used to crash
35
36 1;