X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F020_attributes%2F002_attribute_writer_generation.t;h=f7f776c801666cc064b1ee4b1d59df1b759e67b9;hb=c19af49f6e834464f5b8a864f4a4ece99d8feeaf;hp=1b25f3cad5f37f5d370be6189b2db009403bb7f7;hpb=7ff5653479c2bfc0794635f7fbade9bfe7bb2381;p=gitmo%2FMoose.git diff --git a/t/020_attributes/002_attribute_writer_generation.t b/t/020_attributes/002_attribute_writer_generation.t index 1b25f3c..f7f776c 100644 --- a/t/020_attributes/002_attribute_writer_generation.t +++ b/t/020_attributes/002_attribute_writer_generation.t @@ -13,7 +13,7 @@ use Scalar::Util 'isweak'; { package Foo; use Moose; - + eval { has 'foo' => ( reader => 'get_foo', @@ -38,8 +38,8 @@ use Scalar::Util 'isweak'; isa => 'Int', ); }; - ::ok(!$@, '... created the writer method with type constraint okay'); - + ::ok(!$@, '... created the writer method with type constraint okay'); + eval { has 'foo_weak' => ( reader => 'get_foo_weak', @@ -47,7 +47,7 @@ use Scalar::Util 'isweak'; weak_ref => 1 ); }; - ::ok(!$@, '... created the writer method with weak_ref okay'); + ::ok(!$@, '... created the writer method with weak_ref okay'); } { @@ -61,12 +61,12 @@ use Scalar::Util 'isweak'; lives_ok { $foo->set_foo(100); } '... set_foo wrote successfully'; - is($foo->get_foo(), 100, '... got the correct set value'); - - ok(!isweak($foo->{foo}), '... it is not a weak reference'); - + is($foo->get_foo(), 100, '... got the correct set value'); + + ok(!isweak($foo->{foo}), '... it is not a weak reference'); + # required writer - + dies_ok { Foo->new; } '... cannot create without the required attribute'; @@ -76,44 +76,44 @@ use Scalar::Util 'isweak'; lives_ok { $foo->set_foo_required(100); } '... set_foo_required wrote successfully'; - is($foo->get_foo_required(), 100, '... got the correct set value'); - + is($foo->get_foo_required(), 100, '... got the correct set value'); + dies_ok { $foo->set_foo_required(); } '... set_foo_required died successfully with no value'; lives_ok { $foo->set_foo_required(undef); - } '... set_foo_required did accept undef'; + } '... set_foo_required did accept undef'; + + ok(!isweak($foo->{foo_required}), '... it is not a weak reference'); - ok(!isweak($foo->{foo_required}), '... it is not a weak reference'); - # with type constraint - + can_ok($foo, 'set_foo_int'); is($foo->get_foo_int(), undef, '... got an unset value'); lives_ok { $foo->set_foo_int(100); } '... set_foo_int wrote successfully'; - is($foo->get_foo_int(), 100, '... got the correct set value'); - + is($foo->get_foo_int(), 100, '... got the correct set value'); + dies_ok { $foo->set_foo_int("Foo"); - } '... set_foo_int died successfully'; - - ok(!isweak($foo->{foo_int}), '... it is not a weak reference'); - + } '... set_foo_int died successfully'; + + ok(!isweak($foo->{foo_int}), '... it is not a weak reference'); + # with weak_ref - + my $test = []; - + can_ok($foo, 'set_foo_weak'); is($foo->get_foo_weak(), undef, '... got an unset value'); lives_ok { $foo->set_foo_weak($test); } '... set_foo_weak wrote successfully'; - is($foo->get_foo_weak(), $test, '... got the correct set value'); - + is($foo->get_foo_weak(), $test, '... got the correct set value'); + ok(isweak($foo->{foo_weak}), '... it is a weak reference'); }