PageRenderTime 34ms CodeModel.GetById 18ms RepoModel.GetById 0ms 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. library(rJava)
  3. library(fingerprint)
  4. ## --- Setup ---
  5. pkg <- "rcdk" # <-- 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. library(package=pkg, character.only=TRUE)
  18. ## If desired, load the name space to allow testing of private functions
  19. ## if (is.element(pkg, loadedNamespaces()))
  20. ## attach(loadNamespace(pkg), name=paste("namespace", pkg, sep=":"), pos=3)
  21. ##
  22. ## or simply call PKG:::myPrivateFunction() in tests
  23. ## --- Testing ---
  24. ## Define tests
  25. testSuite <- defineTestSuite(name=paste(pkg, "rcdk Unit Tests"),
  26. dirs=path)
  27. ## Run
  28. tests <- runTestSuite(testSuite)
  29. ## Default report name
  30. #pathReport <- file.path(path, "report")
  31. ## Report to stdout and text files
  32. cat("------------------- UNIT TEST SUMMARY ---------------------\n\n")
  33. printTextProtocol(tests, showDetails=FALSE)
  34. #printTextProtocol(tests, showDetails=FALSE,
  35. # fileName=paste(pathReport, "Summary.txt", sep=""))
  36. #printTextProtocol(tests, showDetails=TRUE,
  37. # fileName=paste(pathReport, ".txt", sep=""))
  38. ## Report to HTML file
  39. #printHTMLProtocol(tests, fileName=paste(pathReport, ".html", sep=""))
  40. ## Return stop() to cause R CMD check stop in case of
  41. ## - failures i.e. FALSE to unit tests or
  42. ## - errors i.e. R errors
  43. tmp <- getErrors(tests)
  44. if(tmp$nFail > 0 | tmp$nErr > 0) {
  45. stop(paste("\n\nunit testing failed (#test failures: ", tmp$nFail,
  46. ", #R errors: ", tmp$nErr, ")\n\n", sep=""))
  47. }
  48. } else {
  49. warning("cannot run unit tests -- package RUnit is not available")
  50. }