Skip to content

Commit

Permalink
fix checkout tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinushey committed Aug 22, 2024
1 parent 7a6837b commit fcfe748
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 9 deletions.
24 changes: 18 additions & 6 deletions R/checkout.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,28 @@ checkout <- function(repos = NULL,
restore(lockfile = lockfile, clean = clean)

# re-generate the activate script
args <- c("--vanilla", "-s", "-e", shQuote("renv::activate()"))
r(args)
local({

# make sure we can find 'renv' on the library paths
renv_scope_libpaths(the$library_path)

# invoke activate
args <- c("--vanilla", "-s", "-e", shQuote("renv::activate()"))
r(args)

})

# update the renv lockfile record
# (note: it might not be available when running tests)
local({

renv <- renv_lockfile_records(lockfile)[["renv"]]
if (is.null(renv))
return()

renv_scope_options(renv.verbose = FALSE)
record(
records = renv_lockfile_records(lockfile)["renv"],
project = project
)
record(records = list(renv = renv), project = project)

})

}
Expand Down
9 changes: 9 additions & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
# NOTE: needs to be visible to embedded instances of renv as well
the$envir_self <<- renv_envir_self()

# figure out where 'renv' was loaded from -- if tests are running
# and we're using devtools::load_all(), we might need to fall back
# to whatever version of renv is available on the library paths
load <- Sys.getenv("DEVTOOLS_LOAD", unset = NA)
the$library_path <<- if (identical(load, .packageName))
dirname(renv_package_find(.packageName))
else
libname

# make sure renv (and packages using renv!!!) use tempdir for storage
# when running tests, or R CMD check
if (checking() || testing()) {
Expand Down
2 changes: 1 addition & 1 deletion man/install.Rd

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

2 changes: 1 addition & 1 deletion man/restore.Rd

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

5 changes: 5 additions & 0 deletions tests/testthat/helper-scope.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,8 @@ renv_scope_local <- function() {
path <- renv_tests_path("local")
renv_scope_envvars(RENV_PATHS_LOCAL = path, scope = parent.frame())
}

renv_tests_dependencies <- function(packages) {
code <- sprintf("library(%s)", packages)
cat(code, file = "dependencies.R", sep = "\n", append = TRUE)
}
4 changes: 3 additions & 1 deletion tests/testthat/test-checkout.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
test_that("we can check out packages from our local repository", {

# enter test scope
project <- renv_tests_scope("breakfast")
project <- renv_tests_scope()
init()

# check out a package + its dependencies; this invocation is
# similar in spirit to a plain `install()` call
renv_tests_dependencies("breakfast")
checkout(packages = "breakfast")

# check that they were installed
Expand Down

0 comments on commit fcfe748

Please sign in to comment.