* Paul LeoNerd Evans <[EMAIL PROTECTED]> [2006-12-31 01:05]: > Whereas, if I want to use the module, I have to first note that > it isn't standard install, so I should start the test with > something like: > > eval { require Test::Exception; import Test::Exception; }; > my $can_test_exception = $@ ? 0 : 1; > > Then each test that might use it should be: > > SKIP: { > skip "No Test::Exception", 1 unless $can_test_exception; > > dies_ok( sub { code() }, > 'An exception is raised' ); > }
You’re not using enough magic. If you *really* want to make your tests run even if Test::Exception isn’t installed, stick the test in a BEGIN block that conditionally installs a `dies_ok` stub. Something like BEGIN { unless( eval "use Test::Exception; 1" ) { *dies_ok = sub { SKIP: { skip "Need Test::Exception for: $_[1]", 1; } }; } } Something like that anyway; untested. > 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. Well yes. The same can be said of relying on *any* module whatsoever; you can always “just” reimplement the functionality in your code and not have to rely on the module. You don’t need Test::Exception to test exception-throwing, but if you need to test a lot of that, then Test::Exception will make your tests a *whole* lot more readable. (Actually, I’d argue that it should be merged into Test::More someday… too cheap in terms of code complexity and at the same time too useful to make people decide whether they want a new dependency just to get it.) Regards, -- Aristotle Pagaltzis // <http://plasmasturm.org/>