From: Yuval Kogman Date: Thu, 24 Apr 2008 10:46:52 +0000 (+0000) Subject: more attr traits tests X-Git-Tag: 0_55~214 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3c693defc2a0a9fddf96d4f383464ea9011f9ce9;p=gitmo%2FMoose.git more attr traits tests --- diff --git a/t/020_attributes/015_attribute_traits.t b/t/020_attributes/015_attribute_traits.t index ed7f4fe..0cb44fd 100644 --- a/t/020_attributes/015_attribute_traits.t +++ b/t/020_attributes/015_attribute_traits.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 12; +use Test::More tests => 13; use Test::Exception; use Test::Moose; @@ -16,6 +16,8 @@ BEGIN { use Moose::Role; has 'alias_to' => (is => 'ro', isa => 'Str'); + + has foo => ( is => "ro", default => "blah" ); after 'install_accessors' => sub { my $self = shift; @@ -57,6 +59,7 @@ my $bar_attr = $c->meta->get_attribute('bar'); does_ok($bar_attr, 'My::Attribute::Trait'); ok($bar_attr->has_applied_traits, '... got the applied traits'); is_deeply($bar_attr->applied_traits, [qw/My::Attribute::Trait/], '... got the applied traits'); +is($bar_attr->foo, "blah", "attr initialized"); my $gorch_attr = $c->meta->get_attribute('gorch'); ok(!$gorch_attr->does('My::Attribute::Trait'), '... gorch doesnt do the trait'); diff --git a/t/020_attributes/016_attribute_traits_registered.t b/t/020_attributes/016_attribute_traits_registered.t index 611d3d0..ad4aa84 100644 --- a/t/020_attributes/016_attribute_traits_registered.t +++ b/t/020_attributes/016_attribute_traits_registered.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 13; +use Test::More tests => 16; use Test::Exception; use Test::Moose; @@ -14,17 +14,19 @@ BEGIN { { package My::Attribute::Trait; use Moose::Role; - + has 'alias_to' => (is => 'ro', isa => 'Str'); - + + has foo => ( is => "ro", default => "blah" ); + after 'install_accessors' => sub { my $self = shift; $self->associated_class->add_method( - $self->alias_to, + $self->alias_to, $self->get_read_method_ref ); }; - + package Moose::Meta::Attribute::Custom::Trait::Aliased; sub register_implementation { 'My::Attribute::Trait' } } @@ -32,19 +34,21 @@ BEGIN { { package My::Other::Attribute::Trait; use Moose::Role; - + my $method = sub { 42; - }; - + }; + + has bar => ( isa => "Str", default => "oink" ); + after 'install_accessors' => sub { my $self = shift; $self->associated_class->add_method( - 'additional_method', + 'additional_method', $method ); }; - + package Moose::Meta::Attribute::Custom::Trait::Other; sub register_implementation { 'My::Other::Attribute::Trait' } } @@ -52,7 +56,7 @@ BEGIN { { package My::Class; use Moose; - + has 'bar' => ( traits => [qw/Aliased/], is => 'ro', @@ -61,7 +65,7 @@ BEGIN { ); } -{ +{ package My::Derived::Class; use Moose; @@ -80,7 +84,9 @@ is($c->bar, 100, '... got the right value for bar'); can_ok($c, 'baz') and is($c->baz, 100, '... got the right value for baz'); -does_ok($c->meta->get_attribute('bar'), 'My::Attribute::Trait'); +my $bar_attr = $c->meta->get_attribute('bar'); +does_ok($bar_attr, 'My::Attribute::Trait'); +is($bar_attr->foo, "blah", "attr initialized"); my $quux = My::Derived::Class->new(bar => 1000); @@ -88,13 +94,18 @@ is($quux->bar, 1000, '... got the right value for bar'); can_ok($quux, 'baz'); is($quux->baz, 1000, '... got the right value for baz'); -ok($quux->meta->get_attribute('bar')->does('My::Attribute::Trait')); + +my $derived_bar_attr = $quux->meta->get_attribute("bar"); +does_ok($derived_bar_attr, 'My::Attribute::Trait' ); + +is( $derived_bar_attr->foo, "blah", "attr initialized" ); TODO: { - local $TODO = 'These do not pass - bug?'; - SKIP: { - skip 'no additional_method, so cannot test its value', 1 if !can_ok($quux, 'additional_method'); - is($quux->additional_method, 42, '... got the right value for additional_method'); - } - ok($quux->meta->get_attribute('bar')->does('My::Other::Attribute::Trait')); + local $TODO = 'traits in clone_and_inherit dont work yet'; + does_ok($derived_bar_attr, 'My::Other::Attribute::Trait' ); + + is( eval { $derived_bar_attr->bar }, "oink", "attr initialized" ); + + can_ok($quux, 'additional_method'); + is(eval { $quux->additional_method }, 42, '... got the right value for additional_method'); }