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