I am using testthat to test my R package (https://github.com/beerda/hexmatrix). Recently, I started C++ testing: I have executed testthat::use_catch()
, which should setup the package for unit testing with C++ Catch, and then I wrote some tests. The tests run correctly if executed by devtools::test()
. However, if I try to run R CMD check
or devtools::check()
, I get the following error message:
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
The xml2 package is installed, rlang::check_installed("xml2") returns TRUE.
Not sure if it is somehow connected: when I try to execute manually the command run_cpp_tests("hexmatrix")
, I get the following error:
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]
Does please anybody have the idea what is going wrong? Thanks, in advance.
The problem seems solved by adding xml2
into Suggests
section of the DESCRIPTION
file of the package.