0

我正在使用 testthat 来测试我的 R 包(https://github.com/beerda/hexmatrix)。最近,我开始了 C++ 测试:我已经执行testthat::use_catch()了,它应该设置包以使用 C++ Catch 进行单元测试,然后我编写了一些测试。如果由 执行,测试将正确运行devtools::test()。但是,如果我尝试运行R CMD checkor 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]

请问有人知道出了什么问题吗?提前致谢。

4

2 回答 2

1

通过添加xml2到包文件的Suggests部分中,问题似乎得到了解决。DESCRIPTION

于 2020-11-06T08:07:12.260 回答
0

这不应该是一个 testthat 依赖项,因为您没有明确使用库 xml2 ?

于 2020-11-27T14:21:14.673 回答