Log: SciViews-R log management functions

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/Log.R

Description

These functions define the code of test functions. They are designed to check the result of some test calculation.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
Log(description = NULL)

createLog(description = NULL, deleteExisting = FALSE)

clearLog()

errorLog(stopit = TRUE, summarize = TRUE)

lastTest()

lastSuite()

Arguments

description

A (short) character string describing this test suite log.

deleteExisting

Do we delete an existing a .Log object already defined in .GlobalEnv (no, by default)?

stopit

Do we issue an error (stop() in case of any error or failure? This is particularly useful if you want to interrupt R CMD check on packages, when you included one or more test suites in examples (see ?unitTests).

summarize

Should the summary of the log be printed in case we stop execution of the code when an error is found (see stopit = argument. It is, indeed, useful to indicate at this time which tests failed or raised an error. So, this argument should usually be left at its default value.

Details

svUnit records results of assertions (using the checkxxx() functions) in a 'svSuiteData' object named .Log and located in .GlobalEnv. Hence, this log is easy to access. However, in order to avoid errors in your code in case this object was deleted, or not created, it is better to access it using Log() which take care to create the object if it is missing.

Value

Log() and createLog() return the .Log object defined in .GlobalEnv by reference (it is indeed an environment). So, you can use its content (and change it, if you write functions to manipulate this log).

clearLog() return invisibly TRUE or FALSE, depending if an existing log object was deleted or not.

errorLog() is mainly used for its side-effect of stopping code execution and/or printing a summary of the test runs in the context of example massaging in R CMD check (see the "Writing R extensions" manual). However, this function also returns invisibly a contingency table with the number of successes, failures, errors and deactivated tests recorded so far.

lastTest() and lastSuite() recall results of last test and last suite run, respectively.

Author(s)

Philippe Grosjean

See Also

svSuiteData(), svSuite(), svTest(), checkEquals()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
clearLog()           # Clear the svUnit log

# Two correct tests
(checkTrue(1 < 2))
(checkException(log("a")))
errorLog()           # Nothing, because there is no error

## Not run: 
(checkTrue(1 > 2))    # This test fails
lastTest()            # Print results of last test
errorLog()            # Stop and summarize the tests run so far

## End(Not run)

clearLog()

svUnit documentation built on April 19, 2021, 9:06 a.m.