Getting a proper exit code from devtools::test()

I am developing a package which contains various unit tests. I am trying to set up a CI pipeline which would run the unit tests and provide info if they are passed or not. I run the unit tests with command

R -e "setwd('production'); devtools::test()"

then I would expect, in case of failed tests, the exit code to be set to 1. I can check it with

echo $?

in this case, whether some test are failing or not, exit code is always 0 which suggests success.
Is there a way go get the proper exit code for failed tests?

1 Like

Generally it is better to run a full R CMD check in CI pipelines, rather than just running tests.

However if you do want to do this you can use the 'fail' reporter (which fails when there are failing tests) along with another one of the reporters, like the progress reporter. e.g.

devtools::test(reporter = c("summary", "fail"))
2 Likes

I recently ran into this exact same problem. For more discussion, check out testthat Issue #515.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.