G'day stevieb,

"... is there a way to flag it to say "don't say anything, except for my debug print statements"?"

You can do this with a combination of diag statements, SKIP: blocks, and a DEBUG flag. Here's a very simple, and highly contrived, example (pm_1194120.t):

use Test::More tests => 2; SKIP: { skip 'Debugging', 0 unless $ENV{PM_1194120_DEBUG}; diag 'DEBUG MODE!'; diag 'Debug statement #1 (1 == 1): ', 1 == 1 ? 'TRUE' : 'FALSE'; diag 'Debug statement #2 (1 == 0): ', 1 == 0 ? 'TRUE' : 'FALSE'; } SKIP: { skip 'Debugging', 2 if $ENV{PM_1194120_DEBUG}; is(1, 1, 'Test: 1 == 1'); isnt(1, 0, 'Test: 1 != 0'); }

Without the debug flag being set, here's verbose, non-verbose, and no STDOUT output (timing information elided):

$ export PM_1194120_DEBUG=0 $ prove -v pm_1194120.t pm_1194120.t .. 1..2 ok 1 - Test: 1 == 1 ok 2 - Test: 1 != 0 ok All tests successful. Files=1, Tests=2, ... Result: PASS $ prove pm_1194120.t pm_1194120.t .. ok All tests successful. Files=1, Tests=2, ... Result: PASS $ prove pm_1194120.t > /dev/null $

Here's the same commands, with the debug flag set:

$ export PM_1194120_DEBUG=1 $ prove -v pm_1194120.t pm_1194120.t .. 1..2 # DEBUG MODE! # Debug statement #1 (1 == 1): TRUE # Debug statement #2 (1 == 0): FALSE ok 1 # skip Debugging ok 2 # skip Debugging ok All tests successful. Files=1, Tests=2, ... Result: PASS $ prove pm_1194120.t pm_1194120.t .. # DEBUG MODE! # Debug statement #1 (1 == 1): TRUE # Debug statement #2 (1 == 0): FALSE pm_1194120.t .. ok All tests successful. Files=1, Tests=2, ... Result: PASS $ prove pm_1194120.t > /dev/null # DEBUG MODE! # Debug statement #1 (1 == 1): TRUE # Debug statement #2 (1 == 0): FALSE $

While that last one does exactly what you ask (i.e. nothing but debug statement output); consider whether you really want to throw away STDOUT (it's only a few lines and could provide useful feedback).

Obviously, there's a huge number of variations on that theme. You could have more than one debug flag and they certainly don't need to be environmental variables. I've separated the diag statements from the tests, but there could be a mixture; and, not everything needs to be in a SKIP: block.

See also: prove (for a variety of other options, '-b' is one I usually need); and Test::More (in particular, the Diagnostics, Conditional tests, and Test control sections).

— Ken


In reply to Re: Quieting Test::More by kcott
in thread Quieting Test::More by stevieb

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.