summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2011-07-22 09:52:56 -0700
committerFather Chrysostomos <sprout@cpan.org>2011-07-22 09:54:13 -0700
commit40914f83eabd350b52615a215aeb2704f7332495 (patch)
treeafe6c7054fffb9c8b7be4587702078fa8b384f4a /t
parent7ffa7e7540d4523072b049e2d1285c34faabeeb9 (diff)
downloadperl-40914f83eabd350b52615a215aeb2704f7332495.tar.gz
Make tests for gmagic on sub exit count fetches
These tests, added in commit 767eda44 (when lvalue subs started auto- vivifying, causing regular sub exit to have to call get-magic), were not counting the number of fetches, but simply whether the fetches were happening. The number that was occurring was wrong until 7ffa7e75, which fixed symbolic refs to call magic the right number of times. But now that that’s fixed, we can count them. So this commit does just that.
Diffstat (limited to 't')
-rw-r--r--t/op/gmagic.t27
1 files changed, 16 insertions, 11 deletions
diff --git a/t/op/gmagic.t b/t/op/gmagic.t
index 26ad08553b..2ec1f1126c 100644
--- a/t/op/gmagic.t
+++ b/t/op/gmagic.t
@@ -11,11 +11,11 @@ use strict;
tie my $c => 'Tie::Monitor';
sub expected_tie_calls {
- my ($obj, $rexp, $wexp) = @_;
+ my ($obj, $rexp, $wexp, $tn) = @_;
local $::Level = $::Level + 1;
my ($rgot, $wgot) = $obj->init();
- is ($rgot, $rexp);
- is ($wgot, $wexp);
+ is ($rgot, $rexp, $tn ? "number of fetches when $tn" : ());
+ is ($wgot, $wexp, $tn ? "number of stores when $tn" : ());
}
# Use ok() instead of is(), cmp_ok() etc, to strictly control number of accesses
@@ -69,14 +69,19 @@ ok($wgot == 0, 'a plain *foo causes no set-magic');
# get-magic when exiting a non-lvalue sub in potentially autovivify-
# ing context
-my $tied_to = tie $_{elem}, "Tie::Monitor";
-eval { () = sub { delete $_{elem} }->()->[3] };
-ok +($tied_to->init)[0],
- 'get-magic is called on mortal magic var on sub exit in autoviv context';
-$tied_to = tie $_{elem}, "Tie::Monitor";
-eval { () = sub { return delete $_{elem} }->()->[3] };
-ok +($tied_to->init)[0],
- 'get-magic is called on mortal magic var on return in autoviv context';
+{
+ no strict;
+
+ my $tied_to = tie $_{elem}, "Tie::Monitor";
+ () = sub { delete $_{elem} }->()->[3];
+ expected_tie_calls $tied_to, 1, 0,
+ 'mortal magic var is implicitly returned in autoviv context';
+
+ $tied_to = tie $_{elem}, "Tie::Monitor";
+ () = sub { return delete $_{elem} }->()->[3];
+ expected_tie_calls $tied_to, 1, 0,
+ 'mortal magic var is explicitly returned in autoviv context';
+}
done_testing();