use Test::More qw( no_plan ); use Test::Trap qw(:void_is_scalar:diag_all_on_fail); # thanks to :void_is_scalar, foo is called in # scalar context here: trap { foo("bar") }; # foo is still called in list context here: () = trap { foo("baz") }; # trap a little ... trap { 1 }; $trap->return_is_deeply( [1], 'Trapped [1]' ); # prints "ok 1\n" $trap->return_is_deeply( [2], 'Trapped [2]' ); # prints "not ok 2\n" with diagnosis: # Failed test 'Trapped [2]' # at .../trap.pl line 17. # Structures begin differing at: # $got->[0] = '1' # $expected->[0] = '2' # Trap contains: # bless({ # leaveby => "return", # "return" => [1], # stderr => "", # stdout => "", # "wantarray" => "", # "warn" => [], # }, "Test::Trap")