@@ -350,6 +350,9 @@ environment_coverage <- function(
350
350
# ' and tests run in. By default it is a path in the R sessions temporary
351
351
# ' directory. It can sometimes be useful to set this (along with `clean =
352
352
# ' 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)
353
356
# ' @seealso [exclusions()] For details on excluding parts of the
354
357
# ' package from the coverage calculations.
355
358
# ' @export
@@ -364,7 +367,7 @@ package_coverage <- function(path = ".",
364
367
code = character (),
365
368
install_path = temp_file(" R_LIBS" ),
366
369
... ,
367
- exclusions , pre_clean = TRUE ) {
370
+ exclusions , pre_clean = TRUE , code_stdout = FALSE ) {
368
371
369
372
if (! missing(exclusions )) {
370
373
warning(
@@ -501,7 +504,7 @@ package_coverage <- function(path = ".",
501
504
502
505
# We always run the commands file (even if empty) to load the package and
503
506
# initialize all the counters to 0.
504
- run_commands(pkg , install_path , code )
507
+ run_commands(pkg , install_path , code , code_stdout )
505
508
},
506
509
message = function (e ) if (quiet ) invokeRestart(" muffleMessage" ) else e ,
507
510
warning = function (e ) if (quiet ) invokeRestart(" muffleWarning" ) else e )
@@ -735,20 +738,30 @@ run_vignettes <- function(pkg, lib) {
735
738
}
736
739
}
737
740
738
- run_commands <- function (pkg , lib , commands ) {
741
+ run_commands <- function (pkg , lib , commands , code_stdout = FALSE ) {
739
742
outfile <- file.path(lib , paste0(pkg $ package , " -commands.Rout" ))
740
743
failfile <- paste(outfile , " fail" , sep = " ." )
741
744
writeLines(c(
742
745
paste0(" library('" , pkg $ package , " ')" ),
743
746
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
+ }
750
758
} 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
+ }
752
765
}
753
766
}
754
767
0 commit comments