Skip to content

Commit 01ab78a

Browse files
committed
add code_stdout option
1 parent 3ec2edf commit 01ab78a

File tree

4 files changed

+32
-12
lines changed

4 files changed

+32
-12
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,5 @@ Suggests:
7272
box (>= 1.2.0)
7373
License: MIT + file LICENSE
7474
VignetteBuilder: knitr
75-
RoxygenNote: 7.2.3
75+
RoxygenNote: 7.3.1
7676
Roxygen: list(markdown = TRUE)

NEWS.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# covr (development version)
22

3+
* Added `code_stdout` option to `package_coverage()` which allows code output to print to the console while running
4+
35
* Added support for `klmr/box` modules. This works best with `file_coverage()`. (@radbasa, #491)
46

57
# covr 3.6.4

R/covr.R

+23-10
Original file line numberDiff line numberDiff line change
@@ -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

man/package_coverage.Rd

+6-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)