Sign in to PrePAN

Test::Warnings Ensure that your tests didn't generate any unexpected warnings



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


    ok 1 - yay!
    some warning here at line 123
    not ok 2 - no (unexpected) warnings (via done_testing)


A trial release is up on CPAN at -- so the best documentation can be found in its POD there.

I also posted a blog entry -

I've also got some new features up on github - I'm not quite sure if the interface is right, so I don't want to release yet (but if I do, it would also be as a TRIAL):

  • Test::Warn-like functionality for capturing and testing warnings -

  • modification of allow_warnings() to take a regex(es) as well as a boolean, for more sophisticated screening out of some warnings -

Comments on the interface, as well as potential failing scenarios and pitfalls, are all actively solicited!


Why should I use this instead of Test::NoWarnings?
worr: See the blog entry linked
@worr: One huge drawback of Test::NoWarnings is that it doesn't play nicely with 'done_testing', a feature available in Test::More since 0.88 which lets you not have to declare a test count in your plan. This is because TNW adds an additional test in the END block, which is after done_testing has run and told Test::Builder that there will be no more tests.

Test::Warnings gets around this issue by hooking into done_testing instead of (actually as well as) END. I fully intend that Test::Warnings is a drop-in replacement for Test::NoWarnings, whether you like including a test count in plan, or prefer to use done_testing.

It also provides a had_no_warnings() function (like TNW does), which you can call at any time to check for surprise warnings. You can also declare certain areas of code as "there might be warnings here, so don't make this a test failure".

In a subsequent release (probably soon, as the code is already written in a side branch on github), you'll also be able to capture warnings from arbitrary code and test against its content, like Test::Warn does. These features will be doing to Test::Warn what Test::Fatal did to Test::Exception (provide the functionality people want, without all the crazy failure edge cases).
Have you considered to fix Test::NoWarnings instead of creating yet another module?

Please sign up to post a review.