【发布时间】:2013-07-09 20:49:27
【问题描述】:
显然有两种方法可以将testthat 与R CMD check 集成。我也不能上班。
方法 #1:(可能已弃用)
在开发包时,将测试放在 inst/tests 中,然后 创建一个文件tests/run-all.R(注意它必须是大写的R), 其中包含以下代码:
library(testthat)
library(mypackage)
test_package("mypackage")
这将评估您在包中的测试 命名空间(所以你可以测试非导出的函数),它会抛出 如果有任何测试失败,则会出现错误。这意味着您将看到 测试失败的完整报告和 R CMD 检查不会通过,除非全部 测试通过。
整个包是here。其中有两个文件:
## minimalbugexample/inst/tests/run-all.R
library(testthat)
library(minimalbugexample)
test_package('minimalbugexample')
和
## minimalbugexample/inst/tests/test-use-Matrix-package.R
context("Intentional break")
expect_that( TRUE, equals(FALSE))
我的描述是
Package: minimalbugexample
Title:
Description:
Version: 0.1.1
Author: Nathan VanHoudnos <nathanvan@letterafterFmail.com>
Maintainer: Nathan VanHoudnos <nathanvan@letterafterFmail.com>
Depends:
R (>= 3.0.1),
Matrix (>= 1.0)
Suggests:
testthat
License: GPL
LazyData: true
Collate:
'minimalbugexample-package.r'
'use-Matrix-package.R'
安装软件包后,我可以很好地运行测试(它们失败了,正如预期的那样)。
> test_package('minimalbugexample')
Intentional break : 1
1. Failure: -------------------------------------------------------------------
TRUE not equal to FALSE
1 element mismatch
Error: Test failures
>
但是R CMD check 不会运行测试。
$ R CMD check minimalbugexample_0.1.1.tar.gz
... snip ...
* checking PDF version of manual ... WARNING
WARNING: There was 1 warning.
See
‘/home/nathanvan/software/minimalbugexample.Rcheck/00check.log’
for details.
我认为 PDF 警告与此无关,但如果需要,我可以提供更多详细信息。
方法#2:(出血边缘)
根据README file of the testthat repository:
现在,推荐的做法是将您的测试放在 tests/testthat 中,并且 确保 R CMD 检查运行然后通过将以下代码放入 测试/test-all.R:
library(testthat)
test_check(yourpackage)
所以我确保我安装了最新版本的 testthat:
> install_github("testthat")
然后换了包。你可以得到这个版本here。我将这两个文件修改为
## minimalbugexample/inst/tests/test-all.R
library(testthat)
test_check(minimalbugexample)
和
## minimalbugexample/inst/tests/testthat/test-use-Matrix-package.R
context("Intentional break")
expect_that( TRUE, equals(FALSE))
然后将DESCRIPTION文件中的包版本更新为0.1.2,我可以构建它,安装它,并使用testthat检查它并获得与以前相同的输出。因此,就testthat 而言,它似乎在工作。
但是,R CMD check 仍然没有运行测试:
$ R CMD check minimalbugexample_0.1.2.tar.gz
... snip ...
* checking PDF version of manual ... WARNING
LaTeX errors when creating PDF version.
This typically indicates Rd problems.
WARNING: There was 1 warning.
See
‘/home/nathanvan/software/minimalbugexample.Rcheck/00check.log’
for details.
所以问题:
我做错了什么?我更喜欢方法 2 的解决方案,但我会采取任何一种方法!
【问题讨论】:
-
请注意,如果您使用方法#1,您 need to add 在
DESCRIPTION中测试Suggests:。