]> git.vpit.fr Git - perl/modules/Scope-Upper.git/blobdiff - t/67-uplevel-scope.t
Activate the correct pad when calling the uplevel'd code
[perl/modules/Scope-Upper.git] / t / 67-uplevel-scope.t
index 715c50cd4541ceae4ad93238361ba6ccc5447a81..92105fcfec759dbeba8a612d9ec5c1547e82c5ed 100644 (file)
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 4;
+use Test::More tests => 4 + 3 * 2;
 
 use Scope::Upper qw<uplevel HERE UP>;
 
@@ -44,3 +44,30 @@ sub {
   uplevel { is $1, 'x', 'match variables scoping 2' } UP;
  }->();
 }->();
+
+SKIP: {
+ skip 'No state variables before perl 5.10' => 3 * 2 unless "$]" >= 5.010;
+
+ my $desc = 'state variables';
+
+ {
+  local $@;
+  eval 'use feature "state"; sub herp { state $id = 123; return ++$id }';
+  die $@ if $@;
+ }
+
+ sub derp {
+  sub {
+   &uplevel(\&herp => UP);
+  }->();
+ }
+
+ for my $run (1 .. 3) {
+  local $@;
+  my $ret = eval {
+   derp()
+  };
+  is $@,   '',         "$desc: run $run did not croak";
+  is $ret, 123 + $run, "$desc: run $run returned the correct value";
+ }
+}