testthat icon indicating copy to clipboard operation
testthat copied to clipboard

progress reporter uses bare runif

Open aronatkins opened this issue 1 year ago • 0 comments

R_DEFAULT_PACKAGES=NULL R -s --vanilla -e 'r <- testthat::ProgressReporter$new(); r$start_reporter(); r$end_reporter()'
# ... progress output not included ...
# Error in runif(1) : could not find function "runif"
# Calls: <Anonymous>
# Execution halted

This is because the call to runif within the ProgressReporter assumes that the stats package has been loaded.

https://github.com/r-lib/testthat/blob/426eb523f6772c76175d6e8d7ca04355b1ee7ad5/R/reporter-progress.R#L269-L271

This can happen when tests use the default (progress) reporter and are attempting to test code in the absence of default packages.

The parallel progress reporter suffers from the same problem:

R_DEFAULT_PACKAGES=NULL R -s --vanilla -e 'r <- testthat::ParallelProgressReporter$new(); r$start_reporter(); r$end_reporter()'
# ... progress output not included ...
# Error in runif(1) : could not find function "runif"
# Calls: <Anonymous> -> <Anonymous>
# Execution halted

The compact progress reporter does not have this issue; it has a different end_reporter definition.

R_DEFAULT_PACKAGES=NULL R -s --vanilla -e 'r <- testthat::CompactProgressReporter$new(); r$start_reporter(); r$end_reporter()'
NULL
 Done!

aronatkins avatar Jul 11 '22 21:07 aronatkins