From: Vincent Pit Date: Thu, 14 Jan 2010 22:25:58 +0000 (+0100) Subject: More tests for reap and localized at given/when X-Git-Tag: v0.10~13 X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FScope-Upper.git;a=commitdiff_plain;h=c8997e4a75e935854f13e100fdcbc222978c1211 More tests for reap and localized at given/when --- diff --git a/t/13-reap-ctl.t b/t/13-reap-ctl.t index 7ec492a..210b5b5 100644 --- a/t/13-reap-ctl.t +++ b/t/13-reap-ctl.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 38 + 4 * 7; +use Test::More tests => 38 + 30 + 4 * 7; use Scope::Upper qw/reap UP HERE/; @@ -122,6 +122,133 @@ $y = undef; is $y, 1, 'die - reap inside eval [ok - y]'; } +SKIP: +{ + skip 'Perl 5.10 required to test given/when' => 30 if $] < 5.010; + + eval <<' GIVEN_TEST_1'; + use feature 'switch'; + local $y; + { + local $x = 1; + given (1) { + local $x = 2; + when (1) { + local $x = 3; + reap \&check => UP; + is $x, 3, 'given/when - reap at given [not yet - x]'; + is $y, undef, 'given/when - reap at given [not yet - y]'; + } + fail 'not reached'; + } + is $x, 1, 'given/when - reap at given [ok - x]'; + is $y, 1, 'given/when - reap at given [ok - y]'; + } + GIVEN_TEST_1 + fail $@ if $@; + + eval <<' GIVEN_TEST_2'; + use feature 'switch'; + local $y; + { + local $x = 1; + given (1) { + local $x = 2; + when (1) { + local $x = 3; + reap \&check => UP; + is $x, 3, 'given/when/continue - reap at given [not yet 1 - x]'; + is $y, undef, 'given/when/continue - reap at given [not yet 1 - y]'; + continue; + } + is $x, 2, 'given/when/continue - reap at given [not yet 2 - x]'; + is $y, undef, 'given/when/continue - reap at given [not yet 2 - y]'; + } + is $x, 1, 'given/when/continue - reap at given [ok - x]'; + is $y, 1, 'given/when/continue - reap at given [ok - y]'; + } + GIVEN_TEST_2 + fail $@ if $@; + + eval <<' GIVEN_TEST_3'; + use feature 'switch'; + local $y; + { + local $x = 1; + given (1) { + local $x = 2; + default { + local $x = 3; + reap \&check => UP; + is $x, 3, 'given/default - reap at given [not yet - x]'; + is $y, undef, 'given/default - reap at given [not yet - y]'; + } + fail 'not reached'; + } + is $x, 1, 'given/default - reap at given [ok - x]'; + is $y, 1, 'given/default - reap at given [ok - y]'; + } + GIVEN_TEST_3 + fail $@ if $@; + + eval <<' GIVEN_TEST_4'; + use feature 'switch'; + local $y; + { + local $x = 1; + given (1) { + local $x = 2; + default { + local $x = 3; + reap \&check => UP; + is $x, 3, 'given/default/continue - reap at given [not yet 1 - x]'; + is $y, undef, 'given/default/continue - reap at given [not yet 1 - y]'; + continue; + } + is $x, 2, 'given/default/continue - reap at given [not yet 2 - x]'; + is $y, undef, 'given/default/continue - reap at given [not yet 2 - y]'; + } + is $x, 1, 'given/default/continue - reap at given [ok - x]'; + is $y, 1, 'given/default/continue - reap at given [ok - y]'; + } + GIVEN_TEST_4 + fail $@ if $@; + + eval <<' GIVEN_TEST_5'; + use feature 'switch'; + local $y; + { + local $x = 1; + given (1) { + local $x = 2; + default { + local $x = 3; + given (2) { + local $x = 4; + when (2) { + local $x = 5; + reap \&check => UP UP; + is $x, 5, 'given/default/given/when - reap at default [not yet 1 - x]'; + is $y, undef, 'given/default/given/when - reap at default [not yet 1 - y]'; + continue; + } + is $x, 4, 'given/default/given/when - reap at default [not yet 2 - x]'; + is $y, undef, 'given/default/given/when - reap at default [not yet 2 - y]'; + } + is $x, 3, 'given/default/given/when - reap at default [not yet 3 - x]'; + is $y, undef, 'given/default/given/when - reap at default [not yet 3 - y]'; + continue; + } + is $x, 2, 'given/default/given/when - reap at default [ok 1 - x]'; + is $y, 1, 'given/default/given/when - reap at default [ok 1 - y]'; + } + is $x, 1, 'given/default/given/when - reap at default [ok 2 - x]'; + is $y, 1, 'given/default/given/when - reap at default [ok 2 - y]'; + } + GIVEN_TEST_5 + fail $@ if $@; +} + $y = undef; { local $x = 1; diff --git a/t/23-localize-ctl.t b/t/23-localize-ctl.t index 213df7f..9acf7be 100644 --- a/t/23-localize-ctl.t +++ b/t/23-localize-ctl.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 44; +use Test::More tests => 44 + 30; use Scope::Upper qw/localize UP HERE/; @@ -187,3 +187,130 @@ $y = undef; is $x, 1, 'die - reap inside eval [ok - x]'; is $y, undef, 'die - reap inside eval [ok - y]'; } + +SKIP: +{ + skip 'Perl 5.10 required to test given/when' => 30 if $] < 5.010; + + eval <<' GIVEN_TEST_1'; + use feature 'switch'; + local $y; + { + local $x = 1; + given (1) { + local $x = 2; + when (1) { + local $x = 3; + localize '$y' => 1 => UP UP; + is $x, 3, 'given/when - localize at given [not yet - x]'; + is $y, undef, 'given/when - localize at given [not yet - y]'; + } + fail 'not reached'; + } + is $x, 1, 'given/when - localize at given [ok - x]'; + is $y, 1, 'given/when - localize at given [ok - y]'; + } + GIVEN_TEST_1 + fail $@ if $@; + + eval <<' GIVEN_TEST_2'; + use feature 'switch'; + local $y; + { + local $x = 1; + given (1) { + local $x = 2; + when (1) { + local $x = 3; + localize '$y' => 1 => UP UP; + is $x, 3, 'given/when/continue - localize at given [not yet 1 - x]'; + is $y, undef, 'given/when/continue - localize at given [not yet 1 - y]'; + continue; + } + is $x, 2, 'given/when/continue - localize at given [not yet 2 - x]'; + is $y, undef, 'given/when/continue - localize at given [not yet 2 - y]'; + } + is $x, 1, 'given/when/continue - localize at given [ok - x]'; + is $y, 1, 'given/when/continue - localize at given [ok - y]'; + } + GIVEN_TEST_2 + fail $@ if $@; + + eval <<' GIVEN_TEST_3'; + use feature 'switch'; + local $y; + { + local $x = 1; + given (1) { + local $x = 2; + default { + local $x = 3; + localize '$y' => 1 => UP UP; + is $x, 3, 'given/default - localize at given [not yet - x]'; + is $y, undef, 'given/default - localize at given [not yet - y]'; + } + fail 'not reached'; + } + is $x, 1, 'given/default - localize at given [ok - x]'; + is $y, 1, 'given/default - localize at given [ok - y]'; + } + GIVEN_TEST_3 + fail $@ if $@; + + eval <<' GIVEN_TEST_4'; + use feature 'switch'; + local $y; + { + local $x = 1; + given (1) { + local $x = 2; + default { + local $x = 3; + localize '$y' => 1 => UP UP; + is $x, 3, 'given/default/continue - localize at given [not yet 1 - x]'; + is $y, undef, 'given/default/continue - localize at given [not yet 1 - y]'; + continue; + } + is $x, 2, 'given/default/continue - localize at given [not yet 2 - x]'; + is $y, undef, 'given/default/continue - localize at given [not yet 2 - y]'; + } + is $x, 1, 'given/default/continue - localize at given [ok - x]'; + is $y, 1, 'given/default/continue - localize at given [ok - y]'; + } + GIVEN_TEST_4 + fail $@ if $@; + + eval <<' GIVEN_TEST_5'; + use feature 'switch'; + local $y; + { + local $x = 1; + given (1) { + local $x = 2; + default { + local $x = 3; + given (2) { + local $x = 4; + when (2) { + local $x = 5; + localize '$y' => 1 => UP UP UP; + is $x, 5, 'given/default/given/when - localize at default [not yet 1 - x]'; + is $y, undef, 'given/default/given/when - localize at default [not yet 1 - y]'; + continue; + } + is $x, 4, 'given/default/given/when - localize at default [not yet 2 - x]'; + is $y, undef, 'given/default/given/when - localize at default [not yet 2 - y]'; + } + is $x, 3, 'given/default/given/when - localize at default [not yet 3 - x]'; + is $y, undef, 'given/default/given/when - localize at default [not yet 3 - y]'; + continue; + } + is $x, 2, 'given/default/given/when - localize at default [ok 1 - x]'; + is $y, 1, 'given/default/given/when - localize at default [ok 1 - y]'; + } + is $x, 1, 'given/default/given/when - localize at default [ok 2 - x]'; + is $y, undef, 'given/default/given/when - localize at default [ok 2 - y]'; + } + GIVEN_TEST_5 + fail $@ if $@; +}