Expectation predicate for testing that a given function call throws a condition
expect_condition(
current,
pattern = NULL,
class = NULL,
...,
info = NA_character_
)[R object or expression] Object or expression to be tested
[character(1L)] A regular expression to match the
condition message; any condition thrown that does not match pattern
will trigger a failure. Must be a single character string
[character] Optional vector of classes from which the
condition should inherit; any conditions thrown that do no inherit from
class will trigger a failure
Ignored
[character(1L)] Optional user-defined message; must be a
single string value
A tinytest object. A tinytest object is a
logical with attributes holding information about the
test that was run
testthat equivalent:
testthat::expect_condition()
Other condition expectation predicates:
expect_no_condition()
expect_condition(message("test message")) # Pass
#> ----- PASSED : <-->
#> call| expect_condition(message("test message"))
expect_condition(warning("test warning")) # Pass
#> ----- PASSED : <-->
#> call| expect_condition(warning("test warning"))
expect_condition(stop("test error")) # Pass
#> ----- PASSED : <-->
#> call| expect_condition(stop("test error"))
expect_condition("tomato") # Fail
#> ----- FAILED[xcpt]: <-->
#> call| expect_condition("tomato")
#> diff| Expected a condition to be thrown, but none were
expect_condition(message("test message"), class = "specialMessage") # Fail
#> ----- FAILED[xcpt]: <-->
#> call| expect_condition(message("test message"), class = "specialMessage")
#> diff| Expected a condition inheriting from 'specialMessage' to be thrown
expect_condition(message("test message"), pattern = "tomato") # Fail
#> ----- FAILED[xcpt]: <-->
#> call| expect_condition(message("test message"), pattern = "tomato")
#> diff| Expected a condition matching the pattern 'tomato' to be thrown