ut_cmp_warning.Rd
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 expression to test, should generate one or more warnings
Regular expression(s) that the warning(s) should match.
If NULL
the warning message will not be checked.
Multiple regexes can be given as a vector; see details.
The number of warnings that should be issued.
If NULL
then one or more warnings should be issued.
Setting expected_count
to zero is not allowed.
Passed to grep
Passed to grep
Passed to grep
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.
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
ok(ut_cmp_warning({
warning("Wooooo!")
}, "^woo", ignore.case = TRUE), "Issued a haunting warning")
#> ok - Issued a haunting warning
ok(ut_cmp_warning({
warning("Woooo!")
warning("Woooooo!")
}, "^Woo", expected_count = 2L), "Issued two haunting warnings")
#> ok - 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")
#> ok - Issued a haunting and a diapproving warning