Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Quieting Test::More

by kcott (Bishop)
on Jul 04, 2017 at 08:03 UTC ( #1194138=note: print w/replies, xml ) Need Help??


in reply to Quieting Test::More

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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1194138]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2020-09-26 15:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If at first I donít succeed, I Ö










    Results (141 votes). Check out past polls.

    Notices?