This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Improve warning_is() to verify that exactly 0 or 1 warning has been seen.
authorNicholas Clark <nick@ccl4.org>
Sat, 5 Mar 2011 11:04:44 +0000 (11:04 +0000)
committerNicholas Clark <nick@ccl4.org>
Sat, 5 Mar 2011 20:26:10 +0000 (20:26 +0000)
t/test.pl

index c895d2a..a3bab73 100644 (file)
--- a/t/test.pl
+++ b/t/test.pl
@@ -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