Search code examples
perltestingtap

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


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?


Solution

  • 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';