Even more corner case fixes - install the resolved final cref into the callER, not...
[p5sagit/Class-Accessor-Grouped.git] / t / accessors.t
index 99b8d44..c04ece2 100644 (file)
@@ -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