http://qs321.pair.com?node_id=1194138


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