| 1 |
|
| 2 |
test_that("use() works as intended", { |
| 3 |
|
| 4 |
skip_on_cran() |
| 5 |
|
| 6 |
renv_tests_scope() |
| 7 |
init() |
| 8 |
|
| 9 |
oldpaths <- .libPaths() |
| 10 |
|
| 11 |
use( |
| 12 |
package = "toast", |
| 13 |
isolate = FALSE, |
| 14 |
attach = FALSE, |
| 15 |
verbose = FALSE, |
| 16 |
sandbox = FALSE |
| 17 |
) |
| 18 |
|
| 19 |
newpaths <- .libPaths() |
| 20 |
|
| 21 |
expect_true(length(newpaths) == length(oldpaths) + 1) |
| 22 |
|
| 23 |
toast <- find.package("toast") |
| 24 |
expect_true(renv_file_same(dirname(toast), .libPaths()[1])) |
| 25 |
|
| 26 |
}) |
| 27 |
|
| 28 |
test_that("use(lockfile) works as intended", { |
| 29 |
|
| 30 |
skip_on_cran() |
| 31 |
skip_on_windows() |
| 32 |
|
| 33 |
renv_tests_scope("bread") |
| 34 |
init() |
| 35 |
|
| 36 |
renv_scope_libpaths() |
| 37 |
use(lockfile = "renv.lock", isolate = TRUE, verbose = FALSE, sandbox = FALSE) |
| 38 |
|
| 39 |
libpath <- renv_use_libpath() |
| 40 |
pkgpath <- renv_package_find("bread") |
| 41 |
|
| 42 |
expect_equal( |
| 43 |
renv_path_normalize(pkgpath), |
| 44 |
renv_path_normalize(file.path(libpath, "bread")) |
| 45 |
) |
| 46 |
|
| 47 |
}) |
| 48 |
|
| 49 |
test_that("renv_use_cacheonly_install installs packages from the cache", { |
| 50 |
|
| 51 |
skip_on_cran() |
| 52 |
|
| 53 |
renv_tests_scope("bread") |
| 54 |
init() |
| 55 |
|
| 56 |
# get records from the lockfile (has proper Source, Version, etc.) |
| 57 |
lockfile <- renv_lockfile_read("renv.lock") |
| 58 |
records <- renv_lockfile_records(lockfile) |
| 59 |
|
| 60 |
# set up a fresh library and install from cache |
| 61 |
library <- tempfile("renv-library-") |
| 62 |
ensure_directory(library) |
| 63 |
|
| 64 |
installed <- renv_use_cacheonly_install(records = records, library = library) |
| 65 |
expect_true("bread" %in% names(installed)) |
| 66 |
expect_true(file.exists(file.path(library, "bread"))) |
| 67 |
|
| 68 |
}) |
| 69 |
|
| 70 |
test_that("renv_use_cacheonly_install skips packages not in the cache", { |
| 71 |
|
| 72 |
skip_on_cran() |
| 73 |
|
| 74 |
renv_tests_scope() |
| 75 |
|
| 76 |
# set up a fresh library |
| 77 |
library <- tempfile("renv-library-") |
| 78 |
ensure_directory(library) |
| 79 |
|
| 80 |
# use a record for a package that won't be in the cache |
| 81 |
records <- list( |
| 82 |
nosuchpackage = list( |
| 83 |
Package = "nosuchpackage", |
| 84 |
Version = "1.0.0", |
| 85 |
Source = "Repository" |
| 86 |
) |
| 87 |
) |
| 88 |
|
| 89 |
installed <- renv_use_cacheonly_install(records = records, library = library) |
| 90 |
expect_length(installed, 0) |
| 91 |
expect_false(file.exists(file.path(library, "nosuchpackage"))) |
| 92 |
|
| 93 |
}) |
| 94 |
|
| 95 |
test_that("renv_use_cacheonly_restore installs lockfile packages from cache", { |
| 96 |
|
| 97 |
skip_on_cran() |
| 98 |
skip_on_windows() |
| 99 |
|
| 100 |
renv_tests_scope("bread") |
| 101 |
init() |
| 102 |
|
| 103 |
# set up a fresh library |
| 104 |
library <- tempfile("renv-library-") |
| 105 |
ensure_directory(library) |
| 106 |
|
| 107 |
installed <- renv_use_cacheonly_restore(lockfile = "renv.lock", library = library) |
| 108 |
expect_true("bread" %in% names(installed)) |
| 109 |
expect_true(file.exists(file.path(library, "bread"))) |
| 110 |
|
| 111 |
}) |
| 112 |
|
| 113 |
test_that("use(repos = NULL) resolves dependencies from cache", { |
| 114 |
|
| 115 |
skip_on_cran() |
| 116 |
|
| 117 |
renv_tests_scope("breakfast") |
| 118 |
init() |
| 119 |
|
| 120 |
# reset the shared use libpath so we get a fresh library |
| 121 |
renv_scope_binding(the, "use_libpath", NULL) |
| 122 |
renv_scope_libpaths() |
| 123 |
|
| 124 |
use( |
| 125 |
"breakfast", |
| 126 |
repos = NULL, |
| 127 |
isolate = TRUE, |
| 128 |
verbose = FALSE, |
| 129 |
sandbox = FALSE |
| 130 |
) |
| 131 |
|
| 132 |
# breakfast depends on oatmeal and toast; toast depends on bread |
| 133 |
libpath <- renv_use_libpath() |
| 134 |
expect_true(file.exists(file.path(libpath, "breakfast"))) |
| 135 |
expect_true(file.exists(file.path(libpath, "oatmeal"))) |
| 136 |
expect_true(file.exists(file.path(libpath, "toast"))) |
| 137 |
expect_true(file.exists(file.path(libpath, "bread"))) |
| 138 |
|
| 139 |
}) |
| 140 |
|
| 141 |
test_that("use(repos = NULL) installs dependencies of already-installed packages", { |
| 142 |
|
| 143 |
skip_on_cran() |
| 144 |
|
| 145 |
renv_tests_scope("breakfast") |
| 146 |
init() |
| 147 |
|
| 148 |
# reset the shared use libpath so we get a fresh library |
| 149 |
renv_scope_binding(the, "use_libpath", NULL) |
| 150 |
renv_scope_libpaths() |
| 151 |
|
| 152 |
# pre-install breakfast (without dependencies) into the use library, |
| 153 |
# so it will be considered "compatible" during the compat check |
| 154 |
libpath <- renv_use_libpath() |
| 155 |
ensure_directory(libpath) |
| 156 |
renv_use_cacheonly_install( |
| 157 |
records = list(breakfast = list(Package = "breakfast", Source = "Repository")), |
| 158 |
library = libpath |
| 159 |
) |
| 160 |
expect_true(file.exists(file.path(libpath, "breakfast"))) |
| 161 |
expect_false(file.exists(file.path(libpath, "oatmeal"))) |
| 162 |
|
| 163 |
use( |
| 164 |
"breakfast", |
| 165 |
repos = NULL, |
| 166 |
isolate = TRUE, |
| 167 |
verbose = FALSE, |
| 168 |
sandbox = FALSE |
| 169 |
) |
| 170 |
|
| 171 |
# dependencies should still be resolved and installed |
| 172 |
expect_true(file.exists(file.path(libpath, "oatmeal"))) |
| 173 |
expect_true(file.exists(file.path(libpath, "toast"))) |
| 174 |
expect_true(file.exists(file.path(libpath, "bread"))) |
| 175 |
|
| 176 |
}) |
| 177 |
|
| 178 |
test_that("use(repos = NULL) installs from cache only", { |
| 179 |
|
| 180 |
skip_on_cran() |
| 181 |
|
| 182 |
renv_tests_scope("bread") |
| 183 |
init() |
| 184 |
|
| 185 |
# reset the shared use libpath so we get a fresh library |
| 186 |
renv_scope_binding(the, "use_libpath", NULL) |
| 187 |
renv_scope_libpaths() |
| 188 |
|
| 189 |
use( |
| 190 |
"bread", |
| 191 |
repos = NULL, |
| 192 |
isolate = TRUE, |
| 193 |
verbose = FALSE, |
| 194 |
sandbox = FALSE |
| 195 |
) |
| 196 |
|
| 197 |
libpath <- renv_use_libpath() |
| 198 |
expect_true(file.exists(file.path(libpath, "bread"))) |
| 199 |
|
| 200 |
}) |