X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F20-localize-target.t;h=9bd7a3885fcc6376122bd87515a4ef96dda79f6c;hb=add935e784ba40a5c477b8b8c93fb4a2159b53a1;hp=726a588d156763797c0f3523ae2556b305dcb14f;hpb=df7ce62096b3b482fc1a0064d6466ddc8907bd66;p=perl%2Fmodules%2FScope-Upper.git diff --git a/t/20-localize-target.t b/t/20-localize-target.t index 726a588..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/; @@ -66,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; @@ -80,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; @@ -254,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'; +}