Skip to content

Commit

Permalink
Added a test for the renv download method diagnostic check
Browse files Browse the repository at this point in the history
  • Loading branch information
rmbielby committed Nov 11, 2024
1 parent faa6a6e commit f029e76
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 10 deletions.
12 changes: 8 additions & 4 deletions R/diagnostic_test.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,16 @@ check_renv_download_method <- function(
}
rdm_present <- .renviron %>% stringr::str_detect("RENV_DOWNLOAD_METHOD")
if (any(rdm_present)) {
dfeR::toggle_message(
"Found RENV_DOWNLOAD_METHOD in .Renviron:",
verbose = verbose
current_setting_message <- paste0(
"RENV_DOWNLOAD_METHOD is currently set to:\n ",
.renviron[rdm_present]
)
dfeR::toggle_message(" ", .renviron[rdm_present], verbose = verbose)
detected_method <- .renviron[rdm_present] |>
stringr::str_split("=") |>
unlist() |>
magrittr::extract(2)
} else {
current_setting_message <- "RENV_DOWNLOAD_METHOD is not currently set."
detected_method <- NA
}
if (is.na(detected_method) || detected_method != "\"curl\"") {
Expand All @@ -133,6 +133,9 @@ check_renv_download_method <- function(
)
readRenviron(renviron_file)
} else {
dfeR::toggle_message(current_setting_message,
verbose = verbose
)
message("If you wish to manually update your .Renviron file:")
message(" - Run the command in the R console to open .Renviron:")
message(" usethis::edit_r_environ()")
Expand All @@ -142,6 +145,7 @@ check_renv_download_method <- function(
}
message(" - Add the following line to .Renviron:")
message(" RENV_DOWNLOAD_METHOD=\"curl\"")
message("Or run `dfeR::check_renv_download_method(clean=TRUE)`")
}
} else {
message("PASS: Your RENV_DOWNLOAD_METHOD is set to curl.")
Expand Down
10 changes: 7 additions & 3 deletions man/check_proxy_settings.Rd

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

6 changes: 4 additions & 2 deletions man/check_renv_download_method.Rd

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

3 changes: 2 additions & 1 deletion man/diagnostic_test.Rd

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

12 changes: 12 additions & 0 deletions tests/testthat/test-diagnostic_test.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,15 @@ test_that("Check proxy settings identifies and removes proxy setting", {
purrr::keep(list(x = NULL), names(list(x = NULL)) != "x")
)
})

test_that("Check RENV_DOWNLOAD_METHOD", {
# Check that check_proxy_settings identifies the rogue entry
expect_equal(
check_renv_download_method(
".Renviron_test",
clean = FALSE
) |>
suppressMessages(),
list(RENV_DOWNLOAD_METHOD = NA)
)
})

0 comments on commit f029e76

Please sign in to comment.