3
if(require("RUnit", quietly = TRUE))
6
library(package=pkg, character.only = TRUE)
7
if(!(exists("path") && file.exists(path)))
8
path <- system.file("unitTests", package = pkg)
13
testSuite <- defineTestSuite(name = paste(pkg, "unit testing"),
17
cat("Now have RUnit Test Suite 'testSuite' for package '",
20
cat('', "Consider doing",
21
"\t tests <- runTestSuite(testSuite)", "\nand later",
22
"\t printTextProtocol(tests)", '', sep = "\n")
24
## run from shell / Rscript / R CMD Batch / ...
26
tests <- runTestSuite(testSuite)
28
if(file.access(path, 02) != 0) {
29
## cannot write to path -> use writable one
30
tdir <- tempfile(paste(pkg, "unitTests", sep="_"))
32
pathReport <- file.path(tdir, "report")
33
cat("RUnit reports are written into ", tdir, "/report.(txt|html)",
36
pathReport <- file.path(path, "report")
40
printTextProtocol(tests, showDetails = FALSE)
41
printTextProtocol(tests, showDetails = FALSE,
42
fileName = paste(pathReport, "Summary.txt", sep = ""))
43
printTextProtocol(tests, showDetails = TRUE,
44
fileName = paste(pathReport, ".txt", sep = ""))
46
## Print HTML Version to a File:
47
## printHTMLProtocol has problems on Mac OS X
48
if (Sys.info()["sysname"] != "Darwin")
49
printHTMLProtocol(tests,
50
fileName = paste(pathReport, ".html", sep = ""))
52
## stop() if there are any failures i.e. FALSE to unit test.
53
## This will cause R CMD check to return error and stop
54
tmp <- getErrors(tests)
55
if(tmp$nFail > 0 | tmp$nErr > 0) {
56
stop(paste("\n\nunit testing failed (#test failures: ", tmp$nFail,
57
", R errors: ", tmp$nErr, ")\n\n", sep=""))
61
cat("R package 'RUnit' cannot be loaded -- no unit tests run\n",
62
"for package", pkg,"\n")
66
################################################################################