http://www.perlmonks.org?node_id=477062

I posted this over at use.perl. I figured I'd stuff it here some someone else may learn from my pain.

I'm such and idiot. I can't believe I never noticed this before. It's quite a dangerous oversight too since it meant tests didn't register a pass or a fail; no output at all which threw off the test counts. Don't let this happen to you.

---some.t--- use Test::More tests => 2; use Error ':try'; use_ok('MyModule'); try { MyModule->foo('badparam'); } catch with MyModule::Exception { pass; } otherwise { fail; }

Of course, if the module throws the exception, we pass. If it throws another exception (or die), we fail. But, if the module unexpectedly succeeds, we neither fail nor pass. That's not so bad right? THe count mismatch would cause the test to fail right? Sure, but picture this:

---some.t--- use Test::More tests => 2; use Error ':try'; use_ok('MyModule'); try { MyModule->foo('badparam'); } catch with MyModule::Exception { pass; } otherwise { fail; } ok('added this test later in this huge test file');

In this scenerio, you've added a test but forgot to update the test plan count. Now you've declared 2 tests and passed 2 tests. No failures and you never know a completely failing test...didn't. This is ever more true if you're using no_plan. Probably another reason not to ever do that. :-)

Ths answer of course is to put a fail in the try block. Not something that seams obvious upon first thought.

---some.t--- use Test::More tests => 2; use Error ':try'; use_ok('MyModule'); try { MyModule->foo('badparam'); fail; } catch with MyModule::Exception { pass; } otherwise { fail; }

Boy do I have a lot of test files to double check. That was a painful lesson.