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
Stories, comments, journals, and other submissions on use Perl; are Copyright 1998-2006, their respective owners.
what's really wrong with use_ok? (Score:1)
I see the value of having a test script which reality-checks that everything compiles, especially if there are big gaps in a test suite.
But I don't see what's wrong with "use_ok()" for a module that you neede to "use" anyway. It's hardly any more syntax. What's the harm?
Re:what's really wrong with use_ok? (Score:2)
First, here's the general 'correct' incantation:
If the module is not used in a "BEGIN" block, compile-time behavior is ignored (e.g., exported functions may alter how your code parses).
If you don't have the 'or die' (or BAIL_OUT), things can get even worse. If the module fails to load, but most of it compiled, you can get partially compiled code loaded. Your 'use_ok' failure may scroll off the screen but failures show up much later in the test program run (this is a very subtle bug and one which once caused and fellow programmers hours of debugging grief).
Finally, where's the canonical spot for that use_ok statement? I often see test suites where I open up four of five different test modules, each of which has identical use_ok statements at the top. Testing something more than once doesn't make it more true. However, if you think you need to test 'use'ing a module more than once -- perhaps it won't load if another module loads -- the you probably have some bad coupling in your code and your "use Some::Module" statement in the test will catch the error anyway. It's annoying to have to write that entire BEGIN block every time I want to use a module. Just putting it into one "load" test means I don't have to worry about that any more.
Reply to This
Parent
Re:what's really wrong with use_ok? summary (Score:1)
So I would say it summarizes like this:
If "use" a module it fails, the test grinds to a halt, which is nearly always a reasonable result.
With "use_ok", the test may /continue/ causing unexpected results later on, because the module is not loaded, or worse, partially loaded.
Thanks for your clarification, Ovid.