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

Reduce nesting in tests by using withr::local_envvar() #599

Merged
merged 3 commits into from
Jan 30, 2025

Conversation

olivroy
Copy link
Contributor

@olivroy olivroy commented Jan 28, 2025

#589 (comment)

Does something along this make sense @hadley ?

Note: easier to review if selecting hide whitespace in github https://github.com/r-lib/covr/pull/599/files?diff=unified&w=1

@olivroy olivroy changed the title Simplify conditions and nesting Reduce nesting in tests by using withr::local_envvar() Jan 28, 2025
@@ -54,396 +54,365 @@ ci_vars <- c(
cov <- package_coverage(test_path("TestS4"))

test_that("it generates a properly formatted json file", {
Copy link
Member

Choose a reason for hiding this comment

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

I was expecting something more like this:

test_that("it generates a properly formatted json file", {
  withr::local_envvar(ci_vars)
  local_mocked_bindings(
    RETRY = function(...) list(...),
    content = identity,
    local_branch = function(dir) "master",
    current_commit = function(dir) "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3"
  )

  res <- codecov(coverage = cov)
  json <- jsonlite::fromJSON(res$body)

  expect_match(json$files$name, "R/TestS4.R")
  expect_equal(
    json$files$coverage[[1]],
    c(
      NA, NA, NA, NA, NA, NA, NA, 5, 2, NA, 3, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
      NA, NA, NA, NA, 1, NA, NA, NA, NA, NA, 1, NA, NA, NA, NA, NA, 1, NA
    )
  )
  expect_equal(json$uploader, "R")
})

)
withr::local_envvar(ci_vars)
Copy link
Member

Choose a reason for hiding this comment

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

I'd suggest you keep this closer to its original position to make the diff a little simpler.

@jimhester jimhester merged commit 7510927 into r-lib:main Jan 30, 2025
12 checks passed
@jimhester
Copy link
Member

Looks good, thanks for working on this @olivroy and @hadley for the review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants