diff --git a/DESCRIPTION b/DESCRIPTION index a6cf16e..67f2ef0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: checked Title: Systematically Run R CMD Checks -Version: 0.5.2 +Version: 0.5.2.9000 Authors@R: c( person( diff --git a/NEWS.md b/NEWS.md index 2843be2..017cff1 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,12 @@ +# checked (development) + +* Make is possible to construct reporter environments with additional values + to better control their behavior. + +* Add `checks_only` parameter to `reporter_basic_tty` which if set to TRUE + will make the reporter broadcast only check tasks instead of both + install and check. + # checked 0.5.2 * Add timers striping to `strip_details_from_issue()` to avoid false-positives. diff --git a/R/reporter.R b/R/reporter.R index ace72b6..fc0ba80 100644 --- a/R/reporter.R +++ b/R/reporter.R @@ -21,31 +21,39 @@ #' A line-feed reporter presenting output one line at a time, providing #' a reporter with minimal assumptions about terminal capabilities. #' +#' @param checks_only whether basic tty reporter should report only check tasks. +#' @param ... additional values which should be assigned to the reported +#' environment. +#' #' @family reporters #' @name reporters NULL -reporter <- function(type) { +reporter <- function(type, ...) { type <- paste0("reporter_", type) - structure(new.env(parent = baseenv()), class = c(type, "reporter")) + reporter_options <- list(...) + structure( + list2env(reporter_options, parent = baseenv(), hash = TRUE), + class = c(type, "reporter") + ) } #' @rdname reporters #' @export -reporter_ansi_tty <- function() { - reporter("ansi_tty") +reporter_ansi_tty <- function(...) { + reporter("ansi_tty", ...) } #' @rdname reporters #' @export -reporter_ansi_tty2 <- function() { - reporter("ansi_tty2") +reporter_ansi_tty2 <- function(...) { + reporter("ansi_tty2", ...) } #' @rdname reporters #' @export -reporter_basic_tty <- function() { - reporter("basic_tty") +reporter_basic_tty <- function(checks_only = FALSE, ...) { + reporter("basic_tty", checks_only = checks_only, ...) } #' @rdname reporters diff --git a/R/reporter_basic_tty.R b/R/reporter_basic_tty.R index 946d56e..1ec4ef4 100644 --- a/R/reporter_basic_tty.R +++ b/R/reporter_basic_tty.R @@ -7,11 +7,15 @@ report_start_setup.reporter_basic_tty <- function( ) { # start with all tasks initialized as pending v <- igraph::V(checker$graph) - v_actionable <- v[is_actionable_task(v$task)] + v_reportable <- if (reporter$checks_only) { + v[is_check(v$task)] + } else { + v[is_actionable_task(v$task)] + } # named factor vector, names as task aliases and value of last reported status - reporter$status <- rep(STATUS$pending, times = length(v_actionable)) - names(reporter$status) <- v_actionable$name + reporter$status <- rep(STATUS$pending, times = length(v_reportable)) + names(reporter$status) <- v_reportable$name reporter$time_start <- Sys.time() @@ -44,8 +48,17 @@ report_status.reporter_basic_tty <- function(reporter, checker, envir) { "pending" = "queued", "in progress" = cli::cli_fmt(cli::cli_text("started")), "done" = { + pkgs_done <- reporter$status == STATUS$done # nolint + # +1 to acount for the task that is currently processed + fmt_count <- + cli::col_grey(" [{sum(pkgs_done)+1}/{length(pkgs_done)}]") + if (is.null(p)) { - cli::cli_fmt(cli::cli_text("finished (restored)")) + cli::cli_fmt( + cli::cli_text( + "finished", cli::format_inline(fmt_count), " (restored)" + ) + ) } else if (p$get_r_exit_status() != 0) { # checks processes don't have logs associated with it message <- if (!is.null(p$log)) { @@ -70,6 +83,7 @@ report_status.reporter_basic_tty <- function(reporter, checker, envir) { fmt_warning <- "{.warn {ewn[[2]]} WARNING{?/S}}" fmt_note <- "{.note {ewn[[3]]} NOTE{?/S}}" fmt_duration <- " {.time_taken ({format_time(dur)})}" + cli::cli_fmt(cli::cli_text( "finished", if (sum(ewn) > 0) " with ", @@ -78,6 +92,7 @@ report_status.reporter_basic_tty <- function(reporter, checker, envir) { if (ewn[[2]] > 0) cli::format_inline(fmt_warning), if (ewn[[3]] > 0) cli::format_inline(fmt_note) )), + cli::format_inline(fmt_count), if (!is.null(dur)) cli::format_inline(fmt_duration) )) } diff --git a/man/reporters.Rd b/man/reporters.Rd index b2f8c13..feb2287 100644 --- a/man/reporters.Rd +++ b/man/reporters.Rd @@ -8,14 +8,20 @@ \alias{reporter_default} \title{Check checker Runner Reporters} \usage{ -reporter_ansi_tty() +reporter_ansi_tty(...) -reporter_ansi_tty2() +reporter_ansi_tty2(...) -reporter_basic_tty() +reporter_basic_tty(checks_only = FALSE, ...) reporter_default() } +\arguments{ +\item{...}{additional values which should be assigned to the reported +environment.} + +\item{checks_only}{whether basic tty reporter should report only check tasks.} +} \description{ Reporters are used to configure how output is communicated while running a \code{\link{checker}}. They range from glossy command-line tools intended for diff --git a/tests/testthat/_snaps/reporters.md b/tests/testthat/_snaps/reporters.md index 6806e4f..5c29a37 100644 --- a/tests/testthat/_snaps/reporters.md +++ b/tests/testthat/_snaps/reporters.md @@ -11,18 +11,18 @@ Message Checks [][install] rev.both.dependency started - [][install] rev.both.dependency finished () + [][install] rev.both.dependency finished [1/7] () [][install] pkg.ok.error started - [][install] pkg.ok.error finished () + [][install] pkg.ok.error finished [2/7] () [][install] pkg.ok.error started [][check] rev.both.ok started - [][install] pkg.ok.error finished () - [][check] rev.both.ok finished with 1 NOTE () + [][install] pkg.ok.error finished [3/7] () + [][check] rev.both.ok finished with 1 NOTE [4/7] () [][check] rev.both.error started - [][check] rev.both.error finished with 1 NOTE () + [][check] rev.both.error finished with 1 NOTE [5/7] () [][check] rev.both.ok started - [][check] rev.both.ok finished with 1 NOTE () + [][check] rev.both.ok finished with 1 NOTE [6/7] () [][check] rev.both.error started - [][check] rev.both.error finished with 1 ERROR, 1 WARNING () + [][check] rev.both.error finished with 1 ERROR, 1 WARNING [7/7] () Finished in