View source: R/ut_cmp_warning.R
ut_cmp_warning | R Documentation |
A helper to catch expected warnings and ensure they match what is expected
ut_cmp_warning(code, expected_regexp = NULL, expected_count = 1L,
ignore.case = FALSE, perl = FALSE, fixed = FALSE)
code |
Code expression to test, should generate one or more warnings |
expected_regexp |
Regular expression(s) that the warning(s) should match.
If |
expected_count |
The number of warnings that should be issued.
If |
ignore.case |
Passed to |
perl |
Passed to |
fixed |
Passed to |
If expected_regexp
is a single regular expression, then all warnings must match the
regular expression.
If expected_regexp
is a vector then:
all warnings must match at least one regular expression
all regular expressions must match at least one warning
Returns TRUE
if code
generates warnings that match expected_regexp
and
expected_count
.
If code
generates warnings that do not match expected_regexp
and
expected_count
returns a vector of strings that detail the difference between the expected
and actual warnings.
Returns "No warnings issued"
if code
does not generate any warnings.
ok(ut_cmp_warning({
warning("Wooooo!")
}, "^woo", ignore.case = TRUE), "Issued a haunting warning")
ok(ut_cmp_warning({
warning("Woooo!")
warning("Woooooo!")
}, "^Woo", expected_count = 2L), "Issued two haunting warnings")
ok(ut_cmp_warning({
warning("Woooo!")
warning("Boooo!")
}, c("^Woo", "^Boo"), expected_count = 2L), "Issued a haunting and a diapproving warning")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.