Using -w to enable warnings is a pretty-darn-good practice when doing development in Perl. But sometimes it's necessary to turn warnings off temporarily to avoid expected warnings while doing something low-level. You do this by clearing the special variable $^W. The operative word is "temporarily". Turning off warnings without turning them back on is a pretty-darn-bad practice.
Hence a useful pair of tests to include when you're testing code that involves third-party software (i.e., stuff Not Under Your Control):
is( $^W, 1, 'warnings are on' ); third_party_code(); is( $^W, 1, 'warnings are still on' );
This test pair might save you hours of headscratching.
In some cases, the third party software you're testing might itself be blameless, falling prey to problems in its dependencies. For example, Test::MockClass uses Hook::WrapSub, which sets $^W = 0; and, for reasons I'm unable to fathom, leaves it there. (Bug report submitted.)
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Testing $^W
by tilly (Archbishop) on Nov 04, 2005 at 03:09 UTC | |
Re: Testing $^W
by Perl Mouse (Chaplain) on Nov 04, 2005 at 09:57 UTC | |
by Anonymous Monk on Nov 04, 2005 at 18:39 UTC | |
by jthalhammer (Friar) on Nov 06, 2005 at 23:14 UTC | |
Re: Testing $^W
by itub (Priest) on Nov 04, 2005 at 04:06 UTC |