atExpectWarnings
Check That Expression Causes Expected Warnings

Description

Evaluate an expression and verify that it causes the warning messages that it should.

Usage

atExpectWarnings(expr, expected = ".")

Arguments

expr An expression to evaluate. It will be taken literally, as in system.time().
expected Regular expressions that should match the expected warning messages. See regexpr for the syntax. "." means to match any warning.
Value
TRUE if the expression evaluates to TRUE and causes the expected warnings. Otherwise a list containing a description of the problem. This sort of output is expected by assertionTest.
Note
If an expression is expected to cause both warnings and an error then wrap it first in atExpectStop and then in atExpectWarnings.
See Also
This is written to be used in test files run by assertionTest, which will report a test failure if there are any warnings not caught by a call to atExpectWarnings().
Examples
## Not run: 
# First two examples should return TRUE
atExpectWarnings({
    warning("Comparing integer and complex number")
    1L == (1+0i)},
    expected = "integer.*complex")
atExpectWarnings(
    atExpectStop({warning("Hmm, possible problem")
    stop("Oops")},
    expected="Oops"),
    expected = "Hmm")

# Next one should describe lack of expected warning atExpectWarnings(all(is.finite(log(3:4))), "NaNs produced")

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

Package assertionTest version 6.1.4-13
Package Index