How should I promote Perl warnings to fatal errors during development?

前端 未结 2 1570
我在风中等你
我在风中等你 2021-02-13 13:21

When running an applications test suite I want to promote all Perl compile and run-time warnings (eg the \"Uninitialized variable\" warning) to fatal errors so that I and the ot

相关标签:
2条回答
  • 2021-02-13 14:02

    I think you're looking for Test::NoWarnings.

    0 讨论(0)
  • 2021-02-13 14:05

    The reason use warnings FATAL => qw( all ); isn't working for you is because use warnings is lexically scoped. So any warnings produced inside TestHelper.pm would be fatal, but warnings produced elsewhere will work as normal.

    If you want to enable fatal warnings globally, I think a $SIG{__WARN__} handler is probably the only way to do it. If you don't want it to blow up on the first warning, you could let your handler store them in an array, then check it in an END block.

    my @WARNINGS;
    $SIG{__WARN__} = sub { push @WARNINGS, shift };
    
    END { 
        if ( @WARNINGS )  {       
            print STDERR "There were warnings!\n";
            print "$_\n" for @WARNINGS;
            exit 1;
        }
    }
    
    0 讨论(0)
提交回复
热议问题