X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F300_immutable%2F001_immutable_moose.t;h=48c0674da6bc0d2685cfc8ef20138c86bc7ad226;hb=f0b2e5673e864903e74a429565d0c57b69a60b95;hp=026d516ecefe15a424a491b7d5807059b6a18688;hpb=0f33d97fce95fd0fec3be3933c04d52c2de2f889;p=gitmo%2FMoose.git diff --git a/t/300_immutable/001_immutable_moose.t b/t/300_immutable/001_immutable_moose.t index 026d516..48c0674 100644 --- a/t/300_immutable/001_immutable_moose.t +++ b/t/300_immutable/001_immutable_moose.t @@ -3,52 +3,55 @@ use strict; use warnings; -use Test::More tests => 17; -use Test::Exception; +use Test::More; +use Test::Fatal; + +use Moose::Meta::Role; -BEGIN { - use_ok('Moose'); - use_ok('Moose::Meta::Role'); -} { - package FooRole; - our $VERSION = '0.01'; - sub foo { 'FooRole::foo' } + package FooRole; + our $VERSION = '0.01'; + sub foo {'FooRole::foo'} } { - package Foo; - use Moose; - - #two checks because the inlined methods are different when - #there is a TC present. - has 'foos' => (is => 'ro', lazy_build => 1); - has 'bars' => (isa => 'Str', is => 'ro', lazy_build => 1); - has 'bazes' => (isa => 'Str', is => 'ro', builder => '_build_bazes'); - sub _build_foos { "many foos" } - sub _build_bars { "many bars" } - sub _build_bazes { "many bazes" } + package Foo; + use Moose; + + #two checks because the inlined methods are different when + #there is a TC present. + has 'foos' => ( is => 'ro', lazy_build => 1 ); + has 'bars' => ( isa => 'Str', is => 'ro', lazy_build => 1 ); + has 'bazes' => ( isa => 'Str', is => 'ro', builder => '_build_bazes' ); + sub _build_foos {"many foos"} + sub _build_bars {"many bars"} + sub _build_bazes {"many bazes"} } { - my $foo_role = Moose::Meta::Role->initialize('FooRole'); - my $meta = Foo->meta; - - lives_ok{ Foo->new } "lazy_build works"; - is(Foo->new->foos, 'many foos' , "correct value for 'foos' before inlining constructor"); - is(Foo->new->bars, 'many bars' , "correct value for 'bars' before inlining constructor"); - is(Foo->new->bazes, 'many bazes' , "correct value for 'bazes' before inlining constructor"); - lives_ok{ $meta->make_immutable } "Foo is imutable"; - lives_ok{ $meta->identifier } "->identifier on metaclass lives"; - dies_ok{ $meta->add_role($foo_role) } "Add Role is locked"; - lives_ok{ Foo->new } "Inlined constructor works with lazy_build"; - is(Foo->new->foos, 'many foos' , "correct value for 'foos' after inlining constructor"); - is(Foo->new->bars, 'many bars' , "correct value for 'bars' after inlining constructor"); - is(Foo->new->bazes, 'many bazes' , "correct value for 'bazes' after inlining constructor"); - lives_ok{ $meta->make_mutable } "Foo is mutable"; - lives_ok{ $meta->add_role($foo_role) } "Add Role is unlocked"; - + my $foo_role = Moose::Meta::Role->initialize('FooRole'); + my $meta = Foo->meta; + + is( exception { Foo->new }, undef, "lazy_build works" ); + is( Foo->new->foos, 'many foos', + "correct value for 'foos' before inlining constructor" ); + is( Foo->new->bars, 'many bars', + "correct value for 'bars' before inlining constructor" ); + is( Foo->new->bazes, 'many bazes', + "correct value for 'bazes' before inlining constructor" ); + is( exception { $meta->make_immutable }, undef, "Foo is imutable" ); + is( exception { $meta->identifier }, undef, "->identifier on metaclass lives" ); + isnt( exception { $meta->add_role($foo_role) }, undef, "Add Role is locked" ); + is( exception { Foo->new }, undef, "Inlined constructor works with lazy_build" ); + is( Foo->new->foos, 'many foos', + "correct value for 'foos' after inlining constructor" ); + is( Foo->new->bars, 'many bars', + "correct value for 'bars' after inlining constructor" ); + is( Foo->new->bazes, 'many bazes', + "correct value for 'bazes' after inlining constructor" ); + is( exception { $meta->make_mutable }, undef, "Foo is mutable" ); + is( exception { $meta->add_role($foo_role) }, undef, "Add Role is unlocked" ); } @@ -70,14 +73,14 @@ BEGIN { sub BUILD { 'baz' } } -lives_ok { Bar->meta->make_immutable } - 'Immutable meta with single BUILD'; +is( exception { Bar->meta->make_immutable }, undef, 'Immutable meta with single BUILD' ); -lives_ok { Baz->meta->make_immutable } - 'Immutable meta with multiple BUILDs'; +is( exception { Baz->meta->make_immutable }, undef, 'Immutable meta with multiple BUILDs' ); =pod Nothing here yet, but soon :) =cut + +done_testing;