Warnings in tests

David Cantrell david at cantrell.org.uk
Thu Mar 15 11:05:47 GMT 2007

There's a thread in perl-qa at the moment in which I've argued that test
suites which ignore warnings being emitted by the code they're testing
are broken, and that any unexpected warnings emitted during testing
should be considered test failures.

As an experiment, I want to see if I can find a way of promoting other
peoples' uncaught warnings to be fatal.  The obvious way is to insert
  $SIG{__WARN__} = sub { die("Caught a warning, making it fatal\n", @_) }

into the environment in which their tests run.  Trouble is, I want this
to happen when I use CPAN.pm to (try to) install their stuff.  CPAN.pm
calls make(1) to run 'make test', which in turn calls 'perl blahblah'
all in seperate processes, which internally use fork() and exec() so I
can't just set that __WARN__ handler when I run the CPAN shell.  It
needs to be inserted by the perl process that is exec()ed to run the
tests.  Can anyone think of a way I can make it do that, without editing
any code in the random modules I'm installing?

The only way I can think of is to replace my perl executable with a
script that does ...

  /path/to/real/perl -MThingy::To::Make::Warnings::Fatal "$@"

but that's icky.  Can anyone think of a better way?

David Cantrell | A machine for turning tea into grumpiness

  engineer: n. one who, regardless of how much effort he puts in
    to a job, will never satisfy either the suits or the scientists

More information about the london.pm mailing list