assertionTest
Test Expressions

Description

Check that all expressions in a file evaluate to TRUE. A message will be printed for each that does not evaluate to TRUE or that emits warnings, has an error, or changes the random number generator seed.

Usage

assertionTest(file, verbose = FALSE, strict = FALSE, local = TRUE,
              cleanup = TRUE, list.output = FALSE, silent = list.output,
              eval.in.try = TRUE, evalREX = FALSE)
## S3 method for class 'assertionTestResults':
print(x, ...)

Arguments

file A file name or vector of file names or a connection object. The contents of the file(s) will be read by parse().
verbose By default assertionTest() will print an expression and its output only if the expression does not cleanly evaluate to TRUE. If verbose=TRUE then it will print each expression and its output.
strict This argument is here for historical purposes and may be removed.
local If TRUE (the default), the expressions in file will be evaluated in a newly created environment, a daughter of .GlobalEnv. If FALSE they will be evaluated in .GlobalEnv itself so that assignments made in the test will remain after the test is over.
cleanup The test files may have calls to atOnExit(expr), which asks that expr be run at the end of the tests done in one call to assertionTest. expr typically removes temporary datasets or files used in the tests. Specifying cleanup=FALSE means that those expressions will not be run. Note that if local=TRUE, the environment used in the test will disappear at the end of the test so the objects in it will be removed anyway.
list.output If TRUE assertionTest will return a list of class "assertionTestResults" containing the tests and their values. print.assertionTestResults is a print method for this that makes a printout similar to what assertionTest itself makes.
silent If TRUE assertionTest will not print any informative messages, even if there are errors in the tests. If verbose is set to TRUE, silent will be set to FALSE.
eval.in.try If TRUE assertionTest will evaluate the test expressions within a try function call, so it captures and reports any test that terminates with an error. If this argument is FALSE, the test expressions are not evaluated inside try, so assertionTest will terminate if any test generates an error. This may be useful when tracking down an error in a test expression.
evalREX If TRUE assertionTest will evaluate the test expressions using the evalREX function. If this argument is the string "trace", the test expressions are evaluated using the evalREX function with the trace=TRUE argument specified. Otherwise, the test expressions are evaluated using the normal eval function.
x For print.assertionTestResults(), the output of assertionTest(list.output=TRUE).
... print.assertionTestResults will accept but ignore other arguments.
Value
If list.output is FALSE (the default), the number of failed test expressions in the input file(s). Otherwise it returns the list described in the list.output section of this help file.
Note
The conventional file name extension of a file to be run under assertionTest() is ".t".
See Also
atExpectWarnings, atExpectStop, atUsesRandom, atSource, and atOnExit are functions that you can put into a test file to interact with assertionTest.
Examples
assertionTest(textConnection("
   {atUsesRandom(x <- sort(sample(10, size=5, replace=FALSE)))
       atOnExit(rm(x))}
   all(diff(x) >= 1)
   atExpectStop(lm(nosuchdata ~ x), expected=\"nosuchdata\")
"))
gc()  # gc() just to close text connection

# The expectWarning test should give no-warning error: assertionTest(textConnection(" atExpectWarnings(!is.finite(log(0.0)), \"Inf\") ")) gc() # gc() just to close text connection

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

Package assertionTest version 6.1.1-7
Package Index