Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up tests #1908

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,4 @@ importFrom(purrr,map)
importFrom(purrr,map_chr)
importFrom(purrr,map_int)
importFrom(purrr,map_lgl)
importFrom(utils,available.packages)
2 changes: 1 addition & 1 deletion R/release.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just mildly curious. Does this make a difference?

Updated: oh I see you want to mock it.

error = function(e) NULL
)
if (is.null(available)) {
Expand Down
1 change: 1 addition & 0 deletions R/usethis-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
64 changes: 20 additions & 44 deletions tests/testthat/test-release.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down Expand Up @@ -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"))
})

Loading