Test with warnings
First we'll check if the fibonacci function works correctly even when called with
negative numbers.
examples/test-warn/t/fibonacci_negative.t
use strict; use warnings; use Test::More; use MyTools qw(fibo); subtest negative => sub { my $result = fibo(-1); is($result, undef, 'fibonacci on -1 returns undef'); }; done_testing;
prove -lv t/fibonacci_negative.t
Given number must be > 0 at /home/gabor/work/slides/perl/examples/test-warn/lib/MyTools.pm line 23. t/fibonacci_negative.t .. # Subtest: negative ok 1 - fibonacci on -1 returns undef 1..1 ok 1 - negative 1..1 ok All tests successful. Files=1, Tests=1, 0 wallclock secs ( 0.01 usr 0.00 sys + 0.16 cusr 0.01 csys = 0.18 CPU) Result: PASS
In the above code the tests are passing but there is a warning as well.
This is an expected warning so we don't need to worry about it. But then again people
or code using our module might start to rely on this warning. We would like to make sure
it won't disappear or change by mistake.