PageRenderTime 16ms CodeModel.GetById 11ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/fingerprint/tests/doRUnit.R

http://github.com/rajarshi/cdkr
R | 58 lines | 29 code | 10 blank | 19 comment | 6 complexity | 4c2ef966480892f12e79a4c6729efa23 MD5 | raw file
 1if(require("RUnit", quietly=TRUE)) {
 2 
 3  ## --- Setup ---
 4 
 5  pkg <- "fingerprint" # <-- Change to package name!
 6  if(Sys.getenv("RCMDCHECK") == "FALSE") {
 7    ## Path to unit tests for standalone running under Makefile (not R CMD check)
 8    ## PKG/tests/../inst/unitTests
 9    path <- file.path(getwd(), "..", "inst", "unitTests")
10  } else {
11    ## Path to unit tests for R CMD check
12    ## PKG.Rcheck/tests/../PKG/unitTests
13    path <- system.file(package=pkg, "unitTests")
14  }
15  cat("\nRunning unit tests\n")
16  print(list(pkg=pkg, getwd=getwd(), pathToUnitTests=path))
17 
18  library(package=pkg, character.only=TRUE)
19 
20  ## If desired, load the name space to allow testing of private functions
21  ## if (is.element(pkg, loadedNamespaces()))
22  ##     attach(loadNamespace(pkg), name=paste("namespace", pkg, sep=":"), pos=3)
23  ##
24  ## or simply call PKG:::myPrivateFunction() in tests
25 
26  ## --- Testing ---
27 
28  ## Define tests
29  testSuite <- defineTestSuite(name=paste(pkg, "fingerprint Unit Tests"),
30                                          dirs=path)
31  ## Run
32  tests <- runTestSuite(testSuite)
33 
34  ## Default report name
35  pathReport <- file.path(path, "report")
36 
37  ## Report to stdout and text files
38  cat("------------------- UNIT TEST SUMMARY ---------------------\n\n")
39  printTextProtocol(tests, showDetails=FALSE)
40  printTextProtocol(tests, showDetails=FALSE,
41                    fileName=paste(pathReport, "Summary.txt", sep=""))
42  printTextProtocol(tests, showDetails=TRUE,
43                    fileName=paste(pathReport, ".txt", sep=""))
44 
45  ## Report to HTML file
46  printHTMLProtocol(tests, fileName=paste(pathReport, ".html", sep=""))
47 
48  ## Return stop() to cause R CMD check stop in case of
49  ##  - failures i.e. FALSE to unit tests or
50  ##  - errors i.e. R errors
51  tmp <- getErrors(tests)
52  if(tmp$nFail > 0 | tmp$nErr > 0) {
53    stop(paste("\n\nunit testing failed (#test failures: ", tmp$nFail,
54               ", #R errors: ",  tmp$nErr, ")\n\n", sep=""))
55  }
56} else {
57  warning("cannot run unit tests -- package RUnit is not available")
58}