Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re^6: Strategy for conditional logging in tests

by andreas1234567 (Vicar)
on Apr 02, 2008 at 09:29 UTC ( #677920=note: print w/ replies, xml ) Need Help??

in reply to Re^5: Strategy for conditional logging in tests
in thread Strategy for conditional logging in tests

Brilliant, I never thought of that. It works:

# foo.t use strict; use warnings; use Test::More qw/no_plan/; use Test::Exception; require_ok(q{}); Log::Log4perl->appender_thresholds_adjust(7); # disable logging # ------ negative tests for add() ------ throws_ok { add(); } qr/error/i, q{Expect error when no args}; ... Log::Log4perl->appender_thresholds_adjust(-7); # enable logging # ------ positive tests for add() ------ cmp_ok(add(2,2), q{==}, 4, q{Expect 2+2=4}); # Note: I want a warning here: cmp_ok(add(1000,1000), q{==}, 2000, q{Expect 1000+1000=2000}); __END__
This gives me the warning I wanted:
$ prove foo.t foo......1/? [WARN] 2008/04/02 11:26:41 main::add - possible + overflow foo......ok All tests successful. Files=1, Tests=8, 1 wallclock secs ( 0.01 usr 0.00 sys + 0.08 cusr + 0.01 csys = 0.10 CPU) Result: PASS
Thanks Thilosophy!

Comment on Re^6: Strategy for conditional logging in tests
Select or Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2015-12-02 04:01 GMT
Find Nodes?
    Voting Booth?

    My keyboard shows this many letters:

    Results (33 votes), past polls