]> git.vpit.fr Git - perl/modules/Scope-Upper.git/blobdiff - t/20-localize-target.t
Fix stack corruption when using unwind() under Devel::NYTProf
[perl/modules/Scope-Upper.git] / t / 20-localize-target.t
index 726a588d156763797c0f3523ae2556b305dcb14f..9bd7a3885fcc6376122bd87515a4ef96dda79f6c 100644 (file)
@@ -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';
+}