- TO DO (i.e. FUTURE FEATURES, MAYBE)
- SEE ALSO
- COPYRIGHT AND LICENSE
Test::Warnings - Test for warnings and the lack of them
use Test::More; use Test::Warnings; pass('yay!'); done_testing;
ok 1 - yay! ok 2 - no (unexpected) warnings (via done_testing) 1..2
If you've ever tried to use Test::NoWarnings to confirm there are no warnings generated by your tests, combined with the convenience of
done_testing to not have to declare a test count, you'll have discovered that these two features do not play well together, as the test count will be calculated before the warnings test is run, resulting in a TAP error. (See
examples/test_nowarnings.pl in this distribution for a demonstration.)
This module is intended to be used as a drop-in replacement for Test::NoWarnings: it also adds an extra test, but runs this test before
done_testing calculates the test count, rather than after. It does this by hooking into
done_testing as well as via an
END block. You can declare a plan, or not, and things will still Just Work.
It is actually equivalent to:
use Test::NoWarnings 1.04 ':early';
as warnings are still printed normally as they occur. You are safe, and enthusiastically encouraged, to perform a global search-replace of the above with
use Test::Warnings; whether or not your tests have a plan.
The following functions are available for import (not included by default):
When passed a true value, or no value at all, subsequent warnings will not result in a test failure; when passed a false value, subsequent warnings will result in a test failure. Initial value is
Returns whether we are currently allowing warnings (set by
allow_warningsas described above).
had_no_warnings(<optional test name>)
Tests whether there have been any warnings so far, not preceded by an
allowing_warningscall. It is run automatically at the end of all tests, but can also be called manually at any time, as often as desired.
All functions are also available by importing the tag
allow_warnings(qr/.../)- allow some warnings and not others
more sophisticated handling in subtests - if we save some state on the Test::Builder object itself, we can allow warnings in a subtest and then the state will revert when the subtest ends, as well as check for warnings at the end of every subtest via
Bugs may be submitted through https://rt.cpan.org/Public/Dist/Display.html?Name=Test-Warning. I am also usually active on irc, as 'ether' at
Karen Etheridge <email@example.com>
This software is copyright (c) 2013 by Karen Etheridge.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.