# NOT RUN {
svSuiteList() # List all currently available test units and test cases
# Exclusion list is used (regular expression filtering!). It contains:
(oex <- getOption("svUnit.excludeList"))
# Clear it, and relist available test units
options(svUnit.excludeList = NULL)
svSuiteList()
# Two functions that include their test cases
Square <- function(x)
return(x^2)
test(Square) <- function() {
checkEquals(9, Square(3))
checkEquals(c(1, 4, 9), Square(1:3))
checkException(Square("xx"))
}
Cube <- function(x)
return(x^3)
test(Cube) <- function() {
checkEquals(27, Cube(3))
checkEquals(c(1, 8, 28), Cube(1:3))
checkException(Cube("xx"))
}
# A separate test case object (not attached to a particular object)
# This is the simplest way to define quick and durty integration tests
test_Integrate <- svTest(function() {
checkTrue(1 < 2, "check1")
v <- 1:3 # The reference
w <- 1:3 # The value to compare to the reference
checkEquals(v, w)
})
# A function without test cases (will be filtered out of the suite list)
foo <- function(x)
return(x)
# Look now which tests are available
svSuiteList()
# Only objects, no package units
svSuiteList(packages = FALSE)
# }
# NOT RUN {
# Create the test unit file for all objects with tests in .GlobalEnv
myunit <- makeUnit(svSuiteList(), name = "AllTests")
file.show(myunit, delete.file = TRUE)
# }
# NOT RUN {
# Filter objects using a list (object with/without tests and a nonexisting obj)
svSuiteList(packages = FALSE, objects = c("Cube", "foo", "bar"))
# Create another svSuite object with selected test items
(mysuite <- svSuite(c("package:svUnit (VirtualClass)", "test(Cube)")))
is.svSuite(mysuite) # Should be!
# }
# NOT RUN {
# Run all the tests currently available
(runTest(svSuiteList(), name = "AllTests"))
summary(Log())
# }
# NOT RUN {
# Restore previous exclusion list, and clean up the environment
options(svUnit.excludeList = oex)
rm(Square, Cube, foo, test_Integrate, mysuite, myunit, oex)
# }
Run the code above in your browser using DataLab