| 1 |
|
| 2 |
test_that("we can repair a broken project library", { |
| 3 |
|
| 4 |
skip_on_cran() |
| 5 |
renv_tests_scope("breakfast") |
| 6 |
|
| 7 |
init() |
| 8 |
|
| 9 |
# find breakfast in the cache, and delete it |
| 10 |
record <- list(Package = "breakfast", Version = "1.0.0") |
| 11 |
cachepath <- renv_cache_find(record) |
| 12 |
unlink(cachepath, recursive = TRUE) |
| 13 |
|
| 14 |
# check that the package no longer exists |
| 15 |
expect_false(renv_package_installed("breakfast")) |
| 16 |
|
| 17 |
# try to repair |
| 18 |
repair() |
| 19 |
|
| 20 |
# validate that we reinstalled it |
| 21 |
expect_true(renv_package_installed("breakfast")) |
| 22 |
|
| 23 |
}) |
| 24 |
|
| 25 |
test_that("repair() uses the package version recorded in the lockfile", { |
| 26 |
|
| 27 |
skip_on_cran() |
| 28 |
renv_tests_scope("breakfast") |
| 29 |
|
| 30 |
init() |
| 31 |
|
| 32 |
# install older breakfast from archive |
| 33 |
install("[email protected]") |
| 34 |
snapshot() |
| 35 |
|
| 36 |
# find breakfast in the cache, and delete it |
| 37 |
record <- list(Package = "breakfast", Version = "0.1.0") |
| 38 |
cachepath <- renv_cache_find(record) |
| 39 |
unlink(cachepath, recursive = TRUE) |
| 40 |
|
| 41 |
# check that the package no longer exists |
| 42 |
expect_false(renv_package_installed("breakfast")) |
| 43 |
|
| 44 |
# try to repair |
| 45 |
repair() |
| 46 |
|
| 47 |
# validate that we reinstalled it |
| 48 |
expect_true(renv_package_installed("breakfast")) |
| 49 |
expect_true(renv_package_version("breakfast") == "0.1.0") |
| 50 |
|
| 51 |
}) |
| 52 |
|
| 53 |
test_that("repair() can update DESCRIPTION files for GitHub packages", { |
| 54 |
|
| 55 |
skip_on_cran() |
| 56 |
renv_tests_scope("skeleton") |
| 57 |
renv_scope_local() |
| 58 |
renv_scope_options(renv.config.cache.symlinks = FALSE) |
| 59 |
init() |
| 60 |
|
| 61 |
# mutate the installed package DESCRIPTION file, so that it appears |
| 62 |
# to be from GitHub |
| 63 |
descpath <- system.file("DESCRIPTION", package = "skeleton") |
| 64 |
desc <- renv_description_read(descpath) |
| 65 |
desc$Repository <- NULL |
| 66 |
desc$BugReports <- "https://github.com/kevinushey/skeleton/issues" |
| 67 |
renv_dcf_write(desc, file = descpath) |
| 68 |
|
| 69 |
metapath <- system.file("Meta/package.rds", package = "skeleton") |
| 70 |
meta <- readRDS(metapath) |
| 71 |
meta$DESCRIPTION <- desc |
| 72 |
saveRDS(meta, file = metapath) |
| 73 |
|
| 74 |
# try to repair, but cancel the request |
| 75 |
renv_scope_options(renv.menu.choice = 2L) |
| 76 |
expect_snapshot(. <- repair(), error = TRUE) |
| 77 |
|
| 78 |
}) |