One can run testthat::test_package() to run tests. This returns a list of test results. If a test has a failure (i.e. some expectation isnt met), it is reflected in this list. If the test errors (i.e. bad code), it does not appear in the returned list. The console output from test_package() does correctly report the number of errors and failures. Here is a simple example:
# https://github.com/bbimber/RTest/tree/master/tests
devtools::install_github('bbimber/RTest', args = "--install-tests")
# Package has three tests:
# test-passing.R: this passes. This is reflected in the returned list.
# test-expectedFail.R: this tests "expect_equal(1, 2)", and fails gracefully. This is reflected in the returned list
# test-exception.R: contains the line "sqrt(2, foo = 'bar')", so errors with the message "2 arguments passed to 'sqrt' which requires 1". This is not reflected in the returned list.
res <- testthat::test_package('RTest', reporter = testthat::check_reporter())
The returned list has two elements, and doesnt have any information about the error. The output of test_package() does contain the right information:
== testthat results ===========================================================
[ OK: 1 | SKIPPED: 0 | WARNINGS: 0 | FAILED: 2 ]
- Error: (unknown) (test-exception.R#4)
- Failure: I am expected to fail, but without exceptions (test-expectedFail.R#4)
Is there a programmatic way to obtain the list of failures and errors? Simply getting the count would be good enough. Thanks in advance for any help.