Hi stevieb,
Testing for warnings is a good idea, and ++ for the rest of your post, I just wanted to point out that I got burned by code similar to what you posted: You can't know how many warnings a piece of code will produce, especially over various Perl versions. Example: this CPAN Testers failure is caused by my test code expecting an exact number of warnings, but Perl 5.6 produced an extra warning in this case. Here's the code I currently use (in addition to Test::Fatal):
sub warns (&) { my $sub = shift; my @warns; { local $SIG{__WARN__} = sub { push @warns, shift }; $sub->() } return @warns; } # example usage use Test::More tests=>2; my @w = warns { is some_func(), "bar"; }; is grep({/\bfoo\b/} @w), 1; sub some_func { # could be any number of other warnings here warn "foo"; return "bar"; }
Regards,
-- Hauke D
In reply to Re^2: Is validation of all subroutine arguments overkill?
by haukex
in thread Is validation of all subroutine arguments overkill?
by nysus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |