Skip to content

Commit

Permalink
Add doesn't-warn() utility test sub
Browse files Browse the repository at this point in the history
Checks whether a warning is emitted. This lets us test for warnings
faster than by using is_run to fire up an entire perl6 for us.
  • Loading branch information
zoffixznet committed Dec 26, 2016
1 parent f8070c4 commit 261c2c3
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/Test/Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,16 @@ multi warns-like (&code, $test, Str $desc) is export {
}
}

multi doesn't-warn (Str $code, |c) is export { doesn't-warn {$code.EVAL}, |c }
multi doesn't-warn (&code, Str $desc) is export {
my ($did-warn, $message) = False;
&code();
CONTROL { when CX::Warn { $did-warn = True; $message = .message; .resume } }

diag "code must not warn but it produced a warning: $message" if $did-warn;
nok $did-warn, $desc;
}

=begin pod
=head1 NAME
Expand Down Expand Up @@ -399,6 +409,15 @@ Catches warnings emited by the provided code (or, if Str is provided,
the EVAL of that Str) and smartmatches them against `$test`, using `cmp-ok`
to do the test..
=head2 doesn't-warn($code-or-str-to-eval, $desc)
multi doesn't-warn (Str $code, |c) { warns-like {$code.EVAL}, |c }
multi doesn't-warn (&code, Str $desc) {
B<NOTE: currently this sub won't catch COMPILE TIME warnings!>
Tests whether the code warns, passing the test if it doesn't.
=end pod

# vim: ft=perl6

0 comments on commit 261c2c3

Please sign in to comment.