Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I'm looking for suggestions on how to handle this. Is it better to require modules that are only needed for testing, or to skip the tests with a message to the user?

Three options:

  1. Include Struct::Compare in the PREREQ_PM of your modules Makefile.PL.
  2. If it's a pure-perl module then package it in with your tests. Stick it in t/lib and add an appropriate use lib line to the test scripts that need it.
  3. Skip the tests. If you need to skip a few tests in a test script you can use the method tachyon showed. If you need to skip an entire script it might be easier to use skip_all something like this (untested code):
    BEGIN { use Test::More; eval 'use Struct::Compare'; Test::More->builder->skip_all("need Struct::Compare") if $@; }; # rest of test script here

As to which is better... harder call. My personal tendency would be to do (1) if the tests were about vital functionality, and (3) if it related to things like checking documentation.

For example in Test::Class I require Test::Differences and a few other modules just for testing in the Makefile.PL. However the test I use for documentation are skipped if the relevant modules (Pod::Coverage, Pod::Checker and IO::String) are not available.

Also - you might want to look at Test::Deep if you're testing complicated structures. Might make your job easier.


In reply to Re: Optional modules for tests? by adrianh
in thread Optional modules for tests? by sutch

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2024-04-25 18:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found