X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F020_attributes%2F002_attribute_writer_generation.t;h=f166150d2fe485a9ab19b89edb6e4db7a1e8d937;hb=ad3882b59692e4e4eab99f9b183c941e6f63d3bd;hp=8b5e0e270a5d624091c4060adfddb3cfb80b55d8;hpb=e59a5c292a333cac504b65ebd4bba20b5e98d796;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 8b5e0e2..f166150 100644 --- a/t/020_attributes/002_attribute_writer_generation.t +++ b/t/020_attributes/002_attribute_writer_generation.t @@ -3,19 +3,16 @@ use strict; use warnings; -use Test::More tests => 29; +use Test::More; use Test::Exception; use Scalar::Util 'isweak'; -BEGIN { - use_ok('Moose'); -} { package Foo; use Moose; - + eval { has 'foo' => ( reader => 'get_foo', @@ -40,8 +37,8 @@ BEGIN { 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', @@ -49,7 +46,7 @@ BEGIN { weak_ref => 1 ); }; - ::ok(!$@, '... created the writer method with weak_ref okay'); + ::ok(!$@, '... created the writer method with weak_ref okay'); } { @@ -63,12 +60,12 @@ BEGIN { 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'; @@ -78,42 +75,45 @@ BEGIN { 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 died successfully'; + } '... 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'); } - - +done_testing;