R CMD check and RUnit
2
0
Entering edit mode
@gorjanc-gregor-1198
Last seen 9.6 years ago
Hi! I appologize for crossposting, but this might be of broader interest. In case you are interested in fusing RUnit with R CMD check under unix alike OS, here is one way of doing/hacking this. My aim was to perform unit tests: (1) during R CMD check (2) at any other time Say you have a package PKG in a map PKG. I use the following structure PKG |- R |- ... |- inst | |- doc | `- unitTests |- ... `- tests Then the following files (content is at the end of the mail) are used: - PKG/tests/doRUnit.R - PKG/inst/unitTests/Makefile - PKG/inst/unitTests/runit.*.R Now when I launch cd /some/path/PKG/.. R CMD check PKG doRUnit.R in map tests is sourced and all unit tests in PKG/inst/unitTests are issued - aim (1). Output of tests can be seen in either: - PKG.Rcheck/tests/doRUnit.Rout - PKG.Rcheck/PKG/unitTests/report.txt - PKG.Rcheck/PKG/unitTests/report.html R CMD check will say OK also when some unit tests fails, but unit tests are at least issued and one should check above outputs to see the results of unit testing. I use the following in my ~/.Makefile to see these results imidiately NAME := $(shell basename $(PWD)) # Get current map name Rcheck: # Check R package of current map (cd ..; \ R CMD check $(NAME) && \ if [ -d $(NAME)/inst/unitTests ]; then \ cat $(NAME).Rcheck/tests/doRUnit.Rout; \ fi) Then only the following is necesarry to start R CME check and print results of unit testing (if it is used) mymake Rcheck where mymake is a shell function mymake () { make -f ~/.Makefile $* } export -f mymake ---------------------------------------------------------------------- If one wants to run only unit tests - aim (2) against currently installed code, use cd PKG/inst/unitTests make test or the following if package should be first re-installed, due to changes cd PKG/inst/unitTests make ---------------------------------------------------------------------- Please note that this hack is not only my work as I have taken the structure and initial idea from package graph in BioC. ---------------------------------------------------------------------- Content of above mentioned files: PKG/tests/doRUnit.R ---------------------------------------------------------------------- if(require("RUnit", quietly=TRUE)) { ## --- Setup --- library("PKG") testDir <- "unitTests" path <- "../PKG" ## Path for standalone i.e. not by R CMD check testing if(Sys.getenv("RCMDCHECK") == "FALSE") path <- "../inst" path <- file.path(getwd(), path, testDir) pathReport <- file.path(path, "report") ## --- Testing --- ## Define tests testsuite.PKG <- defineTestSuite(name="PKG unit testing", dirs=path) ## Run tests <- runTestSuite(testsuite.PKG) ## Print results printTextProtocol(tests) printTextProtocol(tests, fileName=paste(pathReport, ".txt", sep="")) ## Print HTML version to a file printHTMLProtocol(tests, fileName=paste(pathReport, ".html", sep="")) } ---------------------------------------------------------------------- PKG/inst/unitTests/Makefile ---------------------------------------------------------------------- PKG=PKG TOP=../../.. SUITE=doRUnit.R all: inst test inst: # Install package cd ${TOP};\ R CMD INSTALL ${PKG} test: # Run unit tests export RCMDCHECK=FALSE;\ cd ${TOP}/${PKG}/tests;\ R --slave < ${SUITE} ---------------------------------------------------------------------- PKG/inst/unitTests/runit.*.R ---------------------------------------------------------------------- # As many files with RUnit testing as you want ---------------------------------------------------------------------- Lep pozdrav / With regards, Gregor Gorjanc ---------------------------------------------------------------------- University of Ljubljana PhD student Biotechnical Faculty URI: http://www.bfro.uni-lj.si/MR/ggorjan Zootechnical Department mail: gregor.gorjanc <at> bfro.uni-lj.si Groblje 3 tel: +386 (0)1 72 17 861 SI-1230 Domzale fax: +386 (0)1 72 17 888 Slovenia, Europe ---------------------------------------------------------------------- "One must learn by doing the thing; for though you think you know it, you have no certainty until you try." Sophocles ~ 450 B.C.
graph graph • 1.1k views
ADD COMMENT
0
Entering edit mode
Seth Falcon ★ 7.4k
@seth-falcon-992
Last seen 9.6 years ago
Hi Gregor, "Gorjanc Gregor" <gregor.gorjanc at="" bfro.uni-lj.si=""> writes: > In case you are interested in fusing RUnit with R CMD check under unix > alike OS, here is one way of doing/hacking this. > > My aim was to perform unit tests: > (1) during R CMD check > (2) at any other time As you know, we've been using the RUnit package in our group here in Seattle to help with the development of Biobase and graph. I've found that writing unit tests improve my coding by making me focus on the API instead of the implementation and by making bug fixing easier. I've been meaning to improve the scripts I use to run the tests and what you've posted is a start in that direction. I have two additional aims, however, that aren't yet covered: (3) R CMD check should give an error if the tests fail. (4) Works on Windows. + seth
ADD COMMENT
0
Entering edit mode
@gorjanc-gregor-1198
Last seen 9.6 years ago
I have created page [1] in R Wiki on this topic. http://wiki.r-project.org/rwiki/doku.php?id=developers:runit Seth, I have also managed to tweak doRUnit.R so that R CMD check gives an error if the tests fail. I will leave windows port for someone else ;) "Gorjanc Gregor" <gregor.gorjanc at="" ...=""> writes: > In case you are interested in fusing RUnit with R CMD check under unix > alike OS, here is one way of doing/hacking this. > > My aim was to perform unit tests: > (1) during R CMD check > (2) at any other time As you know, we've been using the RUnit package in our group here in Seattle to help with the development of Biobase and graph. I've found that writing unit tests improve my coding by making me focus on the API instead of the implementation and by making bug fixing easier. I've been meaning to improve the scripts I use to run the tests and what you've posted is a start in that direction. I have two additional aims, however, that aren't yet covered: (3) R CMD check should give an error if the tests fail. (4) Works on Windows. Lep pozdrav / With regards, Gregor Gorjanc ---------------------------------------------------------------------- University of Ljubljana PhD student Biotechnical Faculty URI: http://www.bfro.uni-lj.si/MR/ggorjan Zootechnical Department mail: gregor.gorjanc <at> bfro.uni-lj.si Groblje 3 tel: +386 (0)1 72 17 861 SI-1230 Domzale fax: +386 (0)1 72 17 888 Slovenia, Europe ---------------------------------------------------------------------- "One must learn by doing the thing; for though you think you know it, you have no certainty until you try." Sophocles ~ 450 B.C.
ADD COMMENT

Login before adding your answer.

Traffic: 549 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6