Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

Ovid
  (email not shown publicly)
http://publius-ovidius.livejournal.com/
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Tuesday December 11, 2007
09:51 AM

use_ok or die, die, die

[ #35082 ]

I can't tell you how many times I get tired of mysterious test behavior because someone forgot to put an 'or die' at the end of a use_ok() test. With this vim function, typing ',use' will convert all 'use_ok $package;' to have an 'or die' at the end.

map ,use :call UseOrDie()<cr>
function! UseOrDie()
    %s/^\(\s*use_ok\s*(\?['"].*['"])\?\)\s*;/\1 or die;/
endfunction

For those not familiar with the problem, let's say you have 300 tests in one .t file. The 'use_ok' fails, but scrolls off the screen and if you forget to fix the first failure first, you get totally mystified by failures which occur later. I've had this happen to me several times and it's frustrating. use_ok() and require_ok() should both die. If you use require_ok(), you can switch the above to this:

map ,use :call UseOrDie()<cr>
function! UseOrDie()
    %s/^\(\s*\(use\|require\)_ok\s*(\?['"].*['"])\?\)\s*;/\2 or die;/
endfunction

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • I just don't use them at all as ordinary use and require cause nearly exactly same test failure if there is something wrong with module you are trying to load.
    --

    Ilya Martynov (http://martynov.org/ [martynov.org])

  • I use a 01_compile.t in all my modules that contains all the load-integrity testing. So regular use_ok stuff, plugin loading, checking $VERSION values all match, does Exporter export what it is supposed to, etc...

    That way I get a full report on load failures, and the rest of the tests can totally ignore the issue and load normally.
    • That's what I've done with Test::Harness [cpan.org], but this isn't my code base.

      • It's our code base, including yours, no?

        And I believe we already have a test file that loads all modules, but I'm not 100% certain (well, you shouldn't trust anything I say today anyway 8^)