PageRenderTime 142ms CodeModel.GetById 81ms app.highlight 2ms RepoModel.GetById 58ms app.codeStats 0ms

/rcdk/tests/doRUnit.R

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