If you've distributed a module for others to use, you might find that you want to use Test::Differences in your tests, but users might not want yet another module to install. You might want the verbose output of Test::Differences because it makes tracking down problems much easier, but hey, getting a less verbose test report is better than none at all (hell, consider yourself lucky if you get any test reports).

I want to upgrade Class::Trait soon and make the use of Test::Differences optional with code similar to the following:

#!/usr/bin/perl use strict; use warnings; use Test::More tests => 2; BEGIN { eval "use Test::Differences"; if ($@) { *eq_or_diff = \&is_deeply; } } eq_or_diff [ 3, 2 ], [ 3, 2 ], 'first test'; eq_or_diff [ 3, 2 ], [ 3, 2, 1 ], 'second test';

If they have Test::Differences, great. If they don't, they fall back to the Test::More::is_deeply behavior. Not as useful for diagnostics, but better than nothing.

This is something I'm thinking about more and more because while I don't see why users should object to another test module being installed, the reality is, the fewer dependencies we require, the more likely our modules are to be used. I might even use a trick like making a custom test module to make this easier to manage (such as having an optional Test::NoWarnings) and other things.

I recommend all programmers looking at distributing code for general use figure out ways that can gracefully downgrade functionality (if appropriate) rather than force people to install stuff which they may not want or which might itself be difficult to install. POD tests, for example, are excellent candidates for skipping entirely on an end user's machine.

Cheers,
Ovid

New address of my CGI Course.


In reply to Gracefully Downgrading Behavior by Ovid

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.