atExpectStop
Verify That an Expression Causes an Error

Description

Evaluate an expression and return TRUE if it throws the expected error message.

Usage

   atExpectStop(expr, expected = ".")

Arguments

expr An expression to evaluate. It will be taken literally, as in system.time().
expected A regular expression that matches the expected error message. See regexpr for the syntax; "." matches any message.
Value
TRUE if the expression causes the expected message. Otherwise a string describing the discrepency. This is the type of output that assertionTest requires.
See Also
atExpectWarnings does a similar job for warnings.
Examples
## Not run: 
# The following may be put into a test.t file
# and run by assertionTest.  The first should return TRUE.
atExpectStop(lm(y ~ noSuchData), expected="noSuchData.*not found")
# expect complaints from the following two:
atExpectStop(stop("Oops"), expected="a problem happened")
atExpectStop(1L+2L == 3L, expected="integer arithment overflow")

# Run example test files in assertionTest/test-ex assertionTest(system.file(package="assertionTest", "test-ex", "allbad.t")) ## End(Not run)

Package assertionTest version 6.1.1-7
Package Index