| gives_warning {testthat} | R Documentation |
Needs to match at least one of the warnings produced by the expression.
gives_warning(regexp = NULL, all = FALSE, ...) expect_warning(object, regexp = NULL, ..., info = NULL, label = NULL)
regexp |
optional regular expression to match. If not specified, just asserts that expression gives some warning. |
all |
if |
... |
other arguments passed to |
object |
object to test |
info |
extra information to be included in the message (useful when writing tests in loops). |
label |
object label. When |
Other expectations: equals_reference,
expect_equal_to_reference;
equals, expect_equal;
expect-compare,
expect_less_than,
expect_more_than,
is_less_than, is_more_than;
expect_equivalent,
is_equivalent_to;
expect_error, throws_error;
expect_false, expect_true,
is_false, is_true;
expect_identical,
is_identical_to; expect_is,
is_a; expect_match,
matches; expect_message,
shows_message; expect_named,
has_names; expect_null,
is_null; expect_output,
prints_text; takes_less_than
f <- function(x) {
if (x < 0) warning("*x* is already negative")
-x
}
expect_warning(f(-1))
expect_warning(f(-1), "already negative")
## Not run: expect_warning(f(1))
# You can use the arguments of grepl to control the matching
expect_warning(f(-1), "*x*", fixed = TRUE)
expect_warning(f(-1), "NEGATIVE", ignore.case = TRUE)