Test::NoWarnings 1.04 - Immediate warnings with :early pragma


One of the common gotchas with Test::NoWarnings is that the warnings are collected up and displayed in one go at the end of the script.

While this is strictly speaking the correct time to show them and has the least likelihood to result in a collision with some other test module resulting in an explosion, it makes debugging test scripts much more difficult.

Since I took over Test::NoWarnings a number of people have asked me to “fix” this problem.

After much thought, I’ve decided to leave Test::NoWarnings default behaviour the way it is and show everything at the end.

Instead I’ve added a specific debugging aid in the form of an :early pragma.

use Test::NoWarnings 1.04 ':early';

The :early pragma explicitly turns on emitting warnings at the time they occur instead of gathering them until the end.

As this feature is still experimental and I need some time to see any potential fallout, initially I recommend turning it on while you are debugging a test script and then turning it off once the test script passes.

In the future I may switch this to be the default instead. If this happens I’ll add a back-compatibility pragma to provide an easier upgrade path for legacy modules.

But for now, you should have an option to remove the most immediate pain.


Nice addition, thanks for letting us know :)


Could this be controlled by an environment variable?

I think normally I'd want it to be at the end but when I am debugging I might want to be it right where it happened.

Leave a comment

About Adam Kennedy

user-pic I blog about Perl.