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