Skip to content

Commit

Permalink
with parallel tests, we can't rely on order, so tests requiring the p…
Browse files Browse the repository at this point in the history
…re-commit executable should be either placed in the conda tests file or be skipped if installation method is conda
  • Loading branch information
lorenzwalthert committed Mar 31, 2024
1 parent d8f2dba commit 15a1ff4
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 37 deletions.
36 changes: 36 additions & 0 deletions tests/testthat/test-conda.R
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,39 @@ if (!on_cran()) {
}
})
}

test_that("Autoupdate is not conducted when renv present in incompatible setup", {
skip_on_cran()

# mock old pre-commit and renv versions
local_mocked_bindings(version_precommit = function(...) "2.13.0")

local_test_setup(
git = TRUE, use_precommit = TRUE, install_hooks = FALSE, open = FALSE
)
initial <- rev_read() %>%
rev_as_pkg_version()
# simulate adding {renv}
writeLines("", "renv.lock")

# should downgrade rev
expect_error(
ensure_renv_precommit_compat(
package_version_renv = package_version("0.13.0"), root = getwd()
),
"Please update"
)
downgraded <- rev_read() %>%
rev_as_pkg_version()
expect_true(downgraded == initial)

# simulate removing {renv} should be updated
fs::file_delete("renv.lock")
expect_warning(
ensure_renv_precommit_compat(
package_version("0.13.0"),
root = getwd()
),
NA
)
})
37 changes: 0 additions & 37 deletions tests/testthat/test-setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,40 +82,3 @@ test_that("Pre-commit CI setup works", {
)
expect_error(use_ci(root = getwd(), open = FALSE), "o `.pre-commit-config.yaml`")
})


test_that("Autoupdate is not conducted when renv present in incompatible setup", {
skip_on_cran()

# mock old pre-commit and renv versions
mockery::stub(ensure_renv_precommit_compat, "version_precommit", "2.13.0")

local_test_setup(
git = TRUE, use_precommit = TRUE, install_hooks = FALSE, open = FALSE
)
initial <- rev_read() %>%
rev_as_pkg_version()
# simulate adding {renv}
writeLines("", "renv.lock")

# should downgrade rev
expect_error(
ensure_renv_precommit_compat(
package_version_renv = package_version("0.13.0"), root = getwd()
),
"Please update"
)
downgraded <- rev_read() %>%
rev_as_pkg_version()
expect_true(downgraded == initial)

# simulate removing {renv} should be updated
fs::file_delete("renv.lock")
expect_warning(
ensure_renv_precommit_compat(
package_version("0.13.0"),
root = getwd()
),
NA
)
})

0 comments on commit 15a1ff4

Please sign in to comment.