X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F67-uplevel-scope.t;h=b564a547003b6ef624953a8ca6a20b1b8a2817d5;hb=e7846e7f6fded4c4a3139054c5206c1480711867;hp=715c50cd4541ceae4ad93238361ba6ccc5447a81;hpb=1da764455f3f82a24aad0881beb01f5e4d3cf858;p=perl%2Fmodules%2FScope-Upper.git diff --git a/t/67-uplevel-scope.t b/t/67-uplevel-scope.t index 715c50c..b564a54 100644 --- a/t/67-uplevel-scope.t +++ b/t/67-uplevel-scope.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 4; +use Test::More tests => 2 + 2 * 6 + 3 * 2; use Scope::Upper qw; @@ -30,17 +30,60 @@ use Scope::Upper qw; } sub { - "abc" =~ /(.)/; + 'abc' =~ /(.)/; + is $1, 'a', 'match variables scoping 1: before 1'; sub { - "xyz" =~ /(.)/; - uplevel { is $1, 'x', 'match variables scoping 1' } HERE; + 'uvw' =~ /(.)/; + is $1, 'u', 'match variables scoping 1: before 2'; + uplevel { + is $1, 'u', 'match variables scoping 1: before 3'; + 'xyz' =~ /(.)/; + is $1, 'x', 'match variables scoping 1: after 1'; + } HERE; + is $1, 'u', 'match variables scoping 1: after 2'; }->(); + is $1, 'a', 'match variables scoping 1: after 3'; }->(); sub { - "abc" =~ /(.)/; + 'abc' =~ /(.)/; + is $1, 'a', 'match variables scoping 2: before 1'; sub { - "xyz" =~ /(.)/; - uplevel { is $1, 'x', 'match variables scoping 2' } UP; + 'uvw' =~ /(.)/; + is $1, 'u', 'match variables scoping 2: before 2'; + uplevel { + is $1, 'u', 'match variables scoping 2: before 3'; + 'xyz' =~ /(.)/; + is $1, 'x', 'match variables scoping 2: after 1'; + } UP; + is $1, 'u', 'match variables scoping 2: after 2'; }->(); + is $1, 'a', 'match variables scoping 2: after 3'; }->(); + +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"; + } +}