diff --git a/DESCRIPTION b/DESCRIPTION index d086e5c0..f2029db6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -72,5 +72,5 @@ Suggests: box (>= 1.2.0) License: MIT + file LICENSE VignetteBuilder: knitr -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.1 Roxygen: list(markdown = TRUE) diff --git a/NEWS.md b/NEWS.md index 1d6f97a1..3041da42 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # covr (development version) +* Added `code_stdout` option to `package_coverage()` which allows code output to print to the console while running + * Added support for `klmr/box` modules. This works best with `file_coverage()`. (@radbasa, #491) # covr 3.6.4 diff --git a/R/covr.R b/R/covr.R index 106d8f03..82108972 100644 --- a/R/covr.R +++ b/R/covr.R @@ -350,6 +350,9 @@ environment_coverage <- function( #' and tests run in. By default it is a path in the R sessions temporary #' directory. It can sometimes be useful to set this (along with `clean = #' FALSE`) to help debug test failures. +#' @param code_stdout When running code specified in the `code` argument, whether to +#' use Rscript so that the console updates live (defaults to FALSE, using R CMD BATCH, +#' and only showing the output after all tests have run when there is a failure) #' @seealso [exclusions()] For details on excluding parts of the #' package from the coverage calculations. #' @export @@ -364,7 +367,7 @@ package_coverage <- function(path = ".", code = character(), install_path = temp_file("R_LIBS"), ..., - exclusions, pre_clean=TRUE) { + exclusions, pre_clean=TRUE, code_stdout = FALSE) { if (!missing(exclusions)) { warning( @@ -501,7 +504,7 @@ package_coverage <- function(path = ".", # We always run the commands file (even if empty) to load the package and # initialize all the counters to 0. - run_commands(pkg, install_path, code) + run_commands(pkg, install_path, code, code_stdout) }, message = function(e) if (quiet) invokeRestart("muffleMessage") else e, warning = function(e) if (quiet) invokeRestart("muffleWarning") else e) @@ -735,20 +738,30 @@ run_vignettes <- function(pkg, lib) { } } -run_commands <- function(pkg, lib, commands) { +run_commands <- function(pkg, lib, commands, code_stdout = FALSE) { outfile <- file.path(lib, paste0(pkg$package, "-commands.Rout")) failfile <- paste(outfile, "fail", sep = "." ) writeLines(c( paste0("library('", pkg$package, "')"), commands), con = outfile) - cmd <- paste(shQuote(file.path(R.home("bin"), "R")), - "CMD BATCH --vanilla --no-timing", - shQuote(outfile), shQuote(failfile)) - res <- system(cmd) - if (res != 0L) { - show_failures(dirname(failfile)) + + if (!code_stdout) { + cmd <- paste(shQuote(file.path(R.home("bin"), "R")), + "CMD BATCH --vanilla --no-timing", + shQuote(outfile), shQuote(failfile)) + res <- system(cmd) + if (res != 0L) { + show_failures(dirname(failfile)) + } else { + file.rename(failfile, outfile) + } } else { - file.rename(failfile, outfile) + cmd <- paste(shQuote(file.path(R.home("bin"), "Rscript")), + "--vanilla", shQuote(outfile)) + res <- system(cmd) + if (res != 0L) { + stop("Failure when running covr commands") + } } } diff --git a/man/package_coverage.Rd b/man/package_coverage.Rd index c9324ea7..24f45bb0 100644 --- a/man/package_coverage.Rd +++ b/man/package_coverage.Rd @@ -17,7 +17,8 @@ package_coverage( install_path = temp_file("R_LIBS"), ..., exclusions, - pre_clean = TRUE + pre_clean = TRUE, + live_stdout = FALSE ) } \arguments{ @@ -58,6 +59,10 @@ directory. It can sometimes be useful to set this (along with \code{clean = FALS \item{exclusions}{\sQuote{Deprecated}, please use \sQuote{line_exclusions} instead.} \item{pre_clean}{whether to delete all objects present in the src directory before recompiling} + +\item{live_stdout}{When running code specified in the \code{code} argument, whether to +use Rscript so that the console updates live (defaults to FALSE, using R CMD BATCH, +and only showing the output after all tests have run when there is a failure)} } \description{ This function calculates the test coverage for a development package on the