| 1 |
|
| 2 |
# TODO: This test assumes 'pak' integration is disabled? |
| 3 |
test_that("install works when DESCRIPTION contains no dependencies", { |
| 4 |
renv_tests_scope() |
| 5 |
desc <- c("Type: Package", "Package: test", "Version: 1.0") |
| 6 |
writeLines(desc, con = "DESCRIPTION") |
| 7 |
expect_length(install(), 0L) |
| 8 |
}) |
| 9 |
|
| 10 |
test_that("requested version in DESCRIPTION file is honored", { |
| 11 |
|
| 12 |
renv_tests_scope() |
| 13 |
|
| 14 |
desc <- c( |
| 15 |
"Type: Package", |
| 16 |
"Package: test", |
| 17 |
"Imports: bread (== 0.1.0), toast" |
| 18 |
) |
| 19 |
writeLines(desc, con = "DESCRIPTION") |
| 20 |
|
| 21 |
install() |
| 22 |
expect_true(renv_package_version("bread") == "0.1.0") |
| 23 |
|
| 24 |
}) |
| 25 |
|
| 26 |
test_that("installation failure is well-reported", { |
| 27 |
|
| 28 |
# TODO: test seems to fail because a connection gets |
| 29 |
# left open by utils::package.skeleton() |
| 30 |
skip_on_os("windows") |
| 31 |
|
| 32 |
renv_scope_tempdir() |
| 33 |
|
| 34 |
# init dummy library |
| 35 |
library <- renv_scope_tempfile("renv-library-") |
| 36 |
ensure_directory(library) |
| 37 |
|
| 38 |
# dummy environment |
| 39 |
envir <- new.env(parent = emptyenv()) |
| 40 |
envir[["hello"]] <- function() {} |
| 41 |
|
| 42 |
# prepare dummy package |
| 43 |
package <- "renv.dummy.package" |
| 44 |
unlink(package, recursive = TRUE) |
| 45 |
suppressMessages(utils::package.skeleton(package, environment = envir)) |
| 46 |
|
| 47 |
# remove broken man files |
| 48 |
unlink("renv.dummy.package/Read-and-delete-me") |
| 49 |
unlink("renv.dummy.package/man", recursive = TRUE) |
| 50 |
|
| 51 |
# give the package a build-time error |
| 52 |
writeLines("parse error", con = file.path(package, "R/error.R")) |
| 53 |
|
| 54 |
# try to build it and confirm error |
| 55 |
record <- list(Package = package, Path = package) |
| 56 |
expect_error(renv_install_package_impl(record)) |
| 57 |
|
| 58 |
}) |
| 59 |
|
| 60 |
test_that("install forces update of dependencies as needed", { |
| 61 |
|
| 62 |
# TODO: this fails on CRAN presumedly because the wrong |
| 63 |
# version of the breakfast package is searched for; need |
| 64 |
# to figure out where the repositories are getting changed. |
| 65 |
skip_on_cran() |
| 66 |
renv_tests_scope("breakfast") |
| 67 |
|
| 68 |
# install the breakfast package |
| 69 |
install("breakfast") |
| 70 |
|
| 71 |
# ensure its dependencies were installed |
| 72 |
packages <- c("bread", "oatmeal", "toast") |
| 73 |
for (package in packages) |
| 74 |
expect_true(file.exists(renv_package_find(package))) |
| 75 |
|
| 76 |
# remove breakfast |
| 77 |
remove("breakfast") |
| 78 |
|
| 79 |
# modify 'toast' so that it's now too old |
| 80 |
path <- renv_package_find("toast") |
| 81 |
descpath <- file.path(path, "DESCRIPTION") |
| 82 |
desc <- renv_description_read(descpath) |
| 83 |
desc$Version <- "0.1.0" |
| 84 |
renv_dcf_write(desc, file = descpath) |
| 85 |
|
| 86 |
# try to install 'breakfast' again |
| 87 |
install("breakfast") |
| 88 |
|
| 89 |
# validate that 'toast' was updated to 1.0.0 |
| 90 |
desc <- renv_description_read(package = "toast") |
| 91 |
expect_equal(desc$Version, "1.0.0") |
| 92 |
|
| 93 |
}) |
| 94 |
|
| 95 |
test_that("packages can be installed from sources", { |
| 96 |
|
| 97 |
renv_scope_options(renv.config.cache.enabled = FALSE) |
| 98 |
|
| 99 |
project <- renv_tests_scope() |
| 100 |
init() |
| 101 |
|
| 102 |
# get path to package sources in local repos |
| 103 |
repos <- getOption("repos")[["CRAN"]] |
| 104 |
tarball <- file.path(repos, "src/contrib/bread_1.0.0.tar.gz") |
| 105 |
|
| 106 |
# try to install it |
| 107 |
install(tarball) |
| 108 |
expect_true(renv_package_version("bread") == "1.0.0") |
| 109 |
|
| 110 |
}) |
| 111 |
|
| 112 |
test_that("various remote styles can be used during install", { |
| 113 |
|
| 114 |
skip_on_cran() |
| 115 |
skip_if_no_github_auth() |
| 116 |
|
| 117 |
renv_tests_scope() |
| 118 |
init() |
| 119 |
|
| 120 |
# install CRAN latest |
| 121 |
install("bread") |
| 122 |
expect_true(renv_package_installed("bread")) |
| 123 |
expect_true(renv_package_version("bread") == "1.0.0") |
| 124 |
|
| 125 |
# install from archive |
| 126 |
install("[email protected]") |
| 127 |
expect_true(renv_package_installed("bread")) |
| 128 |
expect_true(renv_package_version("bread") == "0.1.0") |
| 129 |
|
| 130 |
# install from github |
| 131 |
install("kevinushey/skeleton") |
| 132 |
expect_true(renv_package_installed("skeleton")) |
| 133 |
expect_true(renv_package_version("skeleton") == "1.0.1") |
| 134 |
|
| 135 |
# install from github PR |
| 136 |
install("kevinushey/skeleton#1") |
| 137 |
expect_true(renv_package_installed("skeleton")) |
| 138 |
expect_true(renv_package_version("skeleton") == "1.0.2") |
| 139 |
|
| 140 |
# install from branch |
| 141 |
install("kevinushey/skeleton@feature/version-bump") |
| 142 |
expect_true(renv_package_installed("skeleton")) |
| 143 |
expect_true(renv_package_version("skeleton") == "1.0.2") |
| 144 |
|
| 145 |
# install from subdir |
| 146 |
install("kevinushey/subdir:subdir") |
| 147 |
expect_true(renv_package_installed("subdir")) |
| 148 |
expect_true(renv_package_version("subdir") == "0.0.0.9000") |
| 149 |
|
| 150 |
# install from URL to zip |
| 151 |
install("https://github.com/kevinushey/skeleton/archive/master.zip") |
| 152 |
expect_true(renv_package_installed("skeleton")) |
| 153 |
expect_true(renv_package_version("skeleton") == "1.0.1") |
| 154 |
|
| 155 |
}) |
| 156 |
|
| 157 |
test_that("Remotes fields in a project DESCRIPTION are respected", { |
| 158 |
|
| 159 |
skip_on_cran() |
| 160 |
skip_if_no_github_auth() |
| 161 |
|
| 162 |
renv_tests_scope() |
| 163 |
init() |
| 164 |
|
| 165 |
desc <- c( |
| 166 |
"Type: Package", |
| 167 |
"Package: renv.test.package", |
| 168 |
"Suggests: skeleton", |
| 169 |
"Remotes: kevinushey/skeleton" |
| 170 |
) |
| 171 |
|
| 172 |
writeLines(desc, con = "DESCRIPTION") |
| 173 |
install() |
| 174 |
|
| 175 |
record <- renv_snapshot_description(package = "skeleton") |
| 176 |
expect_true(record$Source == "GitHub") |
| 177 |
|
| 178 |
}) |
| 179 |
|
| 180 |
test_that("source packages in .zip files can be installed", { |
| 181 |
|
| 182 |
renv_tests_scope() |
| 183 |
|
| 184 |
location <- download.packages("bread", destdir = renv_scope_tempfile()) |
| 185 |
|
| 186 |
path <- location[1, 2] |
| 187 |
renv_archive_decompress(path, exdir = "bread") |
| 188 |
|
| 189 |
zippath <- file.path(getwd(), "bread_1.0.0.zip") |
| 190 |
setwd("bread") |
| 191 |
status <- catchall(zip(zippath, files = ".", extras = "-q")) |
| 192 |
setwd("..") |
| 193 |
|
| 194 |
if (inherits(status, "condition")) |
| 195 |
skip("could not zip archive") |
| 196 |
|
| 197 |
install(zippath) |
| 198 |
expect_true(renv_package_installed("bread")) |
| 199 |
|
| 200 |
}) |
| 201 |
|
| 202 |
test_that("renv warns when installing an already-loaded package", { |
| 203 |
skip_on_cran() |
| 204 |
renv_tests_scope() |
| 205 |
install("[email protected]") |
| 206 |
renv_namespace_load("bread") |
| 207 |
defer(renv_namespace_unload("bread")) |
| 208 |
|
| 209 |
expect_snapshot(install("[email protected]")) |
| 210 |
|
| 211 |
}) |
| 212 |
|
| 213 |
test_that("install() writes out Github fields for backwards compatibility", { |
| 214 |
|
| 215 |
skip_if_no_github_auth() |
| 216 |
renv_tests_scope() |
| 217 |
|
| 218 |
install("rstudio/packrat") |
| 219 |
descpath <- file.path(.libPaths()[1], "packrat/DESCRIPTION") |
| 220 |
dcf <- renv_description_read(descpath) |
| 221 |
|
| 222 |
expect_equal(dcf$RemoteRepo, dcf$GithubRepo) |
| 223 |
expect_equal(dcf$RemoteUsername, dcf$GithubUsername) |
| 224 |
expect_equal(dcf$RemoteRef, dcf$GithubRef) |
| 225 |
expect_equal(dcf$RemoteSha, dcf$GithubSHA1) |
| 226 |
|
| 227 |
}) |
| 228 |
|
| 229 |
test_that("renv uses safe library paths on Windows", { |
| 230 |
skip_if_not(renv_platform_windows()) |
| 231 |
renv_tests_scope() |
| 232 |
|
| 233 |
goodlib <- "Research and Development" |
| 234 |
expect_true(renv_libpaths_safe(goodlib) == goodlib) |
| 235 |
|
| 236 |
badlib <- "R&D" |
| 237 |
expect_false(renv_libpaths_safe(badlib) != badlib) |
| 238 |
|
| 239 |
ensure_directory(badlib) |
| 240 |
renv_libpaths_set(badlib) |
| 241 |
install("bread") |
| 242 |
|
| 243 |
descpath <- file.path(getwd(), "R&D/bread") |
| 244 |
desc <- renv_description_read(descpath) |
| 245 |
|
| 246 |
expect_true(desc$Package == "bread") |
| 247 |
expect_true(desc$Version == "1.0.0") |
| 248 |
|
| 249 |
}) |
| 250 |
|
| 251 |
test_that("renv uses safe library path when needed", { |
| 252 |
|
| 253 |
renv_tests_scope() |
| 254 |
|
| 255 |
badlib <- file.path(getwd(), "Has'Single'Quote") |
| 256 |
dir.create(badlib) |
| 257 |
expect_false(renv_libpaths_safe(badlib) == badlib) |
| 258 |
|
| 259 |
}) |
| 260 |
|
| 261 |
test_that("renv can install packages from Bitbucket", { |
| 262 |
skip_on_cran() |
| 263 |
renv_tests_scope() |
| 264 |
install("bitbucket::kevinushey/skeleton") |
| 265 |
expect_true(renv_package_installed("skeleton")) |
| 266 |
}) |
| 267 |
|
| 268 |
test_that("install via version succeeds", { |
| 269 |
skip_on_cran() |
| 270 |
renv_tests_scope() |
| 271 |
install("[email protected]") |
| 272 |
expect_true(renv_package_installed("bread")) |
| 273 |
expect_true(renv_package_version("bread") == "0.0.1") |
| 274 |
|
| 275 |
}) |
| 276 |
|
| 277 |
test_that("install() installs inferred dependencies", { |
| 278 |
|
| 279 |
skip_on_cran() |
| 280 |
renv_tests_scope("breakfast") |
| 281 |
|
| 282 |
# try installing packages |
| 283 |
records <- install() |
| 284 |
|
| 285 |
# validate that we've installed breakfast + deps |
| 286 |
expect_length(records, 4L) |
| 287 |
expect_true(renv_package_installed("breakfast")) |
| 288 |
|
| 289 |
# try calling install once more; nothing should happen |
| 290 |
records <- install() |
| 291 |
expect_length(records, 0L) |
| 292 |
|
| 293 |
}) |
| 294 |
|
| 295 |
test_that("install() prefers cellar when available", { |
| 296 |
|
| 297 |
skip_on_cran() |
| 298 |
renv_tests_scope() |
| 299 |
|
| 300 |
locals <- paste( |
| 301 |
renv_tests_path("nowhere"), |
| 302 |
renv_tests_path("local"), |
| 303 |
sep = ";" |
| 304 |
) |
| 305 |
|
| 306 |
renv_scope_options(renv.config.cache.enabled = FALSE) |
| 307 |
renv_scope_envvars(RENV_PATHS_CELLAR = locals) |
| 308 |
|
| 309 |
records <- install("skeleton") |
| 310 |
|
| 311 |
record <- records$skeleton |
| 312 |
expect_equal(record$Source, "Cellar") |
| 313 |
|
| 314 |
path <- renv_path_normalize(renv_tests_path("local/skeleton")) |
| 315 |
prefix <- if (renv_platform_windows()) "file:///" else "file://" |
| 316 |
uri <- paste0(prefix, path) |
| 317 |
|
| 318 |
expect_equal(attr(record, "url"), uri) |
| 319 |
|
| 320 |
}) |
| 321 |
|
| 322 |
test_that("packages can be installed from the archive w/libcurl", { |
| 323 |
skip_on_cran() |
| 324 |
|
| 325 |
# validate that we have libcurl |
| 326 |
ok <- identical(capabilities("libcurl"), c(libcurl = TRUE)) |
| 327 |
skip_if(!ok, "libcurl is not available") |
| 328 |
|
| 329 |
# perform test |
| 330 |
renv_tests_scope() |
| 331 |
renv_scope_envvars(RENV_DOWNLOAD_FILE_METHOD = "libcurl") |
| 332 |
install("[email protected]") |
| 333 |
expect_true(renv_package_installed("bread")) |
| 334 |
expect_equal(renv_package_version("bread"), "0.1.0") |
| 335 |
|
| 336 |
}) |
| 337 |
|
| 338 |
test_that("issue #609", { |
| 339 |
skip_on_cran() |
| 340 |
|
| 341 |
renv_tests_scope() |
| 342 |
|
| 343 |
renv_scope_options(configure.vars = c(breakfast = "")) |
| 344 |
install("bread") |
| 345 |
expect_true(renv_package_installed("bread")) |
| 346 |
}) |
| 347 |
|
| 348 |
test_that("we can install packages from git remotes within subdirs", { |
| 349 |
|
| 350 |
skip_on_cran() |
| 351 |
skip_on_ci() |
| 352 |
skip("unreliable test") |
| 353 |
|
| 354 |
renv_tests_scope("subdir") |
| 355 |
|
| 356 |
install("[email protected]:kevinushey/subdir.git:subdir", rebuild = TRUE) |
| 357 |
expect_true(renv_package_installed("subdir")) |
| 358 |
|
| 359 |
snapshot() |
| 360 |
|
| 361 |
remove("subdir") |
| 362 |
expect_false(renv_package_installed("subdir")) |
| 363 |
|
| 364 |
restore(packages = "subdir", rebuild = TRUE) |
| 365 |
expect_true(renv_package_installed("subdir")) |
| 366 |
|
| 367 |
}) |
| 368 |
|
| 369 |
test_that("packages embedded in the project use a project-local RemoteURL", { |
| 370 |
|
| 371 |
skip_if(getRversion() < "4.1") |
| 372 |
skip_if_not_installed("usethis") |
| 373 |
|
| 374 |
renv_tests_scope("example") |
| 375 |
|
| 376 |
usethis <- renv_namespace_load("usethis") |
| 377 |
skip_if(is.null(usethis$create_package)) |
| 378 |
renv_scope_options(usethis.quiet = TRUE) |
| 379 |
unlink("example", recursive = TRUE) |
| 380 |
|
| 381 |
fields <- list( |
| 382 |
"Authors@R" = utils::person( |
| 383 |
"Kevin", "Ushey", |
| 384 |
email = "[email protected]", |
| 385 |
role = c("aut", "cre"), |
| 386 |
comment = c(ORCID = "0000-0003-2880-7407") |
| 387 |
) |
| 388 |
) |
| 389 |
|
| 390 |
usethis$create_package("example", fields = fields, rstudio = FALSE, open = FALSE) |
| 391 |
|
| 392 |
install("./example") |
| 393 |
lockfile <- snapshot(lockfile = NULL) |
| 394 |
expect_equal(lockfile$Packages$example$RemoteUrl, "./example") |
| 395 |
|
| 396 |
# TODO: if the user provides a "weird" path, we'll use it as-is. |
| 397 |
# is that okay? what about relative paths that resolve outside of |
| 398 |
# the project root directory? |
| 399 |
install("./././example") |
| 400 |
lockfile <- snapshot(lockfile = NULL) |
| 401 |
expect_equal(lockfile$Packages$example$RemoteUrl, "./././example") |
| 402 |
|
| 403 |
}) |
| 404 |
|
| 405 |
test_that("packages installed from cellar via direct path", { |
| 406 |
|
| 407 |
skip_on_cran() |
| 408 |
renv_tests_scope("skeleton") |
| 409 |
|
| 410 |
locals <- paste( |
| 411 |
renv_tests_path("nowhere"), |
| 412 |
renv_tests_path("local"), |
| 413 |
sep = ";" |
| 414 |
) |
| 415 |
|
| 416 |
renv_scope_options(renv.config.cache.enabled = FALSE) |
| 417 |
renv_scope_envvars(RENV_PATHS_CELLAR = locals) |
| 418 |
|
| 419 |
path <- renv_tests_path("local/skeleton/skeleton_1.0.1.tar.gz") |
| 420 |
records <- install(path, rebuild = TRUE) |
| 421 |
expect_equal(records$skeleton$Source, "Cellar") |
| 422 |
|
| 423 |
lockfile <- snapshot(lockfile = NULL) |
| 424 |
expect_equal(lockfile$Packages$skeleton$Source, "Cellar") |
| 425 |
|
| 426 |
}) |
| 427 |
|
| 428 |
test_that("staging library path has same permissions as library path", { |
| 429 |
|
| 430 |
skip_on_cran() |
| 431 |
skip_on_windows() |
| 432 |
|
| 433 |
renv_tests_scope() |
| 434 |
|
| 435 |
library <- renv_paths_library() |
| 436 |
ensure_directory(library) |
| 437 |
renv_scope_libpaths(library) |
| 438 |
|
| 439 |
umask <- Sys.umask("0") |
| 440 |
Sys.chmod(library, "0775") |
| 441 |
Sys.umask(umask) |
| 442 |
|
| 443 |
staging <- renv_install_staged_library_path() |
| 444 |
expect_equal(file.mode(staging), file.mode(library)) |
| 445 |
|
| 446 |
}) |
| 447 |
|
| 448 |
test_that("packages installed from a RemoteSubdir can be retrieved from cache", { |
| 449 |
|
| 450 |
skip_on_windows() |
| 451 |
skip_slow() |
| 452 |
|
| 453 |
renv_tests_scope() |
| 454 |
cachepath <- renv_scope_tempfile("renv-cache-") |
| 455 |
ensure_directory(cachepath) |
| 456 |
renv_scope_envvars(RENV_PATHS_CACHE = cachepath) |
| 457 |
|
| 458 |
init() |
| 459 |
|
| 460 |
# install first from remote |
| 461 |
install("kevinushey/subdir:subdir") |
| 462 |
|
| 463 |
# remove, and re-install from cache |
| 464 |
remove("subdir") |
| 465 |
install("kevinushey/subdir:subdir") |
| 466 |
|
| 467 |
expect_true(renv_package_installed("subdir")) |
| 468 |
|
| 469 |
}) |
| 470 |
|
| 471 |
test_that("repositories containing multiple packages can be installed", { |
| 472 |
|
| 473 |
skip_on_windows() |
| 474 |
skip_slow() |
| 475 |
|
| 476 |
renv_tests_scope() |
| 477 |
|
| 478 |
install("kevinushey/subdir:pkgA") |
| 479 |
expect_true(renv_package_installed("pkgA")) |
| 480 |
|
| 481 |
install("kevinushey/subdir:pkgB") |
| 482 |
expect_true(renv_package_installed("pkgB")) |
| 483 |
|
| 484 |
}) |
| 485 |
|
| 486 |
test_that("Suggest dependencies are used when requested", { |
| 487 |
|
| 488 |
renv_tests_scope("breakfast") |
| 489 |
fields <- c("Imports", "Depends", "LinkingTo", "Suggests") |
| 490 |
settings$package.dependency.fields(fields) |
| 491 |
install("breakfast") |
| 492 |
expect_true(renv_package_installed("egg")) |
| 493 |
|
| 494 |
}) |
| 495 |
|
| 496 |
test_that("custom dependency fields in install are supported", { |
| 497 |
|
| 498 |
skip_on_cran() |
| 499 |
skip_on_windows() |
| 500 |
|
| 501 |
renv_tests_scope() |
| 502 |
|
| 503 |
install("breakfast", dependencies = "strong") |
| 504 |
expect_false(renv_package_installed("egg")) |
| 505 |
|
| 506 |
install("breakfast", dependencies = c("strong", "Config/Needs/protein")) |
| 507 |
expect_true(renv_package_installed("egg")) |
| 508 |
}) |
| 509 |
|
| 510 |
test_that("install has user-friendly output", { |
| 511 |
|
| 512 |
renv_scope_libpaths() |
| 513 |
renv_scope_envvars(RENV_PATHS_CACHE = renv_scope_tempfile("renv-tempcache-")) |
| 514 |
|
| 515 |
# sort status lines so snapshot is stable regardless of |
| 516 |
# completion order (socket-based collection is nondeterministic) |
| 517 |
transform <- function(x) { |
| 518 |
x <- strip_dirs(x) |
| 519 |
status <- grepl("\x1b\\[3[12]m", x) |
| 520 |
runs <- rle(status) |
| 521 |
pos <- 1L |
| 522 |
for (i in seq_along(runs$lengths)) { |
| 523 |
len <- runs$lengths[[i]] |
| 524 |
idx <- seq(pos, length.out = len) |
| 525 |
if (runs$values[[i]]) |
| 526 |
x[idx] <- sort(x[idx]) |
| 527 |
pos <- pos + len |
| 528 |
} |
| 529 |
x |
| 530 |
} |
| 531 |
|
| 532 |
renv_tests_scope("breakfast") |
| 533 |
expect_snapshot(install(), transform = transform) |
| 534 |
|
| 535 |
renv_tests_scope("breakfast") |
| 536 |
expect_snapshot(install(), transform = transform) |
| 537 |
|
| 538 |
}) |
| 539 |
|
| 540 |
test_that("package sources of the form <pkg>_<sha>.zip can be installed", { |
| 541 |
skip_on_cran() |
| 542 |
skip_if(!renv_platform_windows()) |
| 543 |
|
| 544 |
renv_tests_scope() |
| 545 |
renv_tests_scope_repos() |
| 546 |
|
| 547 |
# get path to .tar.gz |
| 548 |
source <- download.packages("bread", type = "source")[1, 2] |
| 549 |
|
| 550 |
# repack as a .zip archive |
| 551 |
exdir <- renv_scope_tempfile("bread-") |
| 552 |
ensure_directory(exdir) |
| 553 |
renv_archive_decompress(source, exdir = exdir) |
| 554 |
|
| 555 |
zipfile <- file.path(tempdir(), "bread_f96a78e23d44d68d329c2dbf168a4dee1882a1c6.zip") |
| 556 |
local({ |
| 557 |
renv_scope_wd(exdir) |
| 558 |
zip(zipfile, files = "bread") |
| 559 |
}) |
| 560 |
|
| 561 |
# now try to install it |
| 562 |
install(zipfile) |
| 563 |
expect_true(renv_package_installed("bread")) |
| 564 |
|
| 565 |
}) |
| 566 |
|
| 567 |
test_that("package binaries of the form <pkg>_<sha>.zip can be installed", { |
| 568 |
skip_on_cran() |
| 569 |
skip_if(!renv_platform_windows()) |
| 570 |
|
| 571 |
renv_tests_scope() |
| 572 |
renv_tests_scope_repos() |
| 573 |
|
| 574 |
# install bread |
| 575 |
install("bread") |
| 576 |
|
| 577 |
# create a zipfile from the installed package |
| 578 |
library <- renv_libpaths_active() |
| 579 |
zipfile <- file.path(tempdir(), "bread_f96a78e23d44d68d329c2dbf168a4dee1882a1c6.zip") |
| 580 |
local({ |
| 581 |
renv_scope_wd(library) |
| 582 |
zip(zipfile, files = "bread", extras = "-q") |
| 583 |
}) |
| 584 |
|
| 585 |
# remove bread |
| 586 |
remove("bread") |
| 587 |
expect_false(renv_package_installed("bread")) |
| 588 |
|
| 589 |
# now try to install from zipfile |
| 590 |
install(zipfile) |
| 591 |
expect_true(renv_package_installed("bread")) |
| 592 |
|
| 593 |
}) |
| 594 |
|
| 595 |
test_that("install() reports failure when a 'bad' binary is installed", { |
| 596 |
|
| 597 |
skip_on_cran() |
| 598 |
renv_tests_scope() |
| 599 |
|
| 600 |
# test package load in this scope on all platforms |
| 601 |
renv_scope_envvars(RENV_INSTALL_TEST_LOAD = TRUE) |
| 602 |
|
| 603 |
# install bread |
| 604 |
install("bread") |
| 605 |
|
| 606 |
# copy the installed package, and create a 'broken' binary |
| 607 |
src <- renv_package_find("bread") |
| 608 |
tgt <- file.path(tempdir(), "bread") |
| 609 |
renv_file_copy(src, tgt) |
| 610 |
|
| 611 |
local({ |
| 612 |
renv_scope_wd(tgt) |
| 613 |
dir.create("R") |
| 614 |
writeLines("stop('oh no')", con = "R/bread") |
| 615 |
}) |
| 616 |
|
| 617 |
# try installing the broken binary |
| 618 |
remove("bread") |
| 619 |
expect_false(renv_package_installed("bread")) |
| 620 |
expect_error(install(tgt)) |
| 621 |
expect_false(renv_package_installed("bread")) |
| 622 |
|
| 623 |
# try skipping the load test |
| 624 |
renv_scope_options(INSTALL_opts = c(bread = "--no-test-load")) |
| 625 |
install(tgt) |
| 626 |
expect_true(renv_package_installed("bread")) |
| 627 |
expect_error(renv_namespace_load(bread)) |
| 628 |
remove("bread") |
| 629 |
|
| 630 |
}) |
| 631 |
|
| 632 |
test_that("install() respects dependencies argument", { |
| 633 |
skip_on_cran() |
| 634 |
project <- renv_tests_scope() |
| 635 |
init() |
| 636 |
|
| 637 |
contents <- heredoc(" |
| 638 |
Type: Project |
| 639 |
Depends: coffee |
| 640 |
Imports: bread |
| 641 |
Suggests: muffin |
| 642 |
") |
| 643 |
|
| 644 |
writeLines(contents, con = "DESCRIPTION") |
| 645 |
install(dependencies = "Imports") |
| 646 |
|
| 647 |
expect_true(renv_package_installed("bread")) |
| 648 |
expect_false(renv_package_installed("coffee")) |
| 649 |
expect_false(renv_package_installed("muffin")) |
| 650 |
}) |
| 651 |
|
| 652 |
test_that("install() succeeds even some repositories cannot be queried", { |
| 653 |
renv_tests_scope() |
| 654 |
|
| 655 |
repos <- getOption("repos") |
| 656 |
repos[["NARC"]] <- file.path(repos[["CRAN"]], "missing") |
| 657 |
renv_scope_options(repos = repos) |
| 658 |
|
| 659 |
init() |
| 660 |
install("bread") |
| 661 |
expect_true(renv_package_installed("bread")) |
| 662 |
}) |
| 663 |
|
| 664 |
test_that("install() doesn't duplicate authentication headers", { |
| 665 |
|
| 666 |
skip_on_cran() |
| 667 |
skip_if_no_github_auth() |
| 668 |
|
| 669 |
renv_scope_envvars(RENV_DOWNLOAD_METHOD = "libcurl") |
| 670 |
project <- renv_tests_scope() |
| 671 |
init() |
| 672 |
install("kevinushey/skeleton") |
| 673 |
expect_true(renv_package_installed("skeleton")) |
| 674 |
|
| 675 |
}) |
| 676 |
|
| 677 |
test_that("install() stores repository information for installed packages", { |
| 678 |
|
| 679 |
project <- renv_tests_scope(isolated = TRUE) |
| 680 |
init() |
| 681 |
|
| 682 |
# unset repository option |
| 683 |
repos <- getOption("repos") |
| 684 |
renv_scope_options(repos = character()) |
| 685 |
|
| 686 |
# try to install a package |
| 687 |
writeLines("library(bread)", con = "_deps.R") |
| 688 |
install("bread", repos = c(TEST = unname(repos))) |
| 689 |
|
| 690 |
# create a lockfile |
| 691 |
snapshot() |
| 692 |
|
| 693 |
# validate that the repository information is stored |
| 694 |
lockfile <- renv_lockfile_read("renv.lock") |
| 695 |
record <- lockfile$Packages$bread |
| 696 |
expect_equal(!!record$Source, "Repository") |
| 697 |
expect_equal(!!record$Repository, !!unname(repos)) |
| 698 |
|
| 699 |
# now, add the repository back; it should then be aliased in lockfile |
| 700 |
options(repos = c(TEST = unname(repos))) |
| 701 |
snapshot() |
| 702 |
|
| 703 |
lockfile <- renv_lockfile_read("renv.lock") |
| 704 |
record <- lockfile$Packages$bread |
| 705 |
expect_equal(!!record$Source, "Repository") |
| 706 |
expect_equal(!!record$Repository, "TEST") |
| 707 |
|
| 708 |
}) |
| 709 |
|
| 710 |
test_that("install() lazily resolves project remotes", { |
| 711 |
|
| 712 |
skip_on_cran() |
| 713 |
skip_if_no_github_auth() |
| 714 |
|
| 715 |
project <- renv_tests_scope() |
| 716 |
init() |
| 717 |
|
| 718 |
writeLines("Remotes: kevinushey/skeleton", con = "DESCRIPTION") |
| 719 |
install("bread") |
| 720 |
expect_false(renv_package_installed("skeleton")) |
| 721 |
|
| 722 |
}) |
| 723 |
|
| 724 |
# https://github.com/rstudio/renv/issues/2271 |
| 725 |
test_that("install() resolves named remotes in DESCRIPTION", { |
| 726 |
|
| 727 |
skip_on_cran() |
| 728 |
skip_if_no_github_auth() |
| 729 |
|
| 730 |
renv_tests_scope() |
| 731 |
|
| 732 |
desc <- c( |
| 733 |
"Type: Package", |
| 734 |
"Package: test", |
| 735 |
"Imports: skeleton", |
| 736 |
"Remotes: skeleton=kevinushey/skeleton" |
| 737 |
) |
| 738 |
writeLines(desc, con = "DESCRIPTION") |
| 739 |
|
| 740 |
init(bare = TRUE) |
| 741 |
install() |
| 742 |
expect_true(renv_package_installed("skeleton")) |
| 743 |
|
| 744 |
}) |
| 745 |
|
| 746 |
test_that("install() records the repository used to retrieve a package", { |
| 747 |
|
| 748 |
project <- renv_tests_scope(isolated = TRUE) |
| 749 |
init() |
| 750 |
|
| 751 |
url <- unname(getOption("repos")) |
| 752 |
local({ |
| 753 |
renv_scope_options(repos = character()) |
| 754 |
install("bread", repos = c(TEST = url), rebuild = TRUE) |
| 755 |
}) |
| 756 |
|
| 757 |
dcf <- renv_description_read(package = "bread") |
| 758 |
expect_equal(!!dcf$RemoteRepos, !!url) |
| 759 |
expect_equal(!!dcf$RemoteReposName, "TEST") |
| 760 |
|
| 761 |
}) |
| 762 |
|
| 763 |
test_that("recursive dependency versions are properly resolved", { |
| 764 |
|
| 765 |
project <- renv_tests_scope() |
| 766 |
init() |
| 767 |
|
| 768 |
install("[email protected]") |
| 769 |
install("jamie") |
| 770 |
|
| 771 |
expect_equal(renv_package_version("phone"), "1.0.0") |
| 772 |
|
| 773 |
}) |
| 774 |
|
| 775 |
test_that("install(lock = TRUE) updates lockfile", { |
| 776 |
|
| 777 |
project <- renv_tests_scope() |
| 778 |
init() |
| 779 |
|
| 780 |
# first, get a lockfile as created via install + lock |
| 781 |
install("breakfast", lock = TRUE) |
| 782 |
actual <- renv_lockfile_load(project = project) |
| 783 |
|
| 784 |
# now, try re-computing the lockfile via snapshot |
| 785 |
writeLines("library(breakfast)", con = "dependencies.R") |
| 786 |
expected <- snapshot(lockfile = NULL) |
| 787 |
|
| 788 |
# make sure they're equal |
| 789 |
expect_mapequal( |
| 790 |
renv_lockfile_records(actual), |
| 791 |
renv_lockfile_records(expected) |
| 792 |
) |
| 793 |
|
| 794 |
}) |
| 795 |
|
| 796 |
test_that("installation of package from local sources works", { |
| 797 |
|
| 798 |
project <- renv_tests_scope() |
| 799 |
renv_scope_options(renv.config.cache.enabled = FALSE) |
| 800 |
|
| 801 |
# test the shim |
| 802 |
repopath <- renv_tests_repopath() |
| 803 |
setwd(file.path(repopath, "src/contrib")) |
| 804 |
renv_shim_install_packages("bread_1.0.0.tar.gz", repos = NULL, type = "source") |
| 805 |
expect_true(renv_package_installed("bread")) |
| 806 |
|
| 807 |
# test a regular invocation of install |
| 808 |
suppressMessages(remove.packages("bread")) |
| 809 |
info <- download.packages("bread", destdir = tempdir()) |
| 810 |
install(info[, 2], repos = NULL, type = "source") |
| 811 |
expect_true(renv_package_installed("bread")) |
| 812 |
|
| 813 |
}) |
| 814 |
|
| 815 |
test_that("packages installed from r-universe preserve their remote metadata", { |
| 816 |
|
| 817 |
skip_on_cran() |
| 818 |
skip_on_ci() |
| 819 |
|
| 820 |
project <- renv_tests_scope(packages = "rlang") |
| 821 |
install("rlang", repos = "https://r-lib.r-universe.dev", rebuild = TRUE) |
| 822 |
pkgpath <- find.package("rlang", lib.loc = .libPaths()) |
| 823 |
record <- renv_snapshot_description(pkgpath) |
| 824 |
expect_true(is.character(record[["RemoteSha"]])) |
| 825 |
|
| 826 |
}) |
| 827 |
|
| 828 |
# https://github.com/rstudio/renv/issues/2071 |
| 829 |
test_that("irrelevant R version requirements don't prevent package installation", { |
| 830 |
|
| 831 |
renv_tests_scope() |
| 832 |
init() |
| 833 |
|
| 834 |
# package in repository not compatible with this version of R |
| 835 |
expect_error(install("today")) |
| 836 |
|
| 837 |
# but older version can be successfully installed |
| 838 |
install("[email protected]") |
| 839 |
expect_true(renv_package_installed("today")) |
| 840 |
expect_equal(renv_package_version("today"), "0.1.0") |
| 841 |
|
| 842 |
# other packages can be installed even if this project depends on it |
| 843 |
writeLines("Depends: future, today", con = "DESCRIPTION") |
| 844 |
install("future") |
| 845 |
expect_true(renv_package_installed("future")) |
| 846 |
remove("future") |
| 847 |
|
| 848 |
# but installing that package should still fail |
| 849 |
expect_error(install("today")) |
| 850 |
|
| 851 |
}) |
| 852 |
|
| 853 |
test_that("the remotes field in a package's DESCRIPTION is honoured", { |
| 854 |
|
| 855 |
skip_on_cran() |
| 856 |
skip_if_no_github_auth() |
| 857 |
|
| 858 |
renv_tests_scope("halloween") |
| 859 |
repopath <- renv_tests_repopath() |
| 860 |
pkgpath <- file.path(repopath, "src/contrib/halloween_1.0.0.tar.gz") |
| 861 |
install(pkgpath) |
| 862 |
|
| 863 |
expect_true(renv_package_installed("halloween")) |
| 864 |
expect_true(renv_package_installed("skeleton")) |
| 865 |
|
| 866 |
skeleton <- renv_description_read(package = "skeleton") |
| 867 |
expect_equal(skeleton$RemoteUsername, "kevinushey") |
| 868 |
expect_equal(skeleton$RemoteRepo, "skeleton") |
| 869 |
|
| 870 |
}) |
| 871 |
|
| 872 |
# https://github.com/rstudio/renv/issues/2251 |
| 873 |
test_that("install() report doesn't crash when a package has no version", { |
| 874 |
|
| 875 |
renv_tests_scope("missing") |
| 876 |
init(bare = TRUE) |
| 877 |
expect_snapshot(install(), error = TRUE) |
| 878 |
|
| 879 |
}) |
| 880 |
|
| 881 |
test_that("install from local sources shows progress", { |
| 882 |
|
| 883 |
renv_tests_scope() |
| 884 |
init(bare = TRUE) |
| 885 |
path <- renv_tests_path("packages/bread") |
| 886 |
expect_snapshot(install(path)) |
| 887 |
|
| 888 |
}) |