Skip to content

Commit

Permalink
Remove dead code, add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborcsardi committed Sep 16, 2021
1 parent e629c93 commit a809fd4
Show file tree
Hide file tree
Showing 15 changed files with 611 additions and 68 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ Remotes:
r-lib/cli
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.1.9001
RoxygenNote: 7.1.2
Config/testthat/edition: 3
16 changes: 1 addition & 15 deletions R/background.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,12 @@ rcmdcheck_process <- R6Class(
l
},

read_error_lines = function(...) {
l <- super$read_error_lines(...)
private$cstderr <- c(private$cstderr, paste0(l, "\n"))
l
},

read_output = function(...) {
l <- super$read_output(...)
private$cstdout <- c(private$cstdout, l)
l
},

read_error = function(...) {
l <- super$read_error(...)
private$cstderr <- c(private$cstderr, l)
l
},

kill = function(...) {
private$killed <- TRUE
super$kill(...)
Expand Down Expand Up @@ -132,9 +120,7 @@ rcc_init <- function(self, private, super, path, args, build_args,

# Add pandoc to the PATH for R CMD build.
# The updated PATH is also inherited in the subprocess below.
if (!nzchar(Sys.which("pandoc")) && nzchar(Sys.getenv("RSTUDIO_PANDOC"))) {
local_path(Sys.getenv("RSTUDIO_PANDOC"))
}
if (should_use_rs_pandoc()) local_path(Sys.getenv("RSTUDIO_PANDOC"))

pkgbuild::local_build_tools()

Expand Down
39 changes: 4 additions & 35 deletions R/callback.R
Original file line number Diff line number Diff line change
Expand Up @@ -220,51 +220,20 @@ block_callback <- function(top_line = TRUE, sys_time = NULL) {
}
}

to_status <- function(x) {
notes <- warnings <- errors <- 0
if (grepl("ERROR", x)) {
errors <- as.numeric(sub("^.* ([0-9]+) ERROR.*$", "\\1", x))
}
if (grepl("WARNING", x)) {
warnings <- as.numeric(sub("^.* ([0-9]+) WARNING.*$", "\\1", x))
}
if (grepl("NOTE", x)) {
notes <- as.numeric(sub("^.* ([0-9]+) NOTE.*$", "\\1", x))
}
structure(
list(
notes = rep("", notes),
warnings = rep("", warnings),
errors = rep("", errors)
),
class = "rcmdcheck"
)
}

is_new_check <- function(x) {
grepl("^\\*\\*? ", x)
}

simple_callback <- function(top_line = TRUE) {
simple_callback <- function(top_line = TRUE, sys_time = NULL) {
function(x) cat(gsub("[\r\n]+", "\n", x, useBytes = TRUE))
}

detect_callback <- function() {
if (is_dynamic_tty2()) block_callback() else simple_callback()
}

#' @importFrom cli is_dynamic_tty

is_dynamic_tty2 <- function() {
## This is to work around a cli bug:
## https://github.com/r-lib/cli/issues/70
if ((x <- Sys.getenv("R_CLI_DYNAMIC", "")) != "") {
isTRUE(x)
} else {
is_dynamic_tty()
}
detect_callback <- function() {
if (cli::is_dynamic_tty()) block_callback() else simple_callback()
}

should_add_spinner <- function() {
is_dynamic_tty2()
is_dynamic_tty()
}
10 changes: 9 additions & 1 deletion R/options.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,17 @@
#' fractional. Defaults to 1/3 of a second. The corresponding option is
#' `rcmdcheck.timestamp_limit`.
#'
#' * `RCMDCHECK_USE_RSTUDIO_PANDOC`: Flag (`true` or `false`). If `true`,
#' then rcmdcheck _always_ puts RStudio's pandoc (if available) on the
#' path. If `false`, then it _never_ does that. If not set, or set to a
#' different value, then pandoc is put on the path only if it is not
#' already available. RStudio's pandoc is detected via an `RSTUDIO_PANDOC`
#' environment variable.
#'
#' * `RSTUDIO_PANDOC`: if set, rcmdcheck adds this environment variable
#' to the PATH if pandoc is not on the PATH already. It is usually set
#' in RStudio.
#' in RStudio. See also the `RCMDCHECK_USE_RSTUDIO_PANDOC` environment
#' variable.
#'
#' # Options
#'
Expand Down
4 changes: 1 addition & 3 deletions R/package.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ rcmdcheck <- function(path = ".", quiet = FALSE, args = character(),
}

# Add pandoc to the PATH, for R CMD build and R CMD check
if (!nzchar(Sys.which("pandoc")) && nzchar(Sys.getenv("RSTUDIO_PANDOC"))) {
local_path(Sys.getenv("RSTUDIO_PANDOC"))
}
if (should_use_rs_pandoc()) local_path(Sys.getenv("RSTUDIO_PANDOC"))

pkgbuild::local_build_tools()

Expand Down
14 changes: 14 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,17 @@ as_flag <- function(x, default = FALSE, name = "") {
no_timing <- function(x) {
gsub("\\[[0-9]+s(/[0-9]+s)?\\] ([A-Z]+)", "\\2", x, useBytes = TRUE)
}

should_use_rs_pandoc <- function() {
ev <- Sys.getenv("RCMDCHECK_USE_RSTUDIO_PANDOC", "")

if (tolower(ev) == "true") {
TRUE

} else if (tolower(ev) == "false") {
FALSE

} else {
!nzchar(Sys.which("pandoc")) && nzchar(Sys.getenv("RSTUDIO_PANDOC"))
}
}
9 changes: 8 additions & 1 deletion man/rcmdcheck-config.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a809fd4

Please sign in to comment.