| 1 |
|
| 2 |
test_that("library permissions are validated before restore", { |
| 3 |
skip_on_os("windows") |
| •4 |
skip("This test fails in Debian autopkgtest environment") |
| 5 |
inaccessible <- renv_scope_tempfile() |
| 6 |
dir.create(inaccessible, mode = "0100") |
| 7 |
expect_false(renv_install_preflight_permissions(inaccessible)) |
| 8 |
}) |
| 9 |
|
| 10 |
test_that("restore() gives an error if no lockfile exists", { |
| 11 |
renv_tests_scope() |
| 12 |
expect_false(file.exists("renv.lock")) |
| 13 |
expect_error(restore()) |
| 14 |
}) |
| 15 |
|
| 16 |
test_that("we can restore packages after init", { |
| 17 |
skip_on_cran() |
| 18 |
renv_tests_scope("breakfast") |
| 19 |
|
| 20 |
init() |
| 21 |
|
| 22 |
libpath <- renv_paths_library() |
| 23 |
before <- list.files(libpath) |
| 24 |
|
| 25 |
unlink(renv_paths_library(), recursive = TRUE) |
| 26 |
restore() |
| 27 |
|
| 28 |
after <- list.files(libpath) |
| 29 |
expect_setequal(before, after) |
| 30 |
|
| 31 |
}) |
| 32 |
|
| 33 |
test_that("restore can recover when required packages are missing", { |
| 34 |
skip_on_cran() |
| 35 |
renv_tests_scope("breakfast") |
| 36 |
init() |
| 37 |
|
| 38 |
remove("oatmeal") |
| 39 |
snapshot(force = TRUE) |
| 40 |
unlink(renv_paths_library(), recursive = TRUE) |
| 41 |
restore() |
| 42 |
|
| 43 |
expect_true(renv_package_installed("oatmeal")) |
| 44 |
|
| 45 |
}) |
| 46 |
|
| 47 |
test_that("restore(clean = TRUE) removes packages not in the lockfile", { |
| 48 |
|
| 49 |
renv_tests_scope("oatmeal") |
| 50 |
init() |
| 51 |
|
| 52 |
renv_scope_options(renv.config.auto.snapshot = FALSE) |
| 53 |
install("bread") |
| 54 |
expect_true(renv_package_installed("bread")) |
| 55 |
|
| 56 |
restore(clean = TRUE) |
| 57 |
expect_false(renv_package_installed("bread")) |
| 58 |
|
| 59 |
}) |
| 60 |
|
| 61 |
test_that("renv.records can be used to override records during restore", { |
| 62 |
|
| 63 |
renv_tests_scope("bread") |
| 64 |
init() |
| 65 |
|
| 66 |
install("[email protected]") |
| 67 |
snapshot() |
| 68 |
expect_equal(renv_package_version("bread"), "0.1.0") |
| 69 |
|
| 70 |
bread <- list(Package = "bread", Version = "1.0.0", Source = "CRAN") |
| 71 |
overrides <- list(bread = bread) |
| 72 |
renv_scope_options(renv.records = overrides) |
| 73 |
|
| 74 |
restore() |
| 75 |
expect_equal(renv_package_version("bread"), "1.0.0") |
| 76 |
|
| 77 |
}) |
| 78 |
|
| 79 |
test_that("install.staged works as expected", { |
| 80 |
|
| 81 |
renv_tests_scope("breakfast") |
| 82 |
|
| 83 |
init() |
| 84 |
library <- renv_paths_library(project = getwd()) |
| 85 |
|
| 86 |
install.opts <- list(breakfast = "--version") |
| 87 |
|
| 88 |
local({ |
| 89 |
|
| 90 |
renv_scope_options( |
| 91 |
renv.config.install.staged = TRUE, |
| 92 |
renv.config.install.transactional = TRUE, |
| 93 |
install.opts = install.opts |
| 94 |
) |
| 95 |
|
| 96 |
renv_scope_envvars(RENV_PATHS_CACHE = renv_scope_tempfile()) |
| 97 |
|
| 98 |
unlink(renv_paths_library(), recursive = TRUE) |
| 99 |
expect_error(restore()) |
| 100 |
files <- list.files(library) |
| 101 |
expect_true(length(files) == 0L) |
| 102 |
|
| 103 |
}) |
| 104 |
|
| 105 |
local({ |
| 106 |
|
| 107 |
renv_scope_options( |
| 108 |
renv.config.install.staged = FALSE, |
| 109 |
renv.config.install.transactional = FALSE, |
| 110 |
install.opts = install.opts |
| 111 |
) |
| 112 |
|
| 113 |
renv_scope_envvars(RENV_PATHS_CACHE = renv_scope_tempfile()) |
| 114 |
|
| 115 |
unlink(renv_paths_library(), recursive = TRUE) |
| 116 |
expect_error(restore()) |
| 117 |
files <- list.files(library) |
| 118 |
expect_true(length(files) != 0L) |
| 119 |
|
| 120 |
}) |
| 121 |
|
| 122 |
}) |
| 123 |
|
| 124 |
test_that("restore(lockfile = '/path/to/lockfile') works", { |
| 125 |
|
| 126 |
renv_tests_scope("bread") |
| 127 |
|
| 128 |
init() |
| 129 |
|
| 130 |
unlink(paths$library(), recursive = TRUE) |
| 131 |
restore(lockfile = "renv.lock") |
| 132 |
expect_true(renv_package_installed("bread")) |
| 133 |
|
| 134 |
unlink(paths$library(), recursive = TRUE) |
| 135 |
lockfile <- renv_lockfile_load(project = getwd()) |
| 136 |
restore(lockfile = "renv.lock") |
| 137 |
expect_true(renv_package_installed("bread")) |
| 138 |
|
| 139 |
}) |
| 140 |
|
| 141 |
test_that("restore(packages = <...>) works", { |
| 142 |
renv_tests_scope("breakfast") |
| 143 |
init() |
| 144 |
unlink(paths$library(), recursive = TRUE) |
| 145 |
restore(packages = "toast") |
| 146 |
expect_length(list.files(paths$library()), 2L) |
| 147 |
expect_true(renv_package_installed("bread")) |
| 148 |
expect_true(renv_package_installed("toast")) |
| 149 |
}) |
| 150 |
|
| 151 |
test_that("restore ignores packages of incompatible architecture", { |
| 152 |
|
| 153 |
renv_tests_scope(c("unixonly", "windowsonly")) |
| 154 |
init() |
| 155 |
|
| 156 |
if (renv_platform_unix()) { |
| 157 |
|
| 158 |
expect_true(renv_package_installed("unixonly")) |
| 159 |
expect_false(renv_package_installed("windowsonly")) |
| 160 |
|
| 161 |
lockfile <- renv_lockfile_read("renv.lock") |
| 162 |
package <- lockfile$Packages$unixonly |
| 163 |
expect_identical(package$OS_type, "unix") |
| 164 |
|
| 165 |
remove("unixonly") |
| 166 |
restore() |
| 167 |
expect_true(renv_package_installed("unixonly")) |
| 168 |
|
| 169 |
} else { |
| 170 |
|
| 171 |
expect_true(renv_package_installed("windowsonly")) |
| 172 |
expect_false(renv_package_installed("unixonly")) |
| 173 |
|
| 174 |
lockfile <- renv_lockfile_read("renv.lock") |
| 175 |
package <- lockfile$Packages$windowsonly |
| 176 |
expect_identical(package$OS_type, "windows") |
| 177 |
|
| 178 |
remove("windowsonly") |
| 179 |
restore() |
| 180 |
expect_true(renv_package_installed("windowsonly")) |
| 181 |
|
| 182 |
} |
| 183 |
|
| 184 |
}) |
| 185 |
|
| 186 |
test_that("restore handled records without version set", { |
| 187 |
|
| 188 |
renv_tests_scope() |
| 189 |
|
| 190 |
# create dummy lockfile |
| 191 |
snapshot() |
| 192 |
|
| 193 |
# read lockfile and add record without version |
| 194 |
lockfile <- renv_lockfile_load(project = getwd()) |
| 195 |
lockfile$Packages$bread <- list(Package = "bread", Source = "Repository") |
| 196 |
renv_lockfile_save(lockfile, project = getwd()) |
| 197 |
|
| 198 |
# try to restore |
| 199 |
restore() |
| 200 |
|
| 201 |
# check for success |
| 202 |
expect_true(renv_package_installed("bread")) |
| 203 |
expect_equal(renv_package_version("bread"), "1.0.0") |
| 204 |
|
| 205 |
}) |
| 206 |
|
| 207 |
test_that("restore doesn't re-use active library paths", { |
| 208 |
|
| 209 |
renv_tests_scope() |
| 210 |
renv_scope_options(renv.settings.snapshot.type = "all") |
| 211 |
|
| 212 |
lib1 <- renv_scope_tempfile("lib1") |
| 213 |
lib2 <- renv_scope_tempfile("lib2") |
| 214 |
ensure_directory(c(lib1, lib2)) |
| 215 |
.libPaths(c(lib2, .libPaths())) |
| 216 |
|
| 217 |
install("bread", library = lib2) |
| 218 |
expect_true(renv_package_installed("bread", lib.loc = lib2)) |
| 219 |
|
| 220 |
lockfile <- snapshot(library = lib2, lockfile = NULL) |
| 221 |
restore(library = lib1, lockfile = lockfile) |
| 222 |
expect_true(renv_package_installed("bread", lib.loc = lib1)) |
| 223 |
|
| 224 |
}) |
| 225 |
|
| 226 |
test_that("restore(exclude = <...>) excludes as expected", { |
| 227 |
|
| 228 |
renv_tests_scope("breakfast") |
| 229 |
init() |
| 230 |
|
| 231 |
remove(c("bread", "breakfast", "oatmeal", "toast")) |
| 232 |
restore(exclude = "breakfast") |
| 233 |
expect_false(renv_package_installed("breakfast")) |
| 234 |
|
| 235 |
}) |
| 236 |
|
| 237 |
test_that("restore works with explicit Source", { |
| 238 |
|
| 239 |
renv_tests_scope("breakfast") |
| 240 |
init() |
| 241 |
|
| 242 |
renv_scope_envvars( |
| 243 |
RENV_PATHS_LOCAL = NULL, |
| 244 |
RENV_PATHS_CACHE = NULL |
| 245 |
) |
| 246 |
|
| 247 |
record <- list( |
| 248 |
Package = "skeleton", |
| 249 |
Version = "1.0.0", |
| 250 |
Source = renv_tests_path("local/skeleton/skeleton_1.0.0.tar.gz") |
| 251 |
) |
| 252 |
|
| 253 |
renv_test_retrieve(record) |
| 254 |
|
| 255 |
lockfile <- renv_lockfile_init(project = getwd()) |
| 256 |
lockfile$Packages <- list(skeleton = record) |
| 257 |
renv_lockfile_write(lockfile, file = "renv.lock") |
| 258 |
remove("skeleton") |
| 259 |
|
| 260 |
restore() |
| 261 |
|
| 262 |
expect_true(renv_package_installed("skeleton")) |
| 263 |
expect_true(renv_package_version("skeleton") == "1.0.0") |
| 264 |
|
| 265 |
}) |
| 266 |
|
| 267 |
test_that("restore() restores packages with broken symlinks", { |
| 268 |
|
| 269 |
skip_on_cran() |
| 270 |
renv_scope_options(renv.settings.cache.enabled = TRUE) |
| 271 |
renv_tests_scope("breakfast") |
| 272 |
init() |
| 273 |
|
| 274 |
# check it's installed |
| 275 |
pkgpath <- renv_package_find("breakfast") |
| 276 |
expect_true(renv_file_exists(pkgpath)) |
| 277 |
|
| 278 |
# break the cache |
| 279 |
record <- list(Package = "breakfast", Version = "1.0.0") |
| 280 |
cachepath <- renv_cache_find(record) |
| 281 |
unlink(cachepath, recursive = TRUE) |
| 282 |
|
| 283 |
# check that it's broken |
| 284 |
expect_true(renv_file_broken(pkgpath)) |
| 285 |
|
| 286 |
# try to restore |
| 287 |
restore() |
| 288 |
|
| 289 |
# check that we're happy again |
| 290 |
expect_false(renv_file_broken(pkgpath)) |
| 291 |
expect_true(renv_file_exists(pkgpath)) |
| 292 |
expect_true(renv_package_installed("breakfast")) |
| 293 |
|
| 294 |
}) |
| 295 |
|
| 296 |
test_that("restore() also installs packages with broken symlinks", { |
| 297 |
skip_on_cran() |
| 298 |
skip_on_os("windows") |
| 299 |
renv_scope_options(renv.settings.cache.enabled = TRUE) |
| 300 |
project <- renv_tests_scope("breakfast") |
| 301 |
init() |
| 302 |
|
| 303 |
pkgpaths <- list.files( |
| 304 |
path = renv_paths_library(project = project), |
| 305 |
full.names = TRUE |
| 306 |
) |
| 307 |
|
| 308 |
links <- Sys.readlink(pkgpaths) |
| 309 |
expect_true(all(nzchar(links))) |
| 310 |
|
| 311 |
unlink(links, recursive = TRUE) |
| 312 |
expect_false(renv_package_installed("breakfast")) |
| 313 |
|
| 314 |
restore() |
| 315 |
expect_true(renv_package_installed("breakfast")) |
| 316 |
}) |
| 317 |
|
| 318 |
test_that("we can restore a package installed with a custom repository", { |
| 319 |
|
| 320 |
project <- renv_tests_scope(isolated = TRUE) |
| 321 |
init() |
| 322 |
|
| 323 |
url <- unname(getOption("repos")) |
| 324 |
local({ |
| 325 |
renv_scope_options(repos = character()) |
| 326 |
install("bread", repos = c(TEST = url), rebuild = TRUE) |
| 327 |
}) |
| 328 |
|
| 329 |
dcf <- renv_description_read(package = "bread") |
| 330 |
expect_equal(!!dcf$RemoteRepos, !!url) |
| 331 |
expect_equal(!!dcf$RemoteReposName, "TEST") |
| 332 |
|
| 333 |
writeLines("library(bread)", con = "_deps.R") |
| 334 |
local({ |
| 335 |
renv_scope_options(repos = character()) |
| 336 |
snapshot() |
| 337 |
}) |
| 338 |
|
| 339 |
suppressMessages(remove.packages("bread")) |
| 340 |
local({ |
| 341 |
renv_scope_options(repos = character()) |
| 342 |
restore(rebuild = TRUE) |
| 343 |
}) |
| 344 |
|
| 345 |
expect_true(renv_package_installed("bread")) |
| 346 |
|
| 347 |
}) |
| 348 |
|
| 349 |
test_that("restore uses custom repository URL from lockfile", { |
| 350 |
|
| 351 |
project <- renv_tests_scope(isolated = TRUE) |
| 352 |
init() |
| 353 |
|
| 354 |
# install bread from a named custom repo, with no global repos set |
| 355 |
url <- unname(getOption("repos")) |
| 356 |
local({ |
| 357 |
renv_scope_options(repos = character()) |
| 358 |
install("bread", repos = c(TEST = url)) |
| 359 |
}) |
| 360 |
|
| 361 |
# snapshot with no global repos |
| 362 |
writeLines("library(bread)", con = "_deps.R") |
| 363 |
local({ |
| 364 |
renv_scope_options(repos = character()) |
| 365 |
snapshot() |
| 366 |
}) |
| 367 |
|
| 368 |
# check lockfile: no global repos, but package record has the custom URL |
| 369 |
lockfile <- renv_lockfile_read("renv.lock") |
| 370 |
expect_length(lockfile$R$Repositories, 0L) |
| 371 |
expect_equal(lockfile$Packages$bread$Repository, url) |
| 372 |
|
| 373 |
# remove the package and restore with no global repos |
| 374 |
suppressMessages(remove.packages("bread")) |
| 375 |
expect_false(renv_package_installed("bread")) |
| 376 |
|
| 377 |
local({ |
| 378 |
renv_scope_options(repos = character()) |
| 379 |
restore() |
| 380 |
}) |
| 381 |
|
| 382 |
expect_true(renv_package_installed("bread")) |
| 383 |
|
| 384 |
}) |
| 385 |
|
| 386 |
test_that("restore(strict = TRUE) uses only the recorded repository URL", { |
| 387 |
|
| 388 |
project <- renv_tests_scope(isolated = TRUE) |
| 389 |
init() |
| 390 |
|
| 391 |
# install bread from a named custom repo, with no global repos set |
| 392 |
url <- unname(getOption("repos")) |
| 393 |
local({ |
| 394 |
renv_scope_options(repos = character()) |
| 395 |
install("bread", repos = c(TEST = url)) |
| 396 |
}) |
| 397 |
|
| 398 |
# snapshot with no global repos |
| 399 |
writeLines("library(bread)", con = "_deps.R") |
| 400 |
local({ |
| 401 |
renv_scope_options(repos = character()) |
| 402 |
snapshot() |
| 403 |
}) |
| 404 |
|
| 405 |
# verify lockfile has the custom URL |
| 406 |
lockfile <- renv_lockfile_read("renv.lock") |
| 407 |
expect_equal(lockfile$Packages$bread$Repository, url) |
| 408 |
|
| 409 |
# remove the package |
| 410 |
suppressMessages(remove.packages("bread")) |
| 411 |
expect_false(renv_package_installed("bread")) |
| 412 |
|
| 413 |
# strict restore with the correct URL should succeed |
| 414 |
local({ |
| 415 |
renv_scope_options(repos = character()) |
| 416 |
restore(strict = TRUE) |
| 417 |
}) |
| 418 |
expect_true(renv_package_installed("bread")) |
| 419 |
|
| 420 |
# now simulate a bad repository URL in the lockfile; |
| 421 |
# disable the cache so we can verify the download path fails |
| 422 |
suppressMessages(remove.packages("bread")) |
| 423 |
lockfile$Packages$bread$Repository <- "file:///nonexistent/repo" |
| 424 |
renv_lockfile_write(lockfile, "renv.lock") |
| 425 |
|
| 426 |
# strict restore with a bad URL should fail |
| 427 |
local({ |
| 428 |
renv_scope_options(repos = character(), renv.config.cache.enabled = FALSE) |
| 429 |
expect_error(restore(strict = TRUE)) |
| 430 |
}) |
| 431 |
expect_false(renv_package_installed("bread")) |
| 432 |
|
| 433 |
}) |
| 434 |
|
| 435 |
test_that("restore(strict = FALSE) falls back when the recorded URL is bad", { |
| 436 |
|
| 437 |
renv_tests_scope("bread") |
| 438 |
init() |
| 439 |
|
| 440 |
# doctor the lockfile with a bogus URL-valued Repository |
| 441 |
lockfile <- renv_lockfile_read("renv.lock") |
| 442 |
lockfile$Packages$bread$Repository <- "file:///nonexistent/repo" |
| 443 |
renv_lockfile_write(lockfile, "renv.lock") |
| 444 |
|
| 445 |
# remove the package and restore with the real repo still available; |
| 446 |
# strict = FALSE (default) should fall back and succeed |
| 447 |
remove("bread") |
| 448 |
expect_false(renv_package_installed("bread")) |
| 449 |
|
| 450 |
restore() |
| 451 |
expect_true(renv_package_installed("bread")) |
| 452 |
|
| 453 |
}) |
| 454 |
|
| 455 |
test_that("restore(strict = TRUE) does not affect name-valued Repository fields", { |
| 456 |
|
| 457 |
renv_tests_scope("bread") |
| 458 |
init() |
| 459 |
|
| 460 |
# bread was installed from the test repo; its lockfile record should have |
| 461 |
# Repository = "CRAN" (a name, not a URL) |
| 462 |
lockfile <- renv_lockfile_read("renv.lock") |
| 463 |
expect_equal(lockfile$Packages$bread$Repository, "CRAN") |
| 464 |
|
| 465 |
# remove and strict-restore; name-valued Repository should resolve |
| 466 |
# through the configured repos as usual |
| 467 |
remove("bread") |
| 468 |
expect_false(renv_package_installed("bread")) |
| 469 |
|
| 470 |
restore(strict = TRUE) |
| 471 |
expect_true(renv_package_installed("bread")) |
| 472 |
|
| 473 |
}) |
| 474 |
|
| 475 |
test_that("restore(strict = TRUE) resolves dependencies from standard repos", { |
| 476 |
|
| 477 |
project <- renv_tests_scope(isolated = TRUE) |
| 478 |
init() |
| 479 |
|
| 480 |
# install toast (depends on bread) from a custom-named repo |
| 481 |
url <- unname(getOption("repos")) |
| 482 |
local({ |
| 483 |
renv_scope_options(repos = character()) |
| 484 |
install("toast", repos = c(TEST = url)) |
| 485 |
}) |
| 486 |
|
| 487 |
# snapshot with no global repos |
| 488 |
writeLines("library(toast)", con = "_deps.R") |
| 489 |
local({ |
| 490 |
renv_scope_options(repos = character()) |
| 491 |
snapshot() |
| 492 |
}) |
| 493 |
|
| 494 |
# verify toast has a URL-valued Repository; bread should too |
| 495 |
lockfile <- renv_lockfile_read("renv.lock") |
| 496 |
expect_equal(lockfile$Packages$toast$Repository, url) |
| 497 |
expect_equal(lockfile$Packages$bread$Repository, url) |
| 498 |
|
| 499 |
# remove both packages and strict-restore; |
| 500 |
# both should be retrieved from the recorded URL |
| 501 |
remove(c("toast", "bread")) |
| 502 |
expect_false(renv_package_installed("toast")) |
| 503 |
expect_false(renv_package_installed("bread")) |
| 504 |
|
| 505 |
local({ |
| 506 |
renv_scope_options(repos = character()) |
| 507 |
restore(strict = TRUE) |
| 508 |
}) |
| 509 |
|
| 510 |
expect_true(renv_package_installed("toast")) |
| 511 |
expect_true(renv_package_installed("bread")) |
| 512 |
|
| 513 |
}) |
| 514 |
|
| 515 |
test_that("restore(strict = TRUE) still works when repos.override is set", { |
| 516 |
|
| 517 |
skip_on_cran() |
| 518 |
skip_on_windows() |
| 519 |
|
| 520 |
renv_tests_scope("bread") |
| 521 |
init() |
| 522 |
|
| 523 |
# doctor the lockfile with a bogus URL-valued Repository |
| 524 |
lockfile <- renv_lockfile_read("renv.lock") |
| 525 |
lockfile$Packages$bread$Repository <- "file:///nonexistent/repo" |
| 526 |
renv_lockfile_write(lockfile, "renv.lock") |
| 527 |
|
| 528 |
# remove the package |
| 529 |
remove("bread") |
| 530 |
expect_false(renv_package_installed("bread")) |
| 531 |
|
| 532 |
# validate current behavior: repos.override nullifies the Repository |
| 533 |
# field before strict sees it, so restore succeeds |
| 534 |
renv_scope_options(renv.config.repos.override = getOption("repos")) |
| 535 |
restore(packages = "bread", strict = TRUE, rebuild = TRUE) |
| 536 |
expect_true(renv_package_installed("bread")) |
| 537 |
|
| 538 |
}) |
| 539 |
|
| 540 |
test_that("the Repository field in a lockfile can be overridden", { |
| 541 |
|
| 542 |
skip_on_cran() |
| 543 |
skip_on_windows() |
| 544 |
|
| 545 |
# initialize project |
| 546 |
project <- renv_tests_scope("bread") |
| 547 |
init() |
| 548 |
|
| 549 |
# simulate bread having an external / unexpected repository url |
| 550 |
lockfile <- renv_lockfile_read("renv.lock") |
| 551 |
lockfile$Packages$bread$Repository <- path.expand("~") |
| 552 |
renv_lockfile_write(lockfile, "renv.lock") |
| 553 |
|
| 554 |
# try to force a specific repository URL via override |
| 555 |
renv_scope_options(renv.config.repos.override = getOption("repos")) |
| 556 |
remove("bread") |
| 557 |
restore(packages = "bread", rebuild = TRUE) |
| 558 |
expect_true(renv_package_installed("bread")) |
| 559 |
|
| 560 |
}) |
| 561 |
|
| 562 |
test_that("restore(packages = ...) installs missing transitive dependencies", { |
| 563 |
skip_on_cran() |
| 564 |
renv_tests_scope("breakfast") |
| 565 |
init() |
| 566 |
|
| 567 |
remove("bread") |
| 568 |
expect_false(renv_package_installed("bread")) |
| 569 |
expect_true(renv_package_installed("toast")) |
| 570 |
|
| 571 |
restore(packages = "toast") |
| 572 |
|
| 573 |
expect_true(renv_package_installed("bread")) |
| 574 |
expect_true(renv_package_installed("toast")) |
| 575 |
}) |
| 576 |
|
| 577 |
test_that("restore(packages = ..., exclude = ...) excludes transitive deps", { |
| 578 |
skip_on_cran() |
| 579 |
renv_tests_scope("breakfast") |
| 580 |
init() |
| 581 |
|
| 582 |
remove("bread") |
| 583 |
expect_false(renv_package_installed("bread")) |
| 584 |
|
| 585 |
restore(packages = "toast", exclude = "bread") |
| 586 |
|
| 587 |
# bread should still be missing because it was excluded |
| 588 |
expect_false(renv_package_installed("bread")) |
| 589 |
}) |
| 590 |
|
| 591 |
test_that("restore(packages = ...) is a no-op for already-installed transitive deps", { |
| 592 |
skip_on_cran() |
| 593 |
renv_tests_scope("breakfast") |
| 594 |
init() |
| 595 |
|
| 596 |
# everything is already installed after init(); restore should succeed |
| 597 |
# without error and not reinstall anything |
| 598 |
expect_true(renv_package_installed("bread")) |
| 599 |
expect_true(renv_package_installed("toast")) |
| 600 |
|
| 601 |
restore(packages = "toast") |
| 602 |
|
| 603 |
expect_true(renv_package_installed("bread")) |
| 604 |
expect_true(renv_package_installed("toast")) |
| 605 |
}) |
| 606 |
|
| 607 |
test_that("restore(packages = ...) walks the full transitive closure", { |
| 608 |
skip_on_cran() |
| 609 |
renv_tests_scope("breakfast") |
| 610 |
init() |
| 611 |
|
| 612 |
# bread is two levels deep: breakfast -> toast -> bread |
| 613 |
remove("bread") |
| 614 |
expect_false(renv_package_installed("bread")) |
| 615 |
|
| 616 |
restore(packages = "breakfast") |
| 617 |
|
| 618 |
expect_true(renv_package_installed("bread")) |
| 619 |
expect_true(renv_package_installed("toast")) |
| 620 |
expect_true(renv_package_installed("breakfast")) |
| 621 |
}) |
| 622 |
|
| 623 |
test_that("restore(packages = ...) works for a leaf package with no deps", { |
| 624 |
skip_on_cran() |
| 625 |
renv_tests_scope("breakfast") |
| 626 |
init() |
| 627 |
|
| 628 |
remove("oatmeal") |
| 629 |
expect_false(renv_package_installed("oatmeal")) |
| 630 |
|
| 631 |
restore(packages = "oatmeal") |
| 632 |
|
| 633 |
expect_true(renv_package_installed("oatmeal")) |
| 634 |
}) |
| 635 |
|
| 636 |
test_that("restore(packages = ...) expands deps for multiple requested packages", { |
| 637 |
skip_on_cran() |
| 638 |
renv_tests_scope("breakfast") |
| 639 |
init() |
| 640 |
|
| 641 |
remove("bread") |
| 642 |
remove("oatmeal") |
| 643 |
expect_false(renv_package_installed("bread")) |
| 644 |
expect_false(renv_package_installed("oatmeal")) |
| 645 |
|
| 646 |
restore(packages = c("toast", "oatmeal")) |
| 647 |
|
| 648 |
expect_true(renv_package_installed("bread")) |
| 649 |
expect_true(renv_package_installed("toast")) |
| 650 |
expect_true(renv_package_installed("oatmeal")) |
| 651 |
}) |
| 652 |
|
| 653 |
test_that("renv_restore_recover installs latest versions of failed packages", { |
| 654 |
skip_on_cran() |
| 655 |
renv_tests_scope("bread") |
| 656 |
init() |
| 657 |
|
| 658 |
# remove bread to simulate a failed first pass |
| 659 |
remove.packages("bread", lib = renv_libpaths_active()) |
| 660 |
expect_false(renv_package_installed("bread")) |
| 661 |
|
| 662 |
# set up restore state as restore() would |
| 663 |
renv_scope_restore( |
| 664 |
project = getwd(), |
| 665 |
library = renv_libpaths_active(), |
| 666 |
records = list(bread = list(Package = "bread", Version = "1.0.0", Source = "Repository")), |
| 667 |
packages = "bread" |
| 668 |
) |
| 669 |
|
| 670 |
# recovery should install latest bread |
| 671 |
recovered <- renv_restore_recover("bread", getwd()) |
| 672 |
expect_true("bread" %in% names(recovered)) |
| 673 |
expect_true(renv_package_installed("bread")) |
| 674 |
}) |