On 31 Dec 2006, at 00:03, Paul LeoNerd Evans 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.
[ some options snipped ]
So, a lot more code, to achieve the same end result... Plus, I'm
now in
the situation where if Test::Exception isn't installed, the test won't
be run at all.
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?
You are, of course, free to not use it. I won't mind - honest :-)
For me the advantages are more intention revealing test code, and
reasonably cleanly dealing with some of odd things people do with
exceptions.
Personally I find reading something like:
lives_and { is $dt->answer, 42 } 'correct answer found';
a lot easier to read and maintain than something like:
my $answer = eval { $dt->answer };
if ( my $e = $@ ) {
fail "correct answer found";
diag "died unexpectedly ($e)";
} else {
is $answer, 42, 'correct answer found';
}
Personally my approach is to make "functional" test modules (as
opposed to things like Test::Perl::Critic and friends that are really
only of interest to me as a developer) proper dependencies and pull
them in. For me the benefits of having the module to hand outweigh
the disadvantages of adding an extra dependency. T::E is also a
moderately popular module so you will find it already installed in
lots of places.
As ever YMMV.
(the other option that's not been mentioned would be to include T::E
and its dependencies with the distribution. Not something I'd
recommend personally - just mentioned for completeness)
Cheers,
Adrian