Brian Lee Yung Rowe
2014-Jan-22 16:55 UTC
[Rd] Behavior of --install-tests and testInstalledPackage
Hello, I'm writing a script that automates the testing of reverse dependencies of a package. I found the function testInstalledPackage in the tools package, which seems to do what I want. However, when I use it for a source package that was installed with --install-tests, I've noticed that only the actual test files (e.g. located in inst/tests) are available and run. In other words the test harness script (e.g. in tests) is not copied, so any wiring to run tests isn't available when running testInstalledPackage. I tried loading the required packages (i.e. the installed package to retest plus the testing frameworks RUnit, testthat), but since testInstalledPackage makes an external call to R CMD BATCH, any packages loaded in my current environment have no effect on the tests. The only workaround that I've come up with is to add require statements to the top of each test file, but this is a bit onerous. My question is whether 1) there is a technique to force the test harness script (e.g. tests/run_tests.R, tests/doRUnit.R) to be copied into the installed source package, or 2) there is a way to have testInstalledPackage force the loading of required packages prior to executing test scripts, or 3) has someone already done this? Thanks and Regards, Brian
Winston Chang
2014-Jan-27 17:51 UTC
[Rd] Behavior of --install-tests and testInstalledPackage
On Wed, Jan 22, 2014 at 10:55 AM, Brian Lee Yung Rowe <rowe@muxspace.com>wrote:> Hello, > > I'm writing a script that automates the testing of reverse dependencies of > a package. I found the function testInstalledPackage in the tools package, > which seems to do what I want. However, when I use it for a source package > that was installed with --install-tests, I've noticed that only the actual > test files (e.g. located in inst/tests) are available and run. In other > words the test harness script (e.g. in tests) is not copied, so any wiring > to run tests isn't available when running testInstalledPackage. > > I tried loading the required packages (i.e. the installed package to > retest plus the testing frameworks RUnit, testthat), but since > testInstalledPackage makes an external call to R CMD BATCH, any packages > loaded in my current environment have no effect on the tests. The only > workaround that I've come up with is to add require statements to the top > of each test file, but this is a bit onerous. > > My question is whether > 1) there is a technique to force the test harness script (e.g. > tests/run_tests.R, tests/doRUnit.R) to be copied into the installed source > package, or > 2) there is a way to have testInstalledPackage force the loading of > required packages prior to executing test scripts, or > 3) has someone already done this? >I can answer (3). devtools already has a function that does this: library(devtools) revdep_check('mypackage') It's basically a wrapper for the revdep and check_cran functions from devtools. In the development version of devtools (on Github) there are some changes to improve the output of these functions. -Winston [[alternative HTML version deleted]]