Unit testing RUnit测试卸载的包
我正在按照提示进行测试,但我不耐烦,我想更快地运行测试,而不必等待Unit testing RUnit测试卸载的包,unit-testing,r,Unit Testing,R,我正在按照提示进行测试,但我不耐烦,我想更快地运行测试,而不必等待R CMD check src在检查测试之前调用的30多个检查 我想我可以做的是在中建议的doRUnit.R中添加一个--standalone选项,这样我就可以独立于R CMD运行单元测试 我在脚本中添加了以下行: opt <- list(standalone=NULL) if(require("getopt", quietly=TRUE)) { ## path to unit tests may be gi
R CMD check src
在检查测试之前调用的30多个检查
我想我可以做的是在中建议的doRUnit.R
中添加一个--standalone
选项,这样我就可以独立于R CMD
运行单元测试
我在脚本中添加了以下行:
opt <- list(standalone=NULL)
if(require("getopt", quietly=TRUE)) {
## path to unit tests may be given on command line, in which case
## we also want to move the cwd to this script
opt <- getopt(matrix(c('standalone', 's', 0, "logical"),
ncol=4, byrow=TRUE))
if(!is.null(opt$standalone)) {
## switch the cwd to the dir of this script
args <- commandArgs()
script.name <- substring(args[substring(args, 1, 7)=="--file="], 8, 1000)
if(!is.null(script.name))
setwd(dirname(script.name))
}
}
opt您可能需要手动循环使用R
目录和source()
中的文件,可能需要使用类似source(dir(“/some/Path”,pattern=“*.R”,full.names=TRUE)”的内容
但是我觉得R CMD INSTALL
做得更多。你最好从安装的代码开始工作。而且,正如你所做的和维基页面所建议的那样,直接运行单元测试已经相当不错了。所以我没有更好的方案。但请随时通知我们
编辑:还请注意,R2.10.1为我们提供了加速R CMD安装的新选项
:
2.10.1新功能
R CMD INSTALL有新选项--no-R,
--无LIB、-无数据、-无帮助、-无演示、-无exec、-无禁止安装指定
包装的一部分。这些是
用于特殊目的(例如:。
构建帮助页面数据库
没有完全安装所有
软件包)
这也会有所帮助。对脚本的进一步添加/更正
我现在可以将其作为doRUnit.R--standalone
或者通过R CMD check调用它
if(!is.null(script.name)) {
setwd(dirname(script.name))
path <- '../inst/RUnit/'
}
.
.
.
if (is.null(opt$standalone)) {
cat("\nRunning unit tests of installed library\n")
library(package=pkg, character.only=TRUE)
} else {
cat("\nRunning unit tests of uninstalled library\n")
source(dir("../R/", pattern=".*\\.R", full.names=TRUE))
}
如果(!is.null(script.name)){
setwd(dirname(script.name))
最后,我把我自己的答案和你的答案混合在一起:我首先安装包,然后运行doRUnit——单机版。这样更快,我可以在控制台上看到输出。稍后更新:我在unittests目录中找到了一个目标,它定义了一个目标(xtest),该目标生成在emacs中的*编译*
缓冲区中有用的输出。