@@ -350,6 +350,9 @@ environment_coverage <- function(
350350# ' and tests run in. By default it is a path in the R sessions temporary
351351# ' directory. It can sometimes be useful to set this (along with `clean =
352352# ' FALSE`) to help debug test failures.
353+ # ' @param code_stdout When running code specified in the `code` argument, whether to
354+ # ' use Rscript so that the console updates live (defaults to FALSE, using R CMD BATCH,
355+ # ' and only showing the output after all tests have run when there is a failure)
353356# ' @seealso [exclusions()] For details on excluding parts of the
354357# ' package from the coverage calculations.
355358# ' @export
@@ -364,7 +367,7 @@ package_coverage <- function(path = ".",
364367 code = character (),
365368 install_path = temp_file(" R_LIBS" ),
366369 ... ,
367- exclusions , pre_clean = TRUE ) {
370+ exclusions , pre_clean = TRUE , code_stdout = FALSE ) {
368371
369372 if (! missing(exclusions )) {
370373 warning(
@@ -501,7 +504,7 @@ package_coverage <- function(path = ".",
501504
502505 # We always run the commands file (even if empty) to load the package and
503506 # initialize all the counters to 0.
504- run_commands(pkg , install_path , code )
507+ run_commands(pkg , install_path , code , code_stdout )
505508 },
506509 message = function (e ) if (quiet ) invokeRestart(" muffleMessage" ) else e ,
507510 warning = function (e ) if (quiet ) invokeRestart(" muffleWarning" ) else e )
@@ -735,20 +738,30 @@ run_vignettes <- function(pkg, lib) {
735738 }
736739}
737740
738- run_commands <- function (pkg , lib , commands ) {
741+ run_commands <- function (pkg , lib , commands , code_stdout = FALSE ) {
739742 outfile <- file.path(lib , paste0(pkg $ package , " -commands.Rout" ))
740743 failfile <- paste(outfile , " fail" , sep = " ." )
741744 writeLines(c(
742745 paste0(" library('" , pkg $ package , " ')" ),
743746 commands ), con = outfile )
744- cmd <- paste(shQuote(file.path(R.home(" bin" ), " R" )),
745- " CMD BATCH --vanilla --no-timing" ,
746- shQuote(outfile ), shQuote(failfile ))
747- res <- system(cmd )
748- if (res != 0L ) {
749- show_failures(dirname(failfile ))
747+
748+ if (! code_stdout ) {
749+ cmd <- paste(shQuote(file.path(R.home(" bin" ), " R" )),
750+ " CMD BATCH --vanilla --no-timing" ,
751+ shQuote(outfile ), shQuote(failfile ))
752+ res <- system(cmd )
753+ if (res != 0L ) {
754+ show_failures(dirname(failfile ))
755+ } else {
756+ file.rename(failfile , outfile )
757+ }
750758 } else {
751- file.rename(failfile , outfile )
759+ cmd <- paste(shQuote(file.path(R.home(" bin" ), " Rscript" )),
760+ " --vanilla" , shQuote(outfile ))
761+ res <- system(cmd )
762+ if (res != 0L ) {
763+ stop(" Failure when running covr commands" )
764+ }
752765 }
753766}
754767
0 commit comments