X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F10-base.t;h=dc1081cfba568f51eef90fc9f2247e0ab76b2736;hb=HEAD;hp=f5fb3972ec955206b508f43c28d25a6153de1446;hpb=ff85c569554967a354f1b6d113312fb2899af564;p=perl%2Fmodules%2FVariable-Temp.git diff --git a/t/10-base.t b/t/10-base.t index f5fb397..dc1081c 100644 --- a/t/10-base.t +++ b/t/10-base.t @@ -5,31 +5,41 @@ use warnings; use Variable::Temp 'set_temp'; -use Test::More tests => (7 + 2 * 19) * 2 + 6 * 3; +use Test::More tests => (9 + 2 * 19) * 2 + 6 * 3; sub describe { my $h = $_[0]; return join ', ', map "$_:$h->{$_}", sort keys %$h; } +my $aelem_delete_msg = 'Localized extraneous array elements do not reset array length at scope end before perl 5.12'; +my $aelem_delete_ok = ("$]" >= 5.012); + # Lexicals -my $x = 1; -is $x, 1; { - set_temp $x => 2; - is $x, 2; - $x = 3; - is $x, 3; + my $x = 1; + is $x, 1; + { + set_temp $x => 2; + is $x, 2; + $x = 3; + is $x, 3; + } + is $x, 1; { set_temp $x => 4; is $x, 4; set_temp $x => 5; is $x, 5; } - is $x, 3; + is $x, 1; + { + set_temp $x; + is $x, undef; + } + is $x, 1; } -is $x, 1; { my @y = (1, 2); @@ -65,7 +75,8 @@ is $x, 1; { set_temp @y => [ qw ]; is "@y", 'a b c'; - { + SKIP: { + skip $aelem_delete_msg => 3 unless $aelem_delete_ok; local $y[1] = 'd'; is "@y", 'a d c'; { @@ -129,39 +140,46 @@ is $x, 1; # Globals -our $X = 1; -is $X, 1; { - set_temp $X => 2; - is $X, 2; - $X = 3; - is $X, 3; + our $X = 1; + is $X, 1; + { + set_temp $X => 2; + is $X, 2; + $X = 3; + is $X, 3; + } + is $X, 1; { set_temp $X => 4; is $X, 4; set_temp $X => 5; is $X, 5; } - is $X, 3; + is $X, 1; + { + set_temp $X; + is $X, undef; + } + is $X, 1; { local $X = 6; is $X, 6; } - is $X, 3; + is $X, 1; { local $X = 7; set_temp $X => 8; is $X, 8; } - is $X, 3; + is $X, 1; { set_temp $X => 9; local $X = 10; is $X, 10; } - is $X, 3; + is $X, 1; } -is $X, 1; { our @Y = (1, 2); @@ -197,7 +215,8 @@ is $X, 1; { set_temp @Y => [ qw ]; is "@Y", 'a b c'; - { + SKIP: { + skip $aelem_delete_msg => 3 unless $aelem_delete_ok; local $Y[1] = 'd'; is "@Y", 'a d c'; {