Reshuffle test loop (no func. changes). Examine under -w
[p5sagit/Class-Accessor-Grouped.git] / t / accessors.t
index c04ece2..8bca250 100644 (file)
@@ -1,4 +1,4 @@
-use Test::More tests => 98;
+use Test::More tests => 136;
 use strict;
 use warnings;
 use lib 't/lib';
@@ -10,54 +10,45 @@ use B qw/svref_2object/;
 # things
 my $use_xs;
 BEGIN {
-    $Class::Accessor::Grouped::USE_XS = 0
-        unless defined $Class::Accessor::Grouped::USE_XS;
-    $ENV{CAG_USE_XS} = 1;
-    $use_xs = $Class::Accessor::Grouped::USE_XS;
+  $Class::Accessor::Grouped::USE_XS = 0
+    unless defined $Class::Accessor::Grouped::USE_XS;
+  $ENV{CAG_USE_XS} = 1;
+  $use_xs = $Class::Accessor::Grouped::USE_XS;
 };
 
-use AccessorGroupsSubclass;
-
-{
-    my $obj = AccessorGroupsSubclass->new;
-    my $class = ref $obj;
-    my $name = 'multiple1';
-    my $alias = "_${name}_accessor";
-
-    my $warned = 0;
-    local $SIG{__WARN__} = sub {
-        if  (shift =~ /DESTROY/i) {
-            $warned++;
-        };
-    };
-
-    no warnings qw/once/;
-    local *AccessorGroupsSubclass::DESTROY = sub {};
-
-    $class->mk_group_accessors('warnings', 'DESTROY');
-    ok($warned);
-};
-
-my $obj = AccessorGroupsSubclass->new;
+require AccessorGroupsSubclass;
 
 my $test_accessors = {
-    singlefield => {
-        is_xs => $use_xs,
-        has_extra => 1,
-    },
-    multiple1 => {
-    },
-    multiple2 => {
-    },
-    lr1name => {
-        custom_field => 'lr1;field',
-    },
-    lr2name => {
-        custom_field => "lr2'field",
-    },
+  singlefield => {
+    is_simple => 1,
+    has_extra => 1,
+  },
+  runtime_around => {
+    # even though this accessor is declared as simple it will *not* be
+    # reinstalled due to the runtime 'around'
+    #is_simple => 1,
+    has_extra => 1,
+  },
+  multiple1 => {
+  },
+  multiple2 => {
+  },
+  lr1name => {
+    custom_field => 'lr1;field',
+  },
+  lr2name => {
+    custom_field => "lr2'field",
+  },
+  fieldname_torture => {
+    is_simple => 1,
+    custom_field => join ('', map { chr($_) } (0..255) ),
+  },
 };
 
-for my $name (sort keys %$test_accessors) {
+for my $obj (
+  AccessorGroupsSubclass->new,
+) {
+  for my $name (sort keys %$test_accessors) {
     my $alias = "_${name}_accessor";
     my $field = $test_accessors->{$name}{custom_field} || $name;
     my $extra = $test_accessors->{$name}{has_extra};
@@ -66,10 +57,15 @@ for my $name (sort keys %$test_accessors) {
     ok(!$obj->can($field))
       if $field ne $name;
 
+    # initial method 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");
+      my $cv = svref_2object( $obj->can($meth) );
+      is($cv->GV->NAME, $meth, "initial $meth accessor is named");
+      is(
+        $cv->GV->STASH->NAME,
+        'AccessorGroups',
+        "initial $meth class correct",
+      );
     }
 
     is($obj->$name, undef);
@@ -92,16 +88,20 @@ for my $name (sort keys %$test_accessors) {
     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",
-        );
+      my $cv = svref_2object( $obj->can($meth) );
+      is($cv->GV->NAME, $meth, "$meth accessor is named after operations");
+      is(
+        $cv->GV->STASH->NAME,
+        # XS deferred subs install into each caller, not into the original parent
+        ($use_xs and $test_accessors->{$name}{is_simple})
+          ? ref $obj
+          : 'AccessorGroups'
+        ,
+        "$meth class correct after operations",
+      );
     }
-};
+  }
+}
 
 # important
 1;