Learn R Programming

testextra (version 0.1.0.1)

catch_condition: Catch a condition for testing.

Description

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

Usage

catch_condition(code)

catch_all_conditions(code)

Arguments

code

code to run that should assert a condition.

Examples

Run this code
# NOT RUN {
(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.

# }

Run the code above in your browser using DataLab