diff --git a/DESCRIPTION b/DESCRIPTION index 42ee5a122..7b5ac9a67 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -55,6 +55,8 @@ Suggests: testthat (>= 3.1.8) Config/Needs/website: tidyverse/tidytemplate, xml2 Config/testthat/edition: 3 +Config/testthat/parallel: TRUE +Config/testthat/start-first: github-actions, release Encoding: UTF-8 Language: en-US Roxygen: list(markdown = TRUE) diff --git a/NAMESPACE b/NAMESPACE index 14daa906d..b6bcb9a93 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -221,3 +221,4 @@ importFrom(purrr,map) importFrom(purrr,map_chr) importFrom(purrr,map_int) importFrom(purrr,map_lgl) +importFrom(utils,available.packages) diff --git a/R/release.R b/R/release.R index 7bff3ed56..61302d6de 100644 --- a/R/release.R +++ b/R/release.R @@ -412,7 +412,7 @@ cran_version <- function(package = project_name(), available = NULL) { if (is.null(available)) { # Guard against CRAN mirror being unset available <- tryCatch( - utils::available.packages(repos = default_cran_mirror()), + available.packages(repos = default_cran_mirror()), error = function(e) NULL ) if (is.null(available)) { diff --git a/R/usethis-package.R b/R/usethis-package.R index 082017ade..fd1b8bb99 100644 --- a/R/usethis-package.R +++ b/R/usethis-package.R @@ -7,6 +7,7 @@ #' @importFrom glue glue glue_collapse glue_data #' @importFrom lifecycle deprecated #' @importFrom purrr map map_chr map_lgl map_int +#' @importFrom utils available.packages ## usethis namespace: end NULL diff --git a/tests/testthat/test-release.R b/tests/testthat/test-release.R index dabdddba3..d9644ada1 100644 --- a/tests/testthat/test-release.R +++ b/tests/testthat/test-release.R @@ -29,6 +29,8 @@ test_that("non-patch + lifecycle = advanced deprecation process", { create_local_package() use_package("lifecycle") + local_mocked_bindings(tidy_minimum_r_version = function() "3.6") + has_deprecation <- function(x) any(grepl("deprecation processes", x)) expect_true(has_deprecation(release_checklist("1.0.0", on_cran = TRUE))) expect_true(has_deprecation(release_checklist("1.1.0", on_cran = TRUE))) @@ -200,54 +202,28 @@ test_that("get_release_data() works for new-style CRAN-RELEASE", { expect_equal(path_file(res$file), "CRAN-SUBMISSION") }) -test_that("cran_version() is robust to unset CRAN mirror with unreleased pkg (#1857)", { - skip_if_offline() - # we don't want this to be the name of a package someone actually releases on CRAN - pkg <- "foofy.asdf123" - - withr::with_options( - list(repos = c(CRAN = "https://cloud.r-project.org")), - expect_null(cran_version(pkg)) - ) - - withr::with_options( - list(repos = c(CRAN = "@CRAN@")), - expect_null(cran_version(pkg)) - ) - - withr::with_options( - list(repos = c(CRAN = NA)), - expect_null(cran_version(pkg)) - ) +test_that("cran_version() returns package version if package found", { + local_mocked_bindings(available.packages = function(...) { + # simulate minimal available.packages entry + as.matrix(data.frame(Package = c(usethis = "usethis"), Version = "1.0.0")) + }) - withr::with_options( - list(repos = NULL), - expect_null(cran_version(pkg)) - ) + expect_null(cran_version("doesntexist")) + expect_equal(cran_version("usethis"), package_version("1.0.0")) }) -test_that("cran_version() is robust to unset CRAN mirror with released pkg (#1857)", { - skip_if_offline() - pkg <- "usethis" - - withr::with_options( - list(repos = c(CRAN = "https://cloud.r-project.org")), - expect_s3_class(cran_version(pkg), "package_version") - ) +test_that("cran_version() returns NULL if no available packages", { + local_mocked_bindings(available.packages = function(...) NULL) + expect_null(cran_version("doesntexist")) +}) - withr::with_options( - list(repos = c(CRAN = "@CRAN@")), - expect_s3_class(cran_version(pkg), "package_version") - ) +test_that("default_cran_mirror() is respects set value but falls back to cloud", { + withr::local_options(repos = c(CRAN = "https://example.com")) + expect_equal(default_cran_mirror(), c(CRAN = "https://example.com")) - withr::with_options( - list(repos = c(CRAN = NA)), - expect_s3_class(cran_version(pkg), "package_version") - ) + withr::local_options(repos = c(CRAN = "@CRAN@")) + expect_equal(default_cran_mirror(), c(CRAN = "https://cloud.r-project.org")) - withr::with_options( - list(repos = NULL), - expect_s3_class(cran_version(pkg), "package_version") - ) + withr::local_options(repos = c()) + expect_equal(default_cran_mirror(), c(CRAN = "https://cloud.r-project.org")) }) -