X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F20-localize-target.t;h=9bd7a3885fcc6376122bd87515a4ef96dda79f6c;hb=bbbe07a5dec59669ffef59ce33e3884ecfd1b7f1;hp=56ebd978df5f747f571b6585808ddbb1dda2eb76;hpb=0a6221d3f467b5f819e3c119b4cda0218399cb51;p=perl%2Fmodules%2FScope-Upper.git diff --git a/t/20-localize-target.t b/t/20-localize-target.t index 56ebd97..9bd7a38 100644 --- a/t/20-localize-target.t +++ b/t/20-localize-target.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 50; +use Test::More tests => 50 + 4; use Scope::Upper qw/localize UP HERE/; @@ -32,14 +32,17 @@ sub _t { shift->{t} } is $x, undef, 'localize *x, obj => HERE [end]'; } +our $y; + { - local $x = 2; + local $x = 1; + local $y = 2; { - local $x = 3; - localize *x, 1 => HERE; - is $x, undef, 'localize *x, 1 => HERE [ok]'; + local $y = 3; + localize *x, 'y' => HERE; + is $x, 3, "localize *x, 'y' => HERE [ok]"; } - is $x, $] < 5.008009 ? undef : 2, 'localize *x, 1 => HERE [end]'; + is $x, 1, "localize *x, 'y' => HERE [end]"; } undef *x; @@ -63,7 +66,7 @@ undef *x; SKIP: { - skip 'Can\'t localize through a reference in 5.6' => 2 if $] < 5.008; + skip 'Can\'t localize through a reference before 5.8.1' => 2 if $] < 5.008001; eval q{ no strict 'refs'; local ${''} = 9; @@ -77,7 +80,7 @@ SKIP: SKIP: { - skip 'Can\'t localize through a reference in 5.6' => 2 if $] < 5.008; + skip 'Can\'t localize through a reference before 5.8.1' => 2 if $] < 5.008001; eval q{ no strict 'refs'; local ${''} = 10; @@ -251,3 +254,27 @@ my $xh = { a => 5, c => 7 }; } is foo(), 8, 'localize "&foo", sub { 8 } => UP [ok]'; } + +# Invalid + +sub invalid_ref { qr/^Invalid \Q$_[0]\E reference as the localization target/ } + +{ + eval { localize \1, 0 => HERE }; + like $@, invalid_ref('SCALAR'), 'invalid localize \1, 0 => HERE'; +} + +{ + eval { localize [ ], 0 => HERE }; + like $@, invalid_ref('ARRAY'), 'invalid localize [ ], 0 => HERE'; +} + +{ + eval { localize { }, 0 => HERE }; + like $@, invalid_ref('HASH'), 'invalid localize { }, 0 => HERE'; +} + +{ + eval { localize sub { }, 0 => HERE }; + like $@, invalid_ref('CODE'), 'invalid localize sub { }, 0 => HERE'; +}