assert: Explicitly state that we expect no errors to occur.

Description Usage Arguments Details Examples

View source: R/assert.R

Description

Note we could simply write the expression itself and let it error, but using assert makes the intention of the code clearer (like using base::force).

Usage

1
assert(expr, ...)

Arguments

expr

expression. This expression should not error.

...

additional arguments to expect_false, like info.

Details

For testing the converse, there already is expect_error.

Examples

1
2
3
4
assert(1 + 1) # This will throw no error.
# stopifnot(is(tryCatch(error = identity, assert(not_existent)), 'error'))
# The above will produce an error. In unit tests, it will be clear this
# means "We expect no error to occur."

robertzk/testthatsomemore documentation built on Aug. 15, 2017, 7:45 a.m.