Expectation predicate for testing that a given function call throws a condition

expect_condition(
  current,
  pattern = NULL,
  class = NULL,
  ...,
  info = NA_character_
)

Arguments

current

[R object or expression] Object or expression to be tested

pattern

[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

class

[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

info

[character(1L)] Optional user-defined message; must be a single string value

Value

A tinytest object. A tinytest object is a logical with attributes holding information about the test that was run

See also

testthat equivalent: testthat::expect_condition()

Other condition expectation predicates: expect_no_condition()

Examples

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