]> git.vpit.fr Git - perl/modules/Variable-Magic.git/blobdiff - t/16-huf.t
Update VPIT::TestHelpers to e8344578
[perl/modules/Variable-Magic.git] / t / 16-huf.t
index 7d282777e7409967570975ab7d62fa0d3102cb9f..024a39c9bb32ad90c71d2e6d571213b3cb8c01e0 100644 (file)
@@ -5,47 +5,44 @@ use warnings;
 
 use Test::More;
 
-use Variable::Magic qw/wizard cast dispell VMG_UVAR/;
+use lib 't/lib';
+use VPIT::TestHelpers;
 
-if (!VMG_UVAR) {
- plan skip_all => 'No nice uvar magic for this perl';
-}
+use Variable::Magic qw<wizard cast dispell VMG_UVAR>;
 
-eval "use Hash::Util::FieldHash qw/fieldhash/";
-if ($@) {
- plan skip_all => 'Hash::Util::FieldHash required for testing uvar interaction';
+if (VMG_UVAR) {
+ load_or_skip_all('Hash::Util::FieldHash', undef, [ ]);
+ plan tests => 2 * 5 + 7 + 1;
 } else {
plan tests => 12;
skip_all 'No nice uvar magic for this perl';
 }
 
-fieldhash(my %h);
+use Variable::Magic::TestWatcher;
 
-bless \(my $obj = {}), 'Variable::Magic::Test::Mock';
-$h{$obj} = 5;
+my $wiz = init_watcher [ qw<fetch store> ], 'huf';
+ok defined($wiz),       'huf: wizard with uvar is defined';
+is ref($wiz), 'SCALAR', 'huf: wizard with uvar is a scalar ref';
 
-my ($w, $c) = (undef, 0);
+Hash::Util::FieldHash::fieldhash(\my %h);
 
-eval { $w = wizard fetch => sub { ++$c }, store => sub { --$c } };
-ok(!$@, "wizard with uvar creation error ($@)");
-ok(defined $w, 'wizard with uvar is defined');
-ok(ref($w) eq 'SCALAR', 'wizard with uvar is a scalar ref');
+my $obj = { };
+bless $obj, 'Variable::Magic::Test::Mock';
+$h{$obj} = 5;
 
-my $res = eval { cast %h, $w };
-ok(!$@, "cast uvar magic on fieldhash croaks ($@)");
-ok($res, 'cast uvar magic on fieldhash invalid');
+my ($res) = watch { cast %h, $wiz } { }, 'cast uvar magic on fieldhash';
+ok $res, 'huf: cast uvar magic on fieldhash succeeded';
 
-my $s = $h{$obj};
-ok($s == 5, 'fetch magic on fieldhash doesn\'t clobber');
-ok($c == 1, 'fetch magic on fieldhash');
+my ($s) = watch { $h{$obj} } { fetch => 1 }, 'fetch on magical fieldhash';
+is $s, 5, 'huf: fetch on magical fieldhash succeeded';
 
-$h{$obj} = 7;
-ok($c == 0, 'store magic on fieldhash');
-ok($h{$obj} == 7, 'store magic on fieldhash doesn\'t clobber'); # $c == 1
+watch { $h{$obj} = 7 } { store => 1 }, 'store on magical fieldhash';
+is $h{$obj}, 7, 'huf: store on magical fieldhash succeeded';
 
-$res = eval { dispell %h, $w };
-ok(!$@, "dispell uvar magic on fieldhash croaks ($@)");
-ok($res, 'dispell uvar magic on fieldhash invalid');
+($res) = watch { dispell %h, $wiz } { }, 'dispell uvar magic on fieldhash';
+ok $res, 'huf: dispell uvar magic on fieldhash succeeded';
 
 $h{$obj} = 11;
 $s = $h{$obj};
-ok($s == 11, 'store/fetch on fieldhash after dispell still ok');
+is $s, 11, 'huf: store/fetch on fieldhash after dispell still ok';
+
+$Variable::Magic::TestWatcher::mg_end = { fetch => 1 };