expect_no_error {testthat} | R Documentation |
Does code run without error, warning, message, or other condition?
Description
These expectations are the opposite of expect_error()
,
expect_warning()
, expect_message()
, and expect_condition()
. They
assert the absence of an error, warning, or message, respectively.
Usage
expect_no_error(object, ..., message = NULL, class = NULL)
expect_no_warning(object, ..., message = NULL, class = NULL)
expect_no_message(object, ..., message = NULL, class = NULL)
expect_no_condition(object, ..., message = NULL, class = NULL)
Arguments
object |
Object to test. Supports limited unquoting to make it easier to generate readable failures within a function or for loop. See quasi_label for more details. |
... |
These dots are for future extensions and must be empty. |
message , class |
The default, In many cases, particularly when testing warnings and messages, you will
want to be more specific about the condition you are hoping not to see,
i.e. the condition that motivated you to write the test. Similar to
Note that you should only use |
Examples
expect_no_warning(1 + 1)
foo <- function(x) {
warning("This is a problem!")
}
# warning doesn't match so bubbles up:
expect_no_warning(foo(), message = "bananas")
# warning does match so causes a failure:
try(expect_no_warning(foo(), message = "problem"))