DESCRIPTION

Test::Fatal is an alternative to the popular Test::Exception. It does much less, but should allow greater flexibility in testing exception-throwing code with about the same amount of typing.

It exports one routine by default: exception.

FUNCTIONS

exception

my $exception = exception { ... };

exception takes a bare block of code and returns the exception thrown by that block. If no exception was thrown, it returns undef.

ACHTUNG! If the block results in a false exception, such as 0 or the empty string, Test::Fatal itself will die. Since either of these cases indicates a serious problem with the system under testing, this behavior is considered a feature. If you must test for these conditions, you should use Try::Tiny's try/catch mechanism. (Try::Tiny is the underlying exception handling system of Test::Fatal.)

Note that there is no TAP assert being performed. In other words, no "ok" or "not ok" line is emitted. It's up to you to use the rest of exception in an existing test like ok, isa_ok, is, et cetera.

exception does not alter the stack presented to the called block, meaning that if the exception returned has a stack trace, it will include some frames between the code calling exception and the thing throwing the exception. This is considered a feature because it avoids the occasionally twitchy Sub::Uplevel mechanism.