From: Vincent Pit Date: Mon, 23 Mar 2009 16:01:14 +0000 (+0100) Subject: Test that the uvar/clear doesn't confuse B::Deparse in t/32-hash.t X-Git-Tag: v0.33~2 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=491a2e8180d6c0687483df32056c4ec762e7efd5;p=perl%2Fmodules%2FVariable-Magic.git Test that the uvar/clear doesn't confuse B::Deparse in t/32-hash.t --- diff --git a/t/32-hash.t b/t/32-hash.t index e12b810..5072484 100644 --- a/t/32-hash.t +++ b/t/32-hash.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 2 * 21 + 7 + 1; +use Test::More tests => (2 * 21 + 7) + (2 * 5 + 4) + 1; use Variable::Magic qw/cast dispell MGf_COPY VMG_UVAR/; @@ -72,3 +72,43 @@ watch { watch { undef %h } { clear => 1 }, 'undef'; watch { dispell %h, $wiz } { }, 'dispell'; + +SKIP: { + my $SKIP; + + unless (VMG_UVAR) { + $SKIP = 'uvar magic'; + } else { + eval "use B::Deparse"; + $SKIP = 'B::Deparse' if $@; + } + if ($SKIP) { + $SKIP .= ' required to test uvar/clear interaction fix'; + skip $SKIP => 2 * 5 + 4; + } + + my $bd = B::Deparse->new; + + my %h = (a => 13, b => 15); + watch { cast %h, $wiz } { }, 'cast clear/uvar'; + + my $code = sub { my $x = $h{$_[0]}; ++$x; $x }; + my $before = $bd->coderef2text($code); + my $res; + + watch { $res = $code->('a') } { fetch => 1 }, 'fixed fetch "a"'; + is $res, 14, 'uvar: fixed fetch "a" returned the right thing'; + + my $after = $bd->coderef2text($code); + is $before, $after, 'uvar: fixed fetch deparse correctly'; + + watch { $res = $code->('b') } { fetch => 1 }, 'fixed fetch "b"'; + is $res, 16, 'uvar: fixed fetch "b" returned the right thing'; + + $after = $bd->coderef2text($code); + is $before, $after, 'uvar: fixed fetch deparse correctly'; + + watch { %h = () } { clear => 1 }, 'fixed clear'; + + watch { dispell %h, $wiz } { }, 'dispell clear/uvar'; +}