| 1 |
|
| 2 |
test_that("we can bootstrap the current version of renv", { |
| 3 |
|
| 4 |
skip_on_cran() |
| 5 |
skip_on_ci() |
| 6 |
|
| 7 |
renv_tests_scope() |
| 8 |
|
| 9 |
library <- renv_libpaths_active() |
| 10 |
bootstrap(version = "1.0.0", library = library) |
| 11 |
expect_true(renv_package_installed("renv", library)) |
| 12 |
expect_true(renv_package_version("renv") == "1.0.0") |
| 13 |
|
| 14 |
}) |
| 15 |
|
| 16 |
test_that("we can bootstrap an archived version of renv", { |
| 17 |
|
| 18 |
skip_on_cran() |
| 19 |
skip_on_ci() |
| 20 |
|
| 21 |
renv_tests_scope() |
| 22 |
|
| 23 |
library <- renv_libpaths_active() |
| 24 |
bootstrap(version = "0.1.0", library = library) |
| 25 |
expect_true(renv_package_installed("renv", library)) |
| 26 |
expect_true(renv_package_version("renv") == "0.1.0") |
| 27 |
|
| 28 |
}) |
| 29 |
|
| 30 |
test_that("we can install a version of renv with a sha", { |
| 31 |
|
| 32 |
skip_on_cran() |
| 33 |
skip_on_ci() |
| 34 |
skip_if_no_github_auth() |
| 35 |
|
| 36 |
renv_tests_scope() |
| 37 |
|
| 38 |
version <- structure("0.17.3-62", sha = "5049cef8a") |
| 39 |
library <- renv_libpaths_active() |
| 40 |
bootstrap(version = version, library = library) |
| 41 |
expect_true(renv_package_installed("renv", library)) |
| 42 |
|
| 43 |
desc <- utils::packageDescription("renv", library) |
| 44 |
expect_equal(desc$RemoteType, "github") |
| 45 |
expect_equal(desc$RemotePkgRef, "rstudio/renv") |
| 46 |
expect_equal(desc$RemoteSha, "5049cef8a94591b802f9766a0da092780f59f7e4") |
| 47 |
}) |
| 48 |
|
| 49 |
test_that("bootstrap functions don't depend on non-bootstrap APIs", { |
| 50 |
|
| 51 |
# pattern matching things that are bootstrapped for renv |
| 52 |
pattern <- "^renv_(?:bootstrap|json|options|remote)_" |
| 53 |
|
| 54 |
# get all of the bootstrap functions defined in renv |
| 55 |
renv <- asNamespace("renv") |
| 56 |
keys <- grep(pattern, ls(envir = renv), value = TRUE) |
| 57 |
fns <- mget(keys, envir = renv, mode = "function") |
| 58 |
bodies <- map(fns, body) |
| 59 |
|
| 60 |
# iterate over those functions and look for the called functions |
| 61 |
calls <- stack(mode = "character") |
| 62 |
recurse(bodies, function(node) { |
| 63 |
if (is.call(node) && is.symbol(node[[1L]])) |
| 64 |
calls$push(as.character(node[[1L]])) |
| 65 |
}) |
| 66 |
calls <- calls$data() |
| 67 |
|
| 68 |
# check what renv APIs are used |
| 69 |
apis <- grep("^renv_", calls, value = TRUE) |
| 70 |
|
| 71 |
# validate they're all available |
| 72 |
bad <- grep(pattern, apis, value = TRUE, invert = TRUE) |
| 73 |
expect_true(length(bad) == 0, info = paste("Functions:", bad, collapse = ", ")) |
| 74 |
|
| 75 |
}) |
| 76 |
|
| 77 |
test_that("bootstrapping functions standalone", { |
| 78 |
|
| 79 |
renv_tests_scope() |
| 80 |
|
| 81 |
# get all bootstrap APIs in package |
| 82 |
renv <- asNamespace("renv") |
| 83 |
keys <- ls(envir = renv, pattern = "^renv_bootstrap_", all.names = TRUE) |
| 84 |
vals <- mget(c("catf", "%||%", "header", "bootstrap", keys), envir = renv) |
| 85 |
|
| 86 |
# put those into a separate environment inheriting only from base, and |
| 87 |
# re-mark those as inheriting from base (so they only 'see' each-other) |
| 88 |
envir <- new.env(parent = baseenv()) |
| 89 |
for (i in seq_along(vals)) |
| 90 |
environment(vals[[i]]) <- envir |
| 91 |
list2env(vals, envir = envir) |
| 92 |
|
| 93 |
# set up library path |
| 94 |
library <- renv_scope_tempfile("renv-library-") |
| 95 |
ensure_directory(library) |
| 96 |
|
| 97 |
# try running 'sandboxed' version of bootstrap |
| 98 |
run <- function(version) { |
| 99 |
|
| 100 |
# construct bootstrap call |
| 101 |
code <- call("bootstrap", version = version, library = library) |
| 102 |
|
| 103 |
# run that call |
| 104 |
eval(code, envir = envir) |
| 105 |
|
| 106 |
# validate that renv was successfully installed |
| 107 |
expect_true(renv_package_installed("renv", lib.loc = library)) |
| 108 |
|
| 109 |
# validate that the correct version was installed |
| 110 |
descpath <- file.path(library, "renv/DESCRIPTION") |
| 111 |
desc <- renv_description_read(path = descpath) |
| 112 |
expect_identical(desc$Package, "renv") |
| 113 |
expect_identical(desc$Version, version) |
| 114 |
|
| 115 |
} |
| 116 |
|
| 117 |
# current on CRAN (test repository version) |
| 118 |
run("1.0.0") |
| 119 |
|
| 120 |
# in the CRAN archive (test repository version) |
| 121 |
run("0.1.0") |
| 122 |
|
| 123 |
}) |
| 124 |
|
| 125 |
test_that("bootstrapping gives informative output when succesful", { |
| 126 |
|
| 127 |
scope <- environment() |
| 128 |
local_mocked_bindings( |
| 129 |
|
| 130 |
renv_bootstrap_download_impl = function(url, destfile) { |
| 131 |
file.create(destfile) |
| 132 |
defer(unlink(destfile), scope = scope) |
| 133 |
0L |
| 134 |
}, |
| 135 |
|
| 136 |
renv_bootstrap_install_impl = function(cmd, args, ...) { |
| 137 |
structure("", status = 0L) |
| 138 |
}, |
| 139 |
|
| 140 |
renv_bootstrap_download_cran_latest_find = function(version) { |
| 141 |
if (package_version(version) < "1.0.0") { |
| 142 |
list(type = "binary", repos = "https://cran.rstudio.com") |
| 143 |
} |
| 144 |
}, |
| 145 |
|
| 146 |
load = function(...) invisible() |
| 147 |
|
| 148 |
) |
| 149 |
|
| 150 |
renv_scope_options(renv.bootstrap.quiet = FALSE) |
| 151 |
library <- renv_scope_tempfile() |
| 152 |
|
| 153 |
renv_tests_scope() |
| 154 |
expect_snapshot({ |
| 155 |
bootstrap(version = "0.9.0", library = library) |
| 156 |
bootstrap(version = "1.0.0", library = library) |
| 157 |
bootstrap(version = "1.0.0.1", library = library) |
| 158 |
}) |
| 159 |
}) |
| 160 |
|
| 161 |
test_that("bootstrapping gives informative output when download fails", { |
| 162 |
|
| 163 |
local_mocked_bindings( |
| 164 |
renv_bootstrap_download_impl = function(...) { |
| 165 |
stop("test failure") |
| 166 |
}, |
| 167 |
renv_bootstrap_download_cran_latest_find = function(version) { |
| 168 |
if (package_version(version) < "1.0.0") { |
| 169 |
list(type = "binary", repos = "https://cran.rstudio.com") |
| 170 |
} |
| 171 |
} |
| 172 |
) |
| 173 |
|
| 174 |
renv_scope_options(renv.bootstrap.quiet = FALSE) |
| 175 |
library <- renv_scope_tempfile() |
| 176 |
|
| 177 |
renv_tests_scope() |
| 178 |
expect_snapshot(error = TRUE, { |
| 179 |
bootstrap(version = "0.9.0", library = library) |
| 180 |
bootstrap(version = "1.0.0", library = library) |
| 181 |
bootstrap(version = "1.0.0.1", library = library) |
| 182 |
}) |
| 183 |
|
| 184 |
}) |
| 185 |
|
| 186 |
test_that("bootstrapping gives informative output when install fails", { |
| 187 |
|
| 188 |
local_mocked_bindings( |
| 189 |
renv_bootstrap_download_impl = function(url, destfile) { |
| 190 |
file.create(destfile) |
| 191 |
0L |
| 192 |
}, |
| 193 |
renv_bootstrap_install_impl = function(...) { |
| 194 |
structure("test failure", status = 123L) |
| 195 |
} |
| 196 |
) |
| 197 |
|
| 198 |
renv_scope_options(renv.bootstrap.quiet = FALSE) |
| 199 |
library <- renv_scope_tempfile() |
| 200 |
|
| 201 |
renv_tests_scope() |
| 202 |
expect_snapshot(error = TRUE, { |
| 203 |
bootstrap(version = "1.0.0.1", library = library) |
| 204 |
}) |
| 205 |
|
| 206 |
}) |
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
# helpers ----------------------------------------------------------------- |
| 211 |
|
| 212 |
test_that("renv_boostrap_version_validate() recognises when versions are the same", { |
| 213 |
|
| 214 |
expect_true( |
| 215 |
renv_bootstrap_validate_version( |
| 216 |
version = structure("1.2.3", sha = "abcd123"), |
| 217 |
description = list(RemoteSha = "abcd1234567") |
| 218 |
) |
| 219 |
) |
| 220 |
|
| 221 |
expect_true( |
| 222 |
renv_bootstrap_validate_version( |
| 223 |
version = "1.2.3", |
| 224 |
description = list(Version = "1.2.3") |
| 225 |
) |
| 226 |
) |
| 227 |
|
| 228 |
}) |
| 229 |
|
| 230 |
|
| 231 |
test_that("renv_boostrap_version_validate() gives good warnings", { |
| 232 |
renv_scope_options(renv.bootstrap.quiet = FALSE) |
| 233 |
|
| 234 |
expect_snapshot({ |
| 235 |
|
| 236 |
# out-of-sync (request release; have different release) |
| 237 |
. <- renv_bootstrap_validate_version( |
| 238 |
version = "1.2.3", |
| 239 |
description = list(Version = "2.3.4") |
| 240 |
) |
| 241 |
|
| 242 |
# out-of-sync (request dev; have release) |
| 243 |
. <- renv_bootstrap_validate_version( |
| 244 |
version = "1.2.3-1", |
| 245 |
description = list(Version = "1.2.3") |
| 246 |
) |
| 247 |
|
| 248 |
# out-of-sync (request dev; have different dev) |
| 249 |
. <- renv_bootstrap_validate_version( |
| 250 |
version = structure("1.2.3-1", sha = "22d015905828c3398728a5ff9e381e0433976263"), |
| 251 |
description = list( |
| 252 |
Version = "1.2.3-1", |
| 253 |
RemoteType = "github", |
| 254 |
RemoteSha = "6b09befaaba3f55e0e2c141cb45c5d247b61ef1e" |
| 255 |
) |
| 256 |
) |
| 257 |
|
| 258 |
# out-of-sync (request dev; have release) |
| 259 |
. <- renv_bootstrap_validate_version( |
| 260 |
version = structure("1.2.3-1", sha = "22d015905828c3398728a5ff9e381e0433976263"), |
| 261 |
description = list( |
| 262 |
Version = "1.2.3" |
| 263 |
) |
| 264 |
) |
| 265 |
|
| 266 |
}) |
| 267 |
|
| 268 |
}) |
| 269 |
|
| 270 |
test_that("bootstrap version validation handles 'standard' remote types", { |
| 271 |
|
| 272 |
renv_scope_options(renv.bootstrap.quiet = FALSE) |
| 273 |
expect_snapshot( |
| 274 |
|
| 275 |
. <- renv_bootstrap_validate_version( |
| 276 |
version = "1.0.0", |
| 277 |
description = list( |
| 278 |
Version = "1.0.1", |
| 279 |
RemoteType = "standard", |
| 280 |
RemoteSha = "1.0.1" |
| 281 |
) |
| 282 |
) |
| 283 |
|
| 284 |
) |
| 285 |
|
| 286 |
}) |
| 287 |
|
| 288 |
test_that("version validation warnings are suppressed by RENV_CONFIG_STARTUP_QUIET", { |
| 289 |
|
| 290 |
# https://github.com/rstudio/renv/issues/2214 |
| 291 |
renv_scope_options(renv.bootstrap.quiet = FALSE) |
| 292 |
renv_scope_envvars(RENV_CONFIG_STARTUP_QUIET = "TRUE") |
| 293 |
|
| 294 |
expect_silent( |
| 295 |
renv_bootstrap_validate_version( |
| 296 |
version = "1.2.3", |
| 297 |
description = list(Version = "2.3.4") |
| 298 |
) |
| 299 |
) |
| 300 |
|
| 301 |
}) |
| 302 |
|
| 303 |
test_that("version validation warnings are suppressed by RENV_CONFIG_SYNCHRONIZED_CHECK=FALSE", { |
| 304 |
|
| 305 |
# https://github.com/rstudio/renv/issues/2214 |
| 306 |
renv_scope_options(renv.bootstrap.quiet = FALSE) |
| 307 |
renv_scope_envvars(RENV_CONFIG_SYNCHRONIZED_CHECK = "FALSE") |
| 308 |
|
| 309 |
expect_silent( |
| 310 |
renv_bootstrap_validate_version( |
| 311 |
version = "1.2.3", |
| 312 |
description = list(Version = "2.3.4") |
| 313 |
) |
| 314 |
) |
| 315 |
|
| 316 |
}) |
| 317 |
|
| 318 |
# repos override tests ---------------------------------------------------- |
| 319 |
|
| 320 |
test_that("repos override supports unnamed repo", { |
| 321 |
renv_tests_scope() |
| 322 |
url <- "https://p3m.dev/cran/latest" |
| 323 |
renv_scope_envvars(RENV_CONFIG_REPOS_OVERRIDE = url) |
| 324 |
repos <- renv_bootstrap_repos() |
| 325 |
expect_true(url %in% repos) |
| 326 |
}) |
| 327 |
|
| 328 |
test_that("repos override can use 1 named repository", { |
| 329 |
renv_tests_scope() |
| 330 |
override <- "CRAN=https://p3m.dev/cran/latest" |
| 331 |
renv_scope_envvars(RENV_CONFIG_REPOS_OVERRIDE = override) |
| 332 |
repos <- renv_bootstrap_repos() |
| 333 |
expect_equal(repos["CRAN"], c(CRAN = "https://p3m.dev/cran/latest")) |
| 334 |
}) |
| 335 |
|
| 336 |
test_that("repos override can use 2+ named repositories", { |
| 337 |
renv_tests_scope() |
| 338 |
override <- "CRAN=https://p3m.dev/cran/latest;R_UNIV=https://posit-dev.r-universe.dev" |
| 339 |
renv_scope_envvars(RENV_CONFIG_REPOS_OVERRIDE = override) |
| 340 |
repos <- renv_bootstrap_repos() |
| 341 |
expect_equal(repos["CRAN"], c(CRAN = "https://p3m.dev/cran/latest")) |
| 342 |
expect_equal(repos["R_UNIV"], c(R_UNIV = "https://posit-dev.r-universe.dev")) |
| 343 |
expect_equal(length(repos), 2L) |
| 344 |
}) |
| 345 |
|
| 346 |
test_that("repos override can handle `=` in repo urls", { |
| 347 |
renv_tests_scope() |
| 348 |
override <- "R_UNIV=https://posit-dev.r-universe.dev/?example=query" |
| 349 |
renv_scope_envvars(RENV_CONFIG_REPOS_OVERRIDE = override) |
| 350 |
repos <- renv_bootstrap_repos() |
| 351 |
expect_equal(repos["R_UNIV"], c(R_UNIV = "https://posit-dev.r-universe.dev/?example=query")) |
| 352 |
}) |
| 353 |
|
| 354 |
test_that("repos override handle paths", { |
| 355 |
renv_tests_scope() |
| 356 |
override <- "CRAN=https://p3m.dev/cran/__linux__/noble/latest" |
| 357 |
renv_scope_envvars(RENV_CONFIG_REPOS_OVERRIDE = override) |
| 358 |
repos <- renv_bootstrap_repos() |
| 359 |
expect_equal(repos["CRAN"], c(CRAN = "https://p3m.dev/cran/__linux__/noble/latest")) |
| 360 |
}) |