X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Faccessors.t;h=c04ece203a11b02d7afa46576a576a9617aba8a9;hb=f7cf686751b8f117429990e7aac90a74a63b087a;hp=99b8d442e348c7b61be25e16b5662c152b41bb3b;hpb=f7ce0ad4cc0c24c7241c87dbe8c19b45e25fd96b;p=p5sagit%2FClass-Accessor-Grouped.git diff --git a/t/accessors.t b/t/accessors.t index 99b8d44..c04ece2 100644 --- a/t/accessors.t +++ b/t/accessors.t @@ -1,8 +1,8 @@ -use Test::More tests => 62; +use Test::More tests => 98; use strict; use warnings; use lib 't/lib'; -use Sub::Identify qw/sub_name sub_fullname/; +use B qw/svref_2object/; # we test the pure-perl versions only, but allow overrides # from the accessor_xs test-umbrella @@ -19,16 +19,10 @@ BEGIN { use AccessorGroupsSubclass; { - my $obj = AccessorGroups->new; + my $obj = AccessorGroupsSubclass->new; my $class = ref $obj; my $name = 'multiple1'; my $alias = "_${name}_accessor"; - my $accessor = $obj->can($name); - my $alias_accessor = $obj->can($alias); - isnt(sub_name($accessor), '__ANON__', 'accessor is named'); - isnt(sub_name($alias_accessor), '__ANON__', 'alias is named'); - is(sub_fullname($accessor), join('::',$class,$name), 'accessor FQ name'); - is(sub_fullname($alias_accessor), join('::',$class,$alias), 'alias FQ name'); my $warned = 0; local $SIG{__WARN__} = sub { @@ -38,13 +32,12 @@ use AccessorGroupsSubclass; }; no warnings qw/once/; - local *AccessorGroups::DESTROY = sub {}; + local *AccessorGroupsSubclass::DESTROY = sub {}; $class->mk_group_accessors('warnings', 'DESTROY'); ok($warned); }; - my $obj = AccessorGroupsSubclass->new; my $test_accessors = { @@ -64,7 +57,6 @@ my $test_accessors = { }, }; - for my $name (sort keys %$test_accessors) { my $alias = "_${name}_accessor"; my $field = $test_accessors->{$name}{custom_field} || $name; @@ -74,6 +66,12 @@ for my $name (sort keys %$test_accessors) { ok(!$obj->can($field)) if $field ne $name; + for my $meth ($name, $alias) { + my $cv = svref_2object( $obj->can($meth) ); + is($cv->GV->NAME, $meth, "$meth accessor is named"); + is($cv->GV->STASH->NAME, 'AccessorGroups', "$meth class correct"); + } + is($obj->$name, undef); is($obj->$alias, undef); @@ -92,6 +90,17 @@ for my $name (sort keys %$test_accessors) { # alias gets same as name is($obj->$name, 'b'); + + for my $meth ($name, $alias) { + my $cv = svref_2object( $obj->can($meth) ); + is($cv->GV->NAME, $meth, "$meth accessor is named after operations"); + is( + $cv->GV->STASH->NAME, + # XS lazyinstalls install into each caller, not into the original parent + $test_accessors->{$name}{is_xs} ? 'AccessorGroupsSubclass' :'AccessorGroups', + "$meth class correct after operations", + ); + } }; # important