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") );
}
See Test::Exception:
use Test::Exception;
dies_ok { $foo->method } 'expecting to die';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With