X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F100_bugs%2F012_DEMOLISH_eats_mini.t;h=e4b03c4c970657405a70f3dc92ccd465b7af3756;hb=79dad293813bec9cf024859cb34618dd7ca01b93;hp=5773a601b8bd642d41c0b40d55fa56e7e955e86f;hpb=7ff5653479c2bfc0794635f7fbade9bfe7bb2381;p=gitmo%2FMoose.git diff --git a/t/100_bugs/012_DEMOLISH_eats_mini.t b/t/100_bugs/012_DEMOLISH_eats_mini.t index 5773a60..e4b03c4 100644 --- a/t/100_bugs/012_DEMOLISH_eats_mini.t +++ b/t/100_bugs/012_DEMOLISH_eats_mini.t @@ -3,11 +3,10 @@ use strict; use warnings; -use Test::More tests => 4; +use Test::More; use Test::Exception; - { package Foo; use Moose; @@ -21,19 +20,19 @@ use Test::Exception; # if no call to ANY Moose::Object->new was done before. sub DEMOLISH { my ( $self ) = @_; - # ... Moose (kinda) eats exceptions in DESTROY/DEMOLISH"; + # ... Moose (kinda) eats exceptions in DESTROY/DEMOLISH"; } } { my $obj = eval { Foo->new; }; - ::like( $@, qr/is required/, "... Foo plain" ); - ::is( $obj, undef, "... the object is undef" ); + like( $@, qr/is required/, "... Foo plain" ); + is( $obj, undef, "... the object is undef" ); } { package Bar; - + sub new { die "Bar died"; } sub DESTROY { @@ -43,9 +42,60 @@ use Test::Exception; { my $obj = eval { Bar->new; }; - ::like( $@, qr/Bar died/, "... Bar plain" ); - ::is( $obj, undef, "... the object is undef" ); + like( $@, qr/Bar died/, "... Bar plain" ); + is( $obj, undef, "... the object is undef" ); +} + +{ + package Baz; + use Moose; + + sub DEMOLISH { + $? = 0; + } +} + +{ + local $@ = 42; + local $? = 84; + + { + Baz->new; + } + + is( $@, 42, '$@ is still 42 after object is demolished without dying' ); + is( $?, 84, '$? is still 84 after object is demolished without dying' ); + + local $@ = 0; + + { + Baz->new; + } + + is( $@, 0, '$@ is still 0 after object is demolished without dying' ); + + Baz->meta->make_immutable, redo + if Baz->meta->is_mutable +} + +{ + package Quux; + use Moose; + + sub DEMOLISH { + die "foo\n"; + } } -1; +{ + local $@ = 42; + + eval { my $obj = Quux->new }; + + like( $@, qr/foo/, '$@ contains error from demolish when demolish dies' ); + + Quux->meta->make_immutable, redo + if Quux->meta->is_mutable +} +done_testing;