#!/usr/bin/perl use Test::More tests => 6; use Test::Exception; use Test::Trap; sub A1::DESTROY { eval {} } sub A2::DESTROY { die 42 } sub A3::DESTROY { diag "XXX"; die } diag "Should die, but doesn't:"; { my $obj = bless [], 'A3'; 1 }; # doesn't die! diag "Test::Exception:"; dies_ok { my $obj = bless [], 'A1'; die } q[Exceptions aren't hidden by eval{} during scope cleanup]; throws_ok { my $obj = bless [], 'A2'; die 43 } qr/43/, q[Of multiple failures, the "primary" one is returned]; dies_ok { my $obj = bless [], 'A3'; return 1 } q[Failure during scope cleanup is detected]; diag "Test::Trap:"; trap { my $obj = bless [], 'A1'; die }; $trap->did_die( q[Exceptions aren't hidden by eval{} during scope cleanup] ); trap { my $obj = bless [], 'A2'; die 43 }; $trap->die_like( qr/43/, q[Of multiple failures, the "primary" one is returned] ); trap { my $obj = bless [], 'A3'; 1 }; $trap->did_die( q[Failure during scope cleanup is detected] );