| 1 |
|
| 2 |
test_that("library paths set in a user profile are overridden after load", { |
| 3 |
skip_on_cran() |
| 4 |
skip_on_os("windows") |
| 5 |
|
| 6 |
renv_tests_scope() |
| 7 |
renv_scope_envvars(R_LIBS = NULL) |
| 8 |
|
| 9 |
init() |
| 10 |
renv_imbue_impl(project = getwd(), force = TRUE) |
| 11 |
|
| 12 |
profile <- c( |
| 13 |
".libPaths('.')", |
| 14 |
"source('renv/activate.R')" |
| 15 |
) |
| 16 |
writeLines(profile, con = ".Rprofile") |
| 17 |
|
| 18 |
# ensure profile is executed |
| 19 |
renv_scope_envvars(R_PROFILE_USER = NULL) |
| 20 |
|
| 21 |
# invoke R |
| 22 |
args <- c("-s", "-e", shQuote("writeLines(.libPaths(), 'libpaths.txt')")) |
| 23 |
output <- system2(R(), args, stdout = FALSE, stderr = FALSE) |
| 24 |
|
| 25 |
actual <- readLines("libpaths.txt") |
| 26 |
expected <- renv_libpaths_all() |
| 27 |
|
| 28 |
expect_equal(actual[[1]], expected[[1]]) |
| 29 |
|
| 30 |
}) |
| 31 |
|
| 32 |
test_that(".First is executed; library paths are restored after", { |
| 33 |
|
| 34 |
skip_on_cran() |
| 35 |
skip_on_os("windows") |
| 36 |
|
| 37 |
renv_tests_scope() |
| 38 |
renv_scope_envvars(R_LIBS = NULL) |
| 39 |
|
| 40 |
init() |
| 41 |
renv_imbue_impl(project = getwd(), force = TRUE) |
| 42 |
|
| 43 |
# add a .First to the profile |
| 44 |
profile <- quote({ |
| 45 |
|
| 46 |
.First <- function() { |
| 47 |
writeLines("Hello from .First") |
| 48 |
.libPaths(".") |
| 49 |
} |
| 50 |
|
| 51 |
source("renv/activate.R") |
| 52 |
|
| 53 |
}) |
| 54 |
|
| 55 |
# ensure profile is executed |
| 56 |
renv_scope_envvars(R_PROFILE_USER = NULL) |
| 57 |
writeLines(deparse(profile), con = ".Rprofile") |
| 58 |
|
| 59 |
# invoke R |
| 60 |
script <- renv_test_code({ |
| 61 |
print(.libPaths()) |
| 62 |
writeLines(.libPaths(), con = "libpaths.txt") |
| 63 |
}) |
| 64 |
|
| 65 |
args <- c("-f", shQuote(script)) |
| 66 |
output <- renv_system_exec(R(), args, action = "writing libpaths") |
| 67 |
|
| 68 |
actual <- readLines("libpaths.txt") |
| 69 |
expected <- renv_libpaths_all() |
| 70 |
|
| 71 |
expect_equal(actual[[1L]], expected[[1L]]) |
| 72 |
|
| 73 |
}) |