diff options
author | Nicholas Clark <nick@ccl4.org> | 2011-03-05 11:04:44 +0000 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2011-03-05 20:26:10 +0000 |
commit | 96980024b32bc912ece29c8bb2f36420dce8d27c (patch) | |
tree | 72aa775984dd2d12b53155e79ad2eefed20ecdec /t/test.pl | |
parent | c11a8df30b4de6dbf6ce9fa1be2bf37869beb97d (diff) | |
download | perl-96980024b32bc912ece29c8bb2f36420dce8d27c.tar.gz |
Improve warning_is() to verify that exactly 0 or 1 warning has been seen.
Diffstat (limited to 't/test.pl')
-rw-r--r-- | t/test.pl | 14 |
1 files changed, 11 insertions, 3 deletions
@@ -1065,14 +1065,22 @@ WHOA sub warning_is { my ($code, $expect, $name) = @_; - my $w; - local $SIG {__WARN__} = sub {$w .= join "" => @_}; + my @w; + local $SIG {__WARN__} = sub {push @w, join "", @_}; { use warnings 'all'; &$code; } local $Level = $Level + 1; - is($w, $expect, $name); + if(!defined $expect) { + is("@w", '', $name); + } elsif (@w == 1) { + is($w[0], $expect, $name); + } else { + # This will fail, generating diagnostics + cmp_ok(scalar @w, '==', 1, $name); + diag("Warning: $_") foreach @w; + } } # Set a watchdog to timeout the entire test file |