Planning for deaths in perl tests

perl, testing, unit-testing

Solution

See Test::Exception:

use Test::Exception;
dies_ok { $foo->method } 'expecting to die';

Problem

Is there a way to write tests for Perl calls that you expect to die? I'd like to verify that certain calls will die with poorly formatted inputs. ``` sub routine_a { my $arg = shift; die if $arg eq 'FOO'; print "routine_a: $arg\n"; } sub routine_b { my $arg = shift; die if $arg eq 'BAR'; print "routine_b: $arg\n"; } sub test_all { assert( routine_a("blah") ); assert( routine_b("blab") ); assert_death( routine_a("FOO") ); assert_death( routine_b("BAR") ); } ```

Original source

Related problems