auto_test 在 testthat 中给出报告者错误
auto_test gives reporter error in testthat
我试图强迫自己在一些我真的不想开发包的数据分析项目上做更多的单元测试。所以,我一直在玩 testthat
R 包。我有一个 code
文件夹,里面有一个 src
和一个 test
文件夹。在 src
文件夹中,我有文件 add.R
具有此功能:
add <- function(x,y){
x+y
}
在 test
文件夹中,我有文件 test-add.R
包含以下内容:
library(testthat)
test_that("adding numbers", {
expect_equal(add(2,3), 5)
expect_equal(add(5,5), 10)
})
以下工作正常...
> source('code/src/add.R')
> test_file('code/test/test-add.R')
但我希望能够使用 auto_test
函数,因为随着项目的增长 source
/test_file
会变得乏味。但是当我尝试 auto_test
我得到这个...
> auto_test('code/src', 'code/test')
Error in find_reporter(reporter) : attempt to apply non-function
我确定我遗漏了一些简单的东西,但是什么?
> sessionInfo()
R version 3.2.3 (2015-12-10)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.11.1 (El Capitan)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] testthat_0.11.0.9000 knitr_1.12.3
loaded via a namespace (and not attached):
[1] lazyeval_0.1.10 R6_2.1.2 tools_3.2.3
[4] withr_1.0.1 memoise_1.0.0 crayon_1.3.1
[7] digest_0.6.9 devtools_1.10.0.9000
看来这是testthat
版本0.11.0.9000的问题。如果我从 github 安装此版本,我会收到与您相同的错误消息:
auto_test('code/src', 'code/test')
## Error in find_reporter(reporter) : attempt to apply non-function
但是对于可以从 CRAN 安装的版本 0.11.0,您的示例运行良好:
auto_test('code/src', 'code/test')
## ..
## DONE
我试图强迫自己在一些我真的不想开发包的数据分析项目上做更多的单元测试。所以,我一直在玩 testthat
R 包。我有一个 code
文件夹,里面有一个 src
和一个 test
文件夹。在 src
文件夹中,我有文件 add.R
具有此功能:
add <- function(x,y){
x+y
}
在 test
文件夹中,我有文件 test-add.R
包含以下内容:
library(testthat)
test_that("adding numbers", {
expect_equal(add(2,3), 5)
expect_equal(add(5,5), 10)
})
以下工作正常...
> source('code/src/add.R')
> test_file('code/test/test-add.R')
但我希望能够使用 auto_test
函数,因为随着项目的增长 source
/test_file
会变得乏味。但是当我尝试 auto_test
我得到这个...
> auto_test('code/src', 'code/test')
Error in find_reporter(reporter) : attempt to apply non-function
我确定我遗漏了一些简单的东西,但是什么?
> sessionInfo()
R version 3.2.3 (2015-12-10)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.11.1 (El Capitan)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] testthat_0.11.0.9000 knitr_1.12.3
loaded via a namespace (and not attached):
[1] lazyeval_0.1.10 R6_2.1.2 tools_3.2.3
[4] withr_1.0.1 memoise_1.0.0 crayon_1.3.1
[7] digest_0.6.9 devtools_1.10.0.9000
看来这是testthat
版本0.11.0.9000的问题。如果我从 github 安装此版本,我会收到与您相同的错误消息:
auto_test('code/src', 'code/test')
## Error in find_reporter(reporter) : attempt to apply non-function
但是对于可以从 CRAN 安装的版本 0.11.0,您的示例运行良好:
auto_test('code/src', 'code/test')
## ..
## DONE