From: Peter Rabbitson Date: Fri, 8 Oct 2010 11:51:58 +0000 (+0000) Subject: Cleanup/consolidate main test X-Git-Tag: v0.09007~8 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2834410402128f3ade69b3c35bf9fbdebf81d172;p=p5sagit%2FClass-Accessor-Grouped.git Cleanup/consolidate main test --- diff --git a/t/accessors.t b/t/accessors.t index 49c6bea..3fc1145 100644 --- a/t/accessors.t +++ b/t/accessors.t @@ -8,10 +8,12 @@ use Sub::Identify qw/sub_name sub_fullname/; # from the accessor_xs test-umbrella # Also make sure a rogue envvar will not interfere with # 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; }; use AccessorGroups; @@ -48,11 +50,30 @@ my $class = AccessorGroups->new; is(sub_fullname($alias_accessor), join('::',$class_name,$alias), 'alias FQ name'); } -foreach (qw/singlefield multiple1 multiple2/) { - my $name = $_; +my $test_accessors = { + singlefield => { + is_xs => $use_xs, + }, + multiple1 => { + }, + multiple2 => { + }, + lr1name => { + custom_field => 'lr1;field', + }, + lr2name => { + custom_field => "lr2'field", + }, +}; + + +for my $name (sort keys %$test_accessors) { my $alias = "_${name}_accessor"; + my $field = $test_accessors->{$name}{custom_field} || $name; can_ok($class, $name, $alias); + ok(!$class->can($field)) + if $field ne $name; is($class->$name, undef); is($class->$alias, undef); @@ -60,7 +81,7 @@ foreach (qw/singlefield multiple1 multiple2/) { # get/set via name is($class->$name('a'), 'a'); is($class->$name, 'a'); - is($class->{$name}, 'a'); + is($class->{$field}, 'a'); # alias gets same as name is($class->$alias, 'a'); @@ -68,40 +89,11 @@ foreach (qw/singlefield multiple1 multiple2/) { # get/set via alias is($class->$alias('b'), 'b'); is($class->$alias, 'b'); - is($class->{$name}, 'b'); + is($class->{$field}, 'b'); # alias gets same as name is($class->$name, 'b'); }; -foreach (qw/lr1 lr2/) { - my $name = "$_".'name'; - my $alias = "_${name}_accessor"; - - my $field = { lr1 => 'lr1;field', lr2 => q{lr2'field} }->{$_}; - - can_ok($class, $name, $alias); - ok(!$class->can($field)); - - is($class->$name, undef); - is($class->$alias, undef); - - # get/set via name - is($class->$name('c'), 'c'); - is($class->$name, 'c'); - is($class->{$field}, 'c'); - - # alias gets same as name - is($class->$alias, 'c'); - - # get/set via alias - is($class->$alias('d'), 'd'); - is($class->$alias, 'd'); - is($class->{$field}, 'd'); - - # alias gets same as name - is($class->$name, 'd'); -}; - # important 1; diff --git a/t/accessors_xs.t b/t/accessors_xs.t index 393f916..258e273 100644 --- a/t/accessors_xs.t +++ b/t/accessors_xs.t @@ -16,7 +16,7 @@ BEGIN { if $@; } -# rerun all 3 tests under XSAccessor +# rerun the regular 3 tests under XSAccessor $Class::Accessor::Grouped::USE_XS = 1; for (qw/accessors.t accessors_ro.t accessors_wo.t/) { subtest "$_ with USE_XS" => sub { require( catfile($Bin, $_) ) } diff --git a/t/lib/AccessorGroups.pm b/t/lib/AccessorGroups.pm index eda9b80..d728251 100644 --- a/t/lib/AccessorGroups.pm +++ b/t/lib/AccessorGroups.pm @@ -4,11 +4,17 @@ use warnings; use base 'Class::Accessor::Grouped'; __PACKAGE__->mk_group_accessors('simple', 'singlefield'); -__PACKAGE__->mk_group_accessors('simple', qw/multiple1 multiple2/); -__PACKAGE__->mk_group_accessors('simple', [qw/lr1name lr1;field/], [qw/lr2name lr2'field/]); +__PACKAGE__->mk_group_accessors('multiple', qw/multiple1 multiple2/); +__PACKAGE__->mk_group_accessors('listref', [qw/lr1name lr1;field/], [qw/lr2name lr2'field/]); sub new { return bless {}, shift; }; +foreach (qw/multiple listref/) { + no strict 'refs'; + *{"get_$_"} = __PACKAGE__->can('get_simple'); + *{"set_$_"} = __PACKAGE__->can('set_simple'); +}; + 1; diff --git a/t/lib/AccessorGroupsRO.pm b/t/lib/AccessorGroupsRO.pm index 25857a4..2765734 100644 --- a/t/lib/AccessorGroupsRO.pm +++ b/t/lib/AccessorGroupsRO.pm @@ -13,8 +13,7 @@ sub new { foreach (qw/multiple listref/) { no strict 'refs'; - - *{"get_$_"} = \&Class::Accessor::Grouped::get_simple; + *{"get_$_"} = __PACKAGE__->can ('get_simple'); }; 1; diff --git a/t/lib/AccessorGroupsWO.pm b/t/lib/AccessorGroupsWO.pm index 2f46e75..8b4f3a2 100644 --- a/t/lib/AccessorGroupsWO.pm +++ b/t/lib/AccessorGroupsWO.pm @@ -13,8 +13,7 @@ sub new { foreach (qw/multiple listref/) { no strict 'refs'; - - *{"set_$_"} = \&Class::Accessor::Grouped::set_simple; + *{"set_$_"} = __PACKAGE__->can('set_simple'); }; 1;