++ed by:
JETEVE KARJALA TOBYINK DMOL MISHIN

7 PAUSE user(s)
5 non-PAUSE user(s).

Karen Etheridge

NAME

Test::Warnings - Test for warnings and the lack of them

VERSION

version 0.001

SYNOPSIS

    use Test::More;
    use Test::Warnings;

    pass('yay!');
    done_testing;

emits TAP:

    ok 1 - yay!
    ok 2 - no (unexpected) warnings (via done_testing)
    1..2

DESCRIPTION

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.

FUNCTIONS

The following functions are available for import (not included by default):

  • allow_warnings([bool])

    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 false.

  • allowing_warnings

    Returns whether we are currently allowing warnings (set by allow_warnings as described above).

  • had_no_warnings(<optional test name>)

    Tests whether there have been any warnings so far, not preceded by an allowing_warnings call. 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 :all.

TO DO (i.e. FUTURE FEATURES, MAYBE)

  • allow_warnings(qr/.../) - allow some warnings and not others

  • warning_is, warning_like etc... - inclusion of some Test::Warn-like functionality for testing the content of warnings, but closer to a Test::Fatal-like syntax

  • 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 done_testing.

SUPPORT

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 irc.perl.org.

SEE ALSO

Test::NoWarnings

Test::FailWarnings

AUTHOR

Karen Etheridge <ether@cpan.org>

COPYRIGHT AND LICENSE

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.