Test::FailWarnings


Test::NoWarnings does not play well with done_testing, but Test::FailWarnings does.

examples/test-warn/t/test_failwarnings.t
use strict;
use warnings;

use Test::More;
use Test::FailWarnings;

use MyTools qw(add);

is(add(1, 2), 3,   'first');
is(add(2), 2,      'second');
is(add(3), 3,      'third');
is(add(-1, 1), 0,  'fourth');

done_testing();

prove -v t/test_failwarnings.t



#   Failed test 'Test::FailWarnings should catch no warnings'
#   at /home/gabor/work/slides/perl/examples/test-warn/lib/MyTools.pm line 31.
# Warning was 'Use of uninitialized value $y in addition (+) at /home/gabor/work/slides/perl/examples/test-warn/lib/MyTools.pm line 31.'

#   Failed test 'Test::FailWarnings should catch no warnings'
#   at /home/gabor/work/slides/perl/examples/test-warn/lib/MyTools.pm line 31.
# Warning was 'Use of uninitialized value $y in addition (+) at /home/gabor/work/slides/perl/examples/test-warn/lib/MyTools.pm line 31.'
# Looks like you failed 2 tests of 6.
t/test_failwarnings.t .. 
ok 1 - first
not ok 2 - Test::FailWarnings should catch no warnings
ok 3 - second
not ok 4 - Test::FailWarnings should catch no warnings
ok 5 - third
ok 6 - fourth
1..6
Dubious, test returned 2 (wstat 512, 0x200)
Failed 2/6 subtests 

Test Summary Report
-------------------
t/test_failwarnings.t (Wstat: 512 Tests: 6 Failed: 2)
  Failed tests:  2, 4
  Non-zero exit status: 2
Files=1, Tests=6,  0 wallclock secs ( 0.02 usr  0.00 sys +  0.17 cusr  0.02 csys =  0.21 CPU)
Result: FAIL