From: Peter Rabbitson Date: Fri, 8 Oct 2010 16:10:38 +0000 (+0000) Subject: Cleanup tests, s/class/obj/ where appropriate X-Git-Tag: v0.09007~5 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8443030080ecfca256b68ce0d26df9e6a79b1a37;p=p5sagit%2FClass-Accessor-Grouped.git Cleanup tests, s/class/obj/ where appropriate --- diff --git a/t/accessors.t b/t/accessors.t index e10f102..6a5f03b 100644 --- a/t/accessors.t +++ b/t/accessors.t @@ -18,9 +18,19 @@ BEGIN { use AccessorGroups; -my $class = AccessorGroups->new; +my $obj = AccessorGroups->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 { @@ -29,25 +39,11 @@ my $class = AccessorGroups->new; }; }; - $class->mk_group_accessors('warnings', 'DESTROY'); + no warnings qw/once/; + local *AccessorGroups::DESTROY = sub {}; + $obj->mk_group_accessors('warnings', 'DESTROY'); ok($warned); - - # restore non-accessorized DESTROY - no warnings; - *AccessorGroups::DESTROY = sub {}; -}; - -{ - my $class_name = ref $class; - my $name = 'multiple1'; - my $alias = "_${name}_accessor"; - my $accessor = $class->can($name); - my $alias_accessor = $class->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,$name), 'accessor FQ name'); - is(sub_fullname($alias_accessor), join('::',$class_name,$alias), 'alias FQ name'); } my $test_accessors = { @@ -73,28 +69,28 @@ for my $name (sort keys %$test_accessors) { my $field = $test_accessors->{$name}{custom_field} || $name; my $extra = $test_accessors->{$name}{has_extra}; - can_ok($class, $name, $alias); - ok(!$class->can($field)) + can_ok($obj, $name, $alias); + ok(!$obj->can($field)) if $field ne $name; - is($class->$name, undef); - is($class->$alias, undef); + is($obj->$name, undef); + is($obj->$alias, undef); # get/set via name - is($class->$name('a'), 'a'); - is($class->$name, 'a'); - is($class->{$field}, $extra ? 'a Extra tackled on' : 'a'); + is($obj->$name('a'), 'a'); + is($obj->$name, 'a'); + is($obj->{$field}, $extra ? 'a Extra tackled on' : 'a'); # alias gets same as name - is($class->$alias, 'a'); + is($obj->$alias, 'a'); # get/set via alias - is($class->$alias('b'), 'b'); - is($class->$alias, 'b'); - is($class->{$field}, $extra ? 'b Extra tackled on' : 'b'); + is($obj->$alias('b'), 'b'); + is($obj->$alias, 'b'); + is($obj->{$field}, $extra ? 'b Extra tackled on' : 'b'); # alias gets same as name - is($class->$name, 'b'); + is($obj->$name, 'b'); }; # important diff --git a/t/accessors_ro.t b/t/accessors_ro.t index 4268b25..79413ff 100644 --- a/t/accessors_ro.t +++ b/t/accessors_ro.t @@ -18,7 +18,7 @@ BEGIN { use AccessorGroupsRO; -my $class = AccessorGroupsRO->new; +my $obj = AccessorGroupsRO->new; { my $warned = 0; @@ -29,13 +29,12 @@ my $class = AccessorGroupsRO->new; }; }; - $class->mk_group_ro_accessors('warnings', 'DESTROY'); + no warnings qw/once/; + local *AccessorGroupsRO::DESTROY = sub {}; - ok($warned); + $obj->mk_group_ro_accessors('warnings', 'DESTROY'); - # restore non-accessorized DESTROY - no warnings; - *AccessorGroupsRO::DESTROY = sub {}; + ok($warned); }; my $test_accessors = { @@ -59,20 +58,20 @@ for my $name (sort keys %$test_accessors) { my $alias = "_${name}_accessor"; my $field = $test_accessors->{$name}{custom_field} || $name; - can_ok($class, $name, $alias); + can_ok($obj, $name, $alias); - ok(!$class->can($field)) + ok(!$obj->can($field)) if $field ne $name; - is($class->$name, undef); - is($class->$alias, undef); + is($obj->$name, undef); + is($obj->$alias, undef); # get via name - $class->{$field} = 'a'; - is($class->$name, 'a'); + $obj->{$field} = 'a'; + is($obj->$name, 'a'); # alias gets same as name - is($class->$alias, 'a'); + is($obj->$alias, 'a'); my $ro_regex = $test_accessors->{$name}{is_xs} ? qr/Usage\:.+$name.*\(self\)/ @@ -81,16 +80,16 @@ for my $name (sort keys %$test_accessors) { # die on set via name/alias throws_ok { - $class->$name('b'); + $obj->$name('b'); } $ro_regex; throws_ok { - $class->$alias('b'); + $obj->$alias('b'); } $ro_regex; # value should be unchanged - is($class->$name, 'a'); - is($class->$alias, 'a'); + is($obj->$name, 'a'); + is($obj->$alias, 'a'); }; #important diff --git a/t/accessors_wo.t b/t/accessors_wo.t index 1cda04a..47463b6 100644 --- a/t/accessors_wo.t +++ b/t/accessors_wo.t @@ -18,7 +18,7 @@ BEGIN { use AccessorGroupsWO; -my $class = AccessorGroupsWO->new; +my $obj = AccessorGroupsWO->new; { my $warned = 0; @@ -29,13 +29,11 @@ my $class = AccessorGroupsWO->new; }; }; - $class->mk_group_wo_accessors('warnings', 'DESTROY'); + no warnings qw/once/; + local *AccessorGroupsWO::DESTROY = sub {}; + $obj->mk_group_wo_accessors('warnings', 'DESTROY'); ok($warned); - - # restore non-accessorized DESTROY - no warnings; - *AccessorGroupsWO::DESTROY = sub {}; }; my $test_accessors = { @@ -59,18 +57,18 @@ for my $name (sort keys %$test_accessors) { my $alias = "_${name}_accessor"; my $field = $test_accessors->{$name}{custom_field} || $name; - can_ok($class, $name, $alias); + can_ok($obj, $name, $alias); - ok(!$class->can($field)) + ok(!$obj->can($field)) if $field ne $name; # set via name - is($class->$name('a'), 'a'); - is($class->{$field}, 'a'); + is($obj->$name('a'), 'a'); + is($obj->{$field}, 'a'); # alias sets same as name - is($class->$alias('b'), 'b'); - is($class->{$field}, 'b'); + is($obj->$alias('b'), 'b'); + is($obj->{$field}, 'b'); my $wo_regex = $test_accessors->{$name}{is_xs} ? qr/Usage\:.+$name.*\(self, newvalue\)/ @@ -79,11 +77,11 @@ for my $name (sort keys %$test_accessors) { # die on get via name/alias throws_ok { - $class->$name; + $obj->$name; } $wo_regex; throws_ok { - $class->$alias; + $obj->$alias; } $wo_regex; };