I am running tests in R using the test_dir()
function from the testthat
package. In some of the test scripts there are functions that call readline()
, which - in interactive mode - causes the testing to pause and wait for user input. The functions calling readline()
are not my own and I don't have any influence on them. The user input is irrelevant for the output of those functions.
Is there a way to avoid these pauses during testing?
Approaches that come to mind, but I wouldn't know how to implement them:
- disable interactive mode while R is running
- use another function from the
testthat
package that runs scripts in non-interactive mode - somehow divert
stdin
to something else than the terminal(??) - wrap functions calling
readline()
in another script that is called in non-interactive mode from my testing script and makes the results available
Testing only from the command line using Rscript
is an option, but I'd rather stay in the RStudio workflow.
======
Example Code
with_pause <- function () {
readline()
2
}
without_pause <- function () {
2
}
expect_equal(with_pause(), without_pause())