From: Matt S Trout Date: Tue, 26 Jun 2012 19:13:56 +0000 (+0000) Subject: additional test from FAIL_lazy_isa branch X-Git-Tag: v0.091010~6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6bed18454ee315fef08eaa9268f7b10093083f68;p=gitmo%2FMoo.git additional test from FAIL_lazy_isa branch --- diff --git a/t/lazy_isa.t b/t/lazy_isa.t new file mode 100644 index 0000000..10b286f --- /dev/null +++ b/t/lazy_isa.t @@ -0,0 +1,67 @@ +use strictures 1; +use Test::More; +use Test::Fatal; + +{ + package FooISA; + + use Moo; + + my $isa = sub { die "I want to die" unless $_[0] eq 'live' }; + + has a_lazy_attr => ( + is => 'ro', + isa => $isa, + lazy => 1, + builder => '_build_attr', + ); + + has non_lazy => ( + is => 'ro', + isa => $isa, + builder => '_build_attr', + ); + + sub _build_attr { 'die' } +} + +ok my $lives = FooISA->new(a_lazy_attr=>'live', non_lazy=>'live'), + 'expect to live when both attrs are set to live in init'; + +like( + exception { FooISA->new(a_lazy_attr=>'live', non_lazy=>'die') }, + qr/I want to die/, + 'expect to die when non lazy is set to die in init', +); + +like( + exception { FooISA->new(a_lazy_attr=>'die', non_lazy=>'die') }, + qr/I want to die/, + 'expect to die when non lazy and lazy is set to die in init', +); + +like( + exception { FooISA->new(a_lazy_attr=>'die', non_lazy=>'live') }, + qr/I want to die/, + 'expect to die when lazy is set to die in init', +); + +like( + exception { FooISA->new() }, + qr/I want to die/, + 'expect to die when both lazy and non lazy are allowed to default', +); + +like( + exception { FooISA->new(a_lazy_attr=>'live') }, + qr/I want to die/, + 'expect to die when lazy is set to live but non lazy is allowed to default', +); + +is( + exception { FooISA->new(non_lazy=>'live') }, + undef, + 'ok when non lazy is set to something valid but lazy is allowed to default', +); + +done_testing;