Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • 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 sharing their wisdom with the Monastery: (5)
As of 2024-04-23 18:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found