问题描述
我正在使用testthat测试我的R包(https://github.com/beerda/hexmatrix)。最近,我开始进行C ++测试:我执行了testthat::use_catch()
,这应该设置软件包以使用C ++ Catch进行单元测试,然后编写一些测试。如果由devtools::test()
执行,则测试可以正确运行。但是,如果我尝试运行R CMD check
或devtools::check()
,则会收到以下错误消息:
Running ‘testthat.R’ (1.8s)
Running the tests in ‘tests/testthat.R’ Failed.
Last 13 lines of output:
> test_check("hexmatrix")
── Error (test-cpp.R:1:1): (code run outside of `test_that()`) ─────────────────
Error: The xml2 package must be installed in order to use `run_cpp_tests()`
ℹ Do you need to run `install.packages('xml2')`?
Backtrace:
█
1. └─testthat::run_cpp_tests("hexmatrix") test-cpp.R:1:0
2. └─testthat:::check_installed("xml2","run_cpp_tests()")
══ testthat results ═══════════════════════════════════════════════════════════
Error (test-cpp.R:1:1): (code run outside of `test_that()`)
[ FAIL 1 | WARN 0 | SKIP 0 | PASS 909 ]
Error: Test failures
Execution halted
已安装xml2软件包,rlang :: check_installed(“ xml2”)返回TRUE。
不确定它是否以某种方式连接:当我尝试手动执行命令run_cpp_tests("hexmatrix")
时,出现以下错误:
Error in read_xml.raw(charToRaw(enc2utf8(x)),"UTF-8",...,as_html = as_html,:
XML declaration allowed only at the start of the document [64]
请问有人知道出了什么问题吗?谢谢,谢谢。
解决方法
通过在软件包的xml2
文件的Suggests
部分中添加DESCRIPTION
,似乎可以解决问题。
那不应该是一个testthat依赖项,因为您没有显式使用xml2库?