My usual solution is to eval / require the testing module during the tests, and to skip the tests if it is not available. I also document what is needed (my last test lists all the modules used during the tests, with the reason they are used).

I even go as far as having a function that lets me pretend that the module is not avilable, in order to be able to run the tests in several combinations (or inevitably I will miss some combinations, or skip the wrong number of tests).

Here is the snippet of code I use (comments welcome, and of course, once a module has been _used, it's too late tp disallow its use):

{ my %used; # module => 1 if require ok, 0 otherwise my %disallowed; # for testing, refuses to _use modules in this hash sub _disallow_use { my( @modules)= @_; $disallowed{$_}= 1 foreach (@modules); } sub _allow_use { my( @modules)= @_; $disallowed{$_}= 0 foreach (@modules); } sub _use { my( $module, $version)= @_; $version ||= 0; if( $disallowed{$module}) { return 0; } if( $used{$module}) { return 1; } if( eval "require $module") { import $module; $used{$module}= 1; + no strict 'refs'; if( ${"${module}::VERSION"} >= $ve +rsion ) { return 1; } else + { return 0; } } else { $used{$module}= 0; + return 0; } } }

In reply to Re: Should I use modules to augment testing by mirod
in thread Should I use modules to augment testing by GrandFather

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.