On 12/30/06, Paul LeoNerd Evans <[EMAIL PROTECTED]> wrote:
I recently stumbled upon Test::Exception, and wondered if it might make
my test scripts any better.. So far I'm struggling to see any benefit,
for quite a lot of cost.
Without using this module, my tests look like:
eval { code() };
ok( $@, 'An exception is raised' );
This is a buggy test. $@ can be cleared by destructors firing during
the end of the eval. You must test that the return value of eval is
true to be unambiguously correct.
my $ok = eval { code(); 1 };
my $e = $@;
ok( ! $ok, 'An exception was raised' );
like( $e, qr/.../, 'Exception was ...' );
like( $@, qr/some string match/, 'Exception type' );
You should expect $@ to be cleared during anything that might
conceivably call perl code. This includes using any operators other
than assignment. That includes comparison and boolean tests.
ok( [EMAIL PROTECTED]>isa( "Thing" ), 'Exception type' );
Same problem. Copy $@ away before examining it so it won't be
overwritten under your feet.
Have I missed something here? Does Test::Exception provide me with some
greater functionallity I haven't yet observed? Or should I just not
bother using it?
It provides you better verbs so your tests are talking about a task
and not required to perform the task. Your tests are still buggy
regardless of whether you use Test::Exception.
Josh