like($w, qr/$pattern/, "Got warning /$pattern/");
}
-sub may_not_warn {
- my ($code, $name) = @_;
- my $w;
- local $SIG {__WARN__} = sub {$w .= join "" => @_};
- use warnings 'all';
- ref $code ? &$code : eval $code;
- is($w, undef, $name) or diag("Got warning '$w'");
-}
-
1;
{
my $message = '"1" is not \s';
- may_not_warn sub {ok ("1\n" x 102 !~ /^\s*\n/m, $message)}, "$message (did not warn)";
+ warning_is(sub {unlike("1\n" x 102, qr/^\s*\n/m, $message)},
+ undef, "$message (did not warn)");
}
{
my $SIGMA = "\N{GREEK CAPITAL LETTER SIGMA}";
my $char = "\N{COMBINING GREEK PERISPOMENI}";
- may_not_warn sub {unlike("_:$char:_", qr/_:$SIGMA:_/i, $message)},
- 'Did not warn [change a5961de5f4215b5c]';
+ warning_is(sub {unlike("_:$char:_", qr/_:$SIGMA:_/i, $message)}, undef,
+ 'Did not warn [change a5961de5f4215b5c]');
}
{
my $s = "\x{e4}\x{100}";
# This is not expected to match: the point is that
# neither should we get "Malformed UTF-8" warnings.
- may_not_warn sub {$s =~ /\G(.+?)\n/gcs}, "No 'Malformed UTF-8' warning";
+ warning_is(sub {$s =~ /\G(.+?)\n/gcs}, undef,
+ "No 'Malformed UTF-8' warning");
my @c;
push @c => $1 while $s =~ /\G(.)/gs;
_ok( !$diag, _where(), $name );
}
+sub warning_is {
+ my ($code, $expect, $name) = @_;
+ my $w;
+ local $SIG {__WARN__} = sub {$w .= join "" => @_};
+ {
+ use warnings 'all';
+ &$code;
+ }
+ local $Level = $Level + 1;
+ is($w, $expect, $name);
+}
+
# Set a watchdog to timeout the entire test file
# NOTE: If the test file uses 'threads', then call the watchdog() function
# _AFTER_ the 'threads' module is loaded.