Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possbile to test for expected errors when the testee exits with failure using TAP within Perl?

Tags:

testing

perl

tap

Suppose you're running some unit tests and you want to see if the method ( or script or function or whatever) you're testing fails as it should. How do you setup such a test? I'm hoping for something like this:

ok( $obj->method($my, $bad, $params) == DEATH, 'method dies as expected');

although I don't see how it would work since method dies when passed bad parameters and the test script stops.

Is there another way?

like image 881
gvkv Avatar asked Dec 21 '22 19:12

gvkv


1 Answers

Have you tried Test::Exception? dies_ok should do what you want. Eg:

# Check that something died - we do not care why
dies_ok { $foo->method } 'expecting to die';
like image 67
dsolimano Avatar answered Jan 16 '23 19:01

dsolimano