catch_condition: Catch a condition for testing.

Description Usage Arguments Examples

View source: R/catch_condition.R

Description

This function captures a condition object such as a warning or error, to allow for testing components and classes.

Usage

1
2
3

Arguments

code

code to run that should assert a condition.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
(cond <- catch_condition(stop("catch me.")))
class(cond)

my_fun <- function(){
    message("a message")
    warning("a warning")
    pkg_message("a package message", scope="test")
    pkg_warning("a package warning", scope="test")
    pkg_error("a package error", scope='test')
}
conditions <- catch_all_conditions(my_fun())
conditions$messages
conditions$warnings
conditions$error  # only one error can be caught at a time.

testextra documentation built on Dec. 18, 2019, 9:38 a.m.