Debian Codegraph @

tests/testthat/test-autoload.R

raw
1
2 test_that("autoload() works", {
3 skip_on_cran()
4
5 # TODO: Failed on Windows CI, but works locally?
6 skip_on_windows()
7
8 project <- renv_tests_scope()
9
10 # initialize renv project here
11 init()
12
13 # make sure we have renv installed for this test
14 libpaths <- the$default_libpaths[[".libPaths()"]]
15 source <- find.package("renv", lib.loc = libpaths)
16 renv_imbue_self(project, source = source)
17
18 # make sure autoloader is enabled in this scope
19 renv_scope_envvars(RENV_AUTOLOAD_ENABLED = "TRUE")
20
21 # make sure default library paths are visible to child process
22 renv_scope_envvars(
23 R_LIBS = NULL,
24 R_LIBS_USER = paste(libpaths, collapse = .Platform$path.sep),
25 R_LIBS_SITE = NULL
26 )
27
28 # move to sub-directory
29 dir.create("subdir")
30 renv_scope_wd("subdir")
31
32 # create a .Rprofile that calls renv::autoload()
33 profile <- renv_test_code({
34 renv::autoload()
35 })
36
37 renv_scope_envvars(R_PROFILE_USER = profile)
38
39 # launch R and see what library paths we got
40 output <- renv_system_exec(
41 command = R(),
42 args = c("-s", "-e", renv_shell_quote("writeLines(.libPaths()[1])")),
43 action = "testing autoload"
44 )
45
46 expected <- .libPaths()[1]
47 expect_equal(tail(output, n = length(expected)), expected)
48
49 })