I've been working on a large project and using unit tests heavily.
I very much like the idea of Test::NoWarnings, except for two minor quibbles: So instead I opted to make all warnings fatal
package WarningsDie; use strict; use warnings; use Carp; # confess for warnings and death BEGIN { $SIG{__WARN__} = sub {confess $_[0]}; $SIG{__DIE__} = sub {confess $_[0]}; } 1;
and included this module in Test::Harness
$ENV{HARNESS_PERL_SWITCHES} = "-Iblah/blah/blah -MWarningsDie";
Every test and module starts with  use strict and  use warnings.

My meditation:

it is comforting to use the test suite to rid your modules of warnings; give it a try.

rkg

Replies are listed 'Best First'.
Re: Die On Warnings
by perrin (Chancellor) on Sep 04, 2003 at 19:54 UTC
    You can also do it like this:
    use warnings FATAL => 'all';
Re: Die On Warnings
by liz (Monsignor) on Sep 04, 2003 at 18:18 UTC
    I've done that recently with all of my modules on CPAN. Especially if you run them with 5.8.1 (in which all test-suites are always run with warnings, even if you don't put them in yourself!).

    I would recommend every CPAN author to take the time to take a recent maint snapshot of Perl and try to install their modules with that release. You will surprised with the number of warnings you will get from what you think was perfectly good code (unless you were using warnings already, of course).

    I must however note that some warnings can not be traced that easily, especially when you're doing stuff with threads ;-(. These are usually inside multiple levels of eval and probably in the Test::xxx modules itself.

    And finally, it did show some of my module's tests were bogus, as they were always returning ok, which a warning pointed out to me. So I'm happy with some test-bugs having been stamped out.

    Liz

Re: Die On Warnings
by diotalevi (Canon) on Sep 04, 2003 at 21:13 UTC

    Since I can't use the warnings pragma on 5.005 I've taken to setting $^W during BEGIN in all of my tests. Adding on a handler to SIG{WARNING} completes the chain so tests don't pass unless the code runs without warnings. The actual module code doesn't set this of course.

Re: Die On Warnings
by antirice (Priest) on Sep 05, 2003 at 15:45 UTC

    I use a technique somewhat similar as a test harness when I first get a script. I created a module that actually will force the importing module to use strict and warnings as well as install confess as the default die and warning handler. I use this only for testing purposes and never production code.

    package WarningsStrictAndCarpOhMy; # worst name ever, I know use 5.006_001; use Carp; use strict; use warnings; sub import { my %config; undef @config{@_}; $^H |= strict->import unless exists $config{'no_strict'}; ${^WARNING_BITS} |= warnings->import; $SIG{__DIE__} = \&wasnt_me; $SIG{__WARN__} = \&wasnt_me; } sub wasnt_me { Carp::confess($_[0]); } 1;

    Just thought someone else might be able to get some use out of it

    antirice    
    The first rule of Perl club is - use Perl
    The
    ith rule of Perl club is - follow rule i - 1 for i > 1

      Can you explain the 1st two lines? They look like magic to me.
      undef @config{@_}; $^H |= strict->import unless exists $config{'no_strict'};
      Thanks --
      rkg

        The first two lines declare a hash and fill the hash with the elements of @_ as keys with each pointing to undef. The third line of the sub does a bitwise-or on $^H with the return of the default strict import unless "no_strict" was in @_. The first two lines are just a quick way of telling whether or not "no_strict" was present in the import list.

        In other words you control what operation gets performed from the import list. For more information I offer the following reading material: perldsc, use, Exporter, perlvar and perlmod.

        Hope this helps.

        antirice    
        The first rule of Perl club is - use Perl
        The
        ith rule of Perl club is - follow rule i - 1 for i > 1