| 1 |
|
| 2 |
test_that("invalid lockfile entries are reported", { |
| 3 |
|
| 4 |
renv_tests_scope() |
| 5 |
renv_scope_options(repos = NULL) |
| 6 |
|
| 7 |
expect_warning(renv_load_r(getwd(), NULL)) |
| 8 |
expect_warning(renv_load_r(getwd(), list())) |
| 9 |
|
| 10 |
# this used to be a warning, but now we just write as an info message |
| 11 |
# expect_warning(renv_load_r(getwd(), list(Version = "1.0.0"))) |
| 12 |
|
| 13 |
}) |
| 14 |
|
| 15 |
test_that("renv/settings.R is sourced on load if available", { |
| 16 |
renv_tests_scope() |
| 17 |
ensure_directory("renv") |
| 18 |
writeLines("options(renv.test.dummy = 1)", con = "renv/settings.R") |
| 19 |
renv_load_settings(getwd()) |
| 20 |
expect_equal(getOption("renv.test.dummy"), 1) |
| 21 |
options(renv.test.dummy = NULL) |
| 22 |
}) |
| 23 |
|
| 24 |
test_that("errors when sourcing user profile are reported", { |
| 25 |
skip_on_cran() |
| 26 |
renv_tests_scope() |
| 27 |
renv_scope_options(renv.config.user.profile = TRUE) |
| 28 |
profile <- renv_scope_tempfile("renv-profile-", fileext = ".R") |
| 29 |
writeLines("stop(1)", con = profile) |
| 30 |
renv_scope_envvars(R_PROFILE_USER = profile) |
| 31 |
tryCatch(expect_warning(renv_load_rprofile(getwd())), error = identity) |
| 32 |
}) |
| 33 |
|
| 34 |
test_that("load() installs packages if needed", { |
| 35 |
|
| 36 |
renv_tests_scope("breakfast") |
| 37 |
renv_scope_envvars(RENV_CONFIG_STARTUP_QUIET = "FALSE") |
| 38 |
|
| 39 |
install("bread") |
| 40 |
init() |
| 41 |
unlink("renv/library", recursive = TRUE) |
| 42 |
|
| 43 |
load() |
| 44 |
expect_true(renv_package_installed("breakfast")) |
| 45 |
|
| 46 |
}) |
| 47 |
|
| 48 |
test_that("load() reports on problems", { |
| 49 |
|
| 50 |
renv_scope_libpaths() |
| 51 |
renv_tests_scope() |
| 52 |
renv_scope_envvars(RENV_CONFIG_STARTUP_QUIET = "FALSE") |
| 53 |
|
| 54 |
renv_tests_scope("egg") |
| 55 |
init() |
| 56 |
record("[email protected]") |
| 57 |
|
| 58 |
expect_snapshot(load()) |
| 59 |
|
| 60 |
}) |
| 61 |
|
| 62 |
test_that("load() delegates to base::load() when appropriate", { |
| 63 |
|
| 64 |
renv_tests_scope() |
| 65 |
|
| 66 |
value <- 42 |
| 67 |
save(value, file = ".RData") |
| 68 |
rm(value) |
| 69 |
|
| 70 |
load(".RData") |
| 71 |
expect_equal(value, 42) |
| 72 |
rm(value) |
| 73 |
|
| 74 |
load(file = ".RData") |
| 75 |
expect_equal(value, 42) |
| 76 |
rm(value) |
| 77 |
|
| 78 |
envir <- new.env(parent = emptyenv()) |
| 79 |
load(".RData", envir = envir) |
| 80 |
expect_equal(envir$value, 42) |
| 81 |
|
| 82 |
}) |