Debian Codegraph @

tests/testthat/test-retrieve.R

raw
1
2 test_that("we can retrieve packages from CRAN", {
3
4 skip_slow()
5
6 renv_tests_scope()
7
8 record <- list(
9 Package = "oatmeal",
10 Version = "1.0.0",
11 Source = "CRAN"
12 )
13
14 renv_test_retrieve(record)
15
16 })
17
18 test_that("we can retrieve packages from the CRAN archive", {
19
20 skip_slow()
21
22 renv_tests_scope()
23
24 record <- list(
25 Package = "bread",
26 Version = "0.1.0",
27 Source = "CRAN"
28 )
29
30 renv_test_retrieve(record)
31
32 })
33
34 test_that("packages with an unknown source are retrieved from CRAN", {
35
36 skip_slow()
37
38 renv_tests_scope()
39
40 record <- list(
41 Package = "bread",
42 Version = "0.1.0",
43 Source = "unknown"
44 )
45
46 renv_test_retrieve(record)
47
48 })
49
50 test_that("we can retrieve packages from Bitbucket", {
51
52 skip_on_cran()
53 skip("unreliable test")
54
55 record <- list(
56 Package = "skeleton",
57 Source = "bitbucket",
58 RemoteRepo = "skeleton",
59 RemoteUsername = "kevinushey",
60 RemoteSha = "958296dbbbf7f1d82f7f5dd1b121c7558604809f"
61 )
62
63 renv_test_retrieve(record)
64
65 })
66
67
68 test_that("we can retrieve packages from git", {
69
70 skip_on_cran()
71 skip("unreliable test")
72
73 record <- list(
74 Package = "skeleton",
75 Source = "git",
76 RemoteUrl = "git://github.com/kevinushey/skeleton.git",
77 RemoteSha = "958296dbbbf7f1d82f7f5dd1b121c7558604809f"
78 )
79
80 renv_test_retrieve(record)
81
82 })
83
84 test_that("we can retrieve packages with git dependencies", {
85 skip_on_cran()
86 skip_slow()
87
88 # GitHub doesn't like ssh (used as remote field in renv.git1)
89 skip_on_ci()
90
91 record <- list(
92 Package = "renv.git1",
93 Source = "git",
94 RemoteUrl = "https://github.com/kevinushey/renv.git1",
95 RemoteRef = "main"
96 )
97
98 renv_test_retrieve(record)
99 })
100
101
102 test_that("we can retrieve packages from GitHub", {
103
104 skip_slow()
105
106 record <- list(
107 Package = "skeleton",
108 Source = "github",
109 RemoteUsername = "kevinushey",
110 RemoteRepo = "skeleton",
111 RemoteSha = "958296dbbbf7f1d82f7f5dd1b121c7558604809f"
112 )
113
114 renv_test_retrieve(record)
115
116 })
117
118 test_that("we can retrieve packages from GitHub (in a sub-directory)", {
119
120 skip_slow()
121
122 record <- list(
123 Package = "subdir",
124 Source = "github",
125 RemoteUsername = "kevinushey",
126 RemoteRepo = "subdir",
127 RemoteSubdir = "subdir",
128 RemoteSha = "100373b23c8adae1da4e4d6995402d40e9227cfb"
129 )
130
131 renv_test_retrieve(record)
132
133 })
134
135
136 test_that("we can retrieve packages from GitLab", {
137
138 skip_slow()
139
140 record <- list(
141 Package = "skeleton",
142 Source = "gitlab",
143 RemoteUsername = "kevinushey",
144 RemoteRepo = "skeleton",
145 RemoteSha = "958296dbbbf7f1d82f7f5dd1b121c7558604809f"
146 )
147
148 renv_test_retrieve(record)
149
150 })
151
152 test_that("we can retrieve packages with URLs", {
153 skip_slow()
154 url <- "https://api.github.com/repos/kevinushey/skeleton/tarball"
155 record <- renv_remotes_resolve(url)
156 renv_test_retrieve(record)
157 })
158
159 test_that("we can retrieve packages from URL sources", {
160
161 skip_slow()
162
163 renv_tests_scope()
164 renv_scope_local()
165
166 record <- list(
167 Package = "skeleton",
168 Version = "1.0.1",
169 Source = "URL",
170 RemoteType = "url",
171 RemoteUrl = "https://api.github.com/repos/kevinushey/skeleton/tarball"
172 )
173
174 renv_test_retrieve(record)
175
176 })
177
178 test_that("we can retrieve packages from local sources", {
179
180 renv_tests_scope()
181 renv_scope_local()
182
183 record <- list(
184 Package = "skeleton",
185 Version = "1.0.1",
186 Source = "local"
187 )
188
189 renv_test_retrieve(record)
190
191 })
192
193 test_that("compatible local sources are preferred when available", {
194
195 renv_tests_scope()
196 renv_scope_local()
197
198 record <- list(
199 Package = "skeleton",
200 Version = "1.0.1",
201 Source = "CRAN"
202 )
203
204 renv_test_retrieve(record)
205
206 record <- list(
207 Package = "skeleton",
208 Version = "1.0.1",
209 Source = "unknown"
210 )
211
212 renv_test_retrieve(record)
213
214 })
215
216 test_that("an explicitly-provided local source path can be used", {
217
218 renv_tests_scope()
219 renv_scope_local()
220
221 source <- renv_tests_path("local/skeleton/skeleton_1.0.1.tar.gz")
222 renv_scope_wd(tempdir())
223
224 record <- list(
225 Package = "skeleton",
226 Version = "1.0.1",
227 Source = source
228 )
229
230 renv_test_retrieve(record)
231
232 })
233
234
235
236 test_that("explicit path to binary packages work", {
237
238 skip_if_not(renv_platform_macos())
239
240 renv_tests_scope()
241 renv_scope_local()
242
243 # make sure we have a binary package in the cellar to test with
244 srcpath <- renv_tests_path("local/skeleton/skeleton_1.0.1.tar.gz")
245 binpath <- renv_tests_path("local/skeleton/skeleton_1.0.1.tgz")
246 defer(unlink(binpath))
247
248 # create the binary
249 local({
250 renv_scope_wd(dirname(srcpath))
251 args <- c("CMD", "INSTALL", "--build", basename(srcpath))
252 renv_system_exec(R(), args)
253 })
254
255 record <- list(
256 Package = "skeleton",
257 Version = "1.0.1",
258 Source = binpath
259 )
260
261 renv_test_retrieve(record)
262
263 })
264
265 test_that("remotes::install_local() records are handled", {
266
267 renv_scope_envvars(RENV_PATHS_LOCAL = NULL)
268
269 record <- list(
270 Package = "skeleton",
271 Version = "1.0.1",
272 Source = "local",
273 RemoteUrl = renv_tests_path("local/skeleton/skeleton_1.0.1.tar.gz")
274 )
275
276 renv_test_retrieve(record)
277
278 })
279
280 test_that("we can retrieve packages from GitHub", {
281
282 skip_slow()
283
284 record <- list(
285 Package = "skeleton",
286 Source = "github",
287 RemoteHost = "https://api.github.com",
288 RemoteUsername = "kevinushey",
289 RemoteRepo = "skeleton",
290 RemoteSha = "958296dbbbf7f1d82f7f5dd1b121c7558604809f"
291 )
292
293 renv_test_retrieve(record)
294
295 })
296
297 test_that("we can retrieve packages from R repositories", {
298
299 skip_on_cran()
300 renv_tests_scope()
301
302 record <- list(
303 Package = "oatmeal",
304 Version = "1.0.0",
305 Source = "Repository",
306 Repository = "CRAN"
307 )
308
309 renv_test_retrieve(record)
310
311 })
312
313 test_that("we can retrieve files using file URIs", {
314
315 skip_on_cran()
316 renv_tests_scope()
317
318 source <- file.path(getwd(), "source")
319 target <- file.path(getwd(), "target")
320
321 writeLines("Hello, world!", con = source)
322
323 # plain 'file:' URI with no authority
324 uri <- paste("file:", source, sep = "")
325 download(uri, destfile = target)
326 expect_equal(readLines(target), "Hello, world!")
327 unlink(target)
328
329 # file URI using empty authority
330 prefix <- if (renv_platform_windows()) "file:///" else "file://"
331 uri <- paste(prefix, source, sep = "")
332 download(uri, destfile = target)
333 expect_equal(readLines(target), "Hello, world!")
334 unlink(target)
335
336 })
337
338 test_that("records with RemoteSha successfully retrieved from archives", {
339
340 renv_tests_scope()
341
342 record <- list(
343 Package = "bread",
344 Version = "0.1.0",
345 Source = "Repository",
346 RemoteSha = "oops"
347 )
348
349 renv_test_retrieve(record)
350
351 })
352
353 test_that("we respect the default branch for gitlab repositories", {
354 skip_on_cran()
355 remote <- renv_remotes_resolve("gitlab::kevinushey/main")
356 expect_equal(remote$RemoteRef, "main")
357 })
358
359 test_that("renv can retrieve the latest release associated with a project", {
360 skip_if_no_github_auth()
361
362 remote <- renv_remotes_resolve("rstudio/keras@*release")
363 expect_true(is.list(remote))
364 })
365
366 test_that("retrieve handles local sources", {
367 skip_on_cran()
368
369 renv_tests_scope()
370 renv_scope_options(renv.config.cache.enabled = FALSE)
371
372 record <- list(
373 Package = "bread",
374 Version = "1.0.0",
375 Source = "bread_1.0.0.tar.gz"
376 )
377
378 expect_error(renv_test_retrieve(record))
379
380 # call download.packages once to get URL
381 url <- download.packages("bread", destdir = getwd())
382 if (!file.exists(record$Source))
383 file.copy(url[1, 2], record$Source)
384
385 renv_test_retrieve(record)
386
387 })
388
389 test_that("explicitly local packages fall back to repository sources", {
390
391 renv_tests_scope()
392 renv_scope_options(renv.config.cache.enabled = FALSE)
393
394 record <- list(
395 Package = "bread",
396 Version = "1.0.0",
397 Source = "Local"
398 )
399
400 renv_test_retrieve(record)
401
402 })
403
404 test_that("we can use retrieve() to download packages without installing", {
405 project <- renv_tests_scope()
406 init()
407
408 result <- retrieve(packages = "breakfast")
409 expect_false(renv_package_installed("breakfast"))
410 expect_contains(names(result), "breakfast")
411 expect_contains(names(result), "bread")
412
413 result <- retrieve(packages = "bread", destdir = ".")
414 expect_equal(result, c(bread = "./bread_1.0.0.tar.gz"))
415
416 install("bread")
417 result <- retrieve(packages = "bread", destdir = ".")
418 expect_equal(result, c(bread = "./bread_1.0.0.tar.gz"))
419
420 })
421
422 test_that("renv_retrieve_libpaths_impl reuses a compatible installed package", {
423
424 # https://github.com/rstudio/renv/issues/2288 — the built-version check used
425 # to compare a version string to TRUE, which always failed, so the user /
426 # site library shortcut never fired and renv would needlessly download.
427 renv_tests_scope()
428
429 # install bread 1.0.0 into a temporary "user library"
430 userlib <- renv_scope_tempfile("renv-userlib-")
431 ensure_directory(userlib)
432 install("bread", library = userlib)
433
434 # set up restore state so renv_retrieve_successful() has somewhere to record
435 templib <- renv_scope_tempfile("renv-library-")
436 ensure_directory(templib)
437 renv_scope_libpaths(c(templib, .libPaths()))
438
439 record <- list(
440 Package = "bread",
441 Version = "1.0.0",
442 Source = "Repository",
443 Repository = "CRAN"
444 )
445
446 renv_scope_restore(
447 project = getwd(),
448 library = templib,
449 records = list(bread = record),
450 packages = "bread",
451 recursive = TRUE
452 )
453
454 expect_true(renv_retrieve_libpaths_impl(record, userlib))
455
456 state <- renv_restore_state()
457 expect_true(state$install$contains("bread"))
458 expect_equal(state$install$get("bread")$Path, file.path(userlib, "bread"))
459
460 })
461
462 test_that("renv_retrieve_libpaths_impl rejects packages built for a different R version", {
463
464 renv_tests_scope()
465
466 # the file-backed DESCRIPTION cache would otherwise return the original
467 # Built field after we mutate the file below
468 renv_scope_options(renv.config.filebacked.cache = FALSE)
469
470 userlib <- renv_scope_tempfile("renv-userlib-")
471 ensure_directory(userlib)
472 install("bread", library = userlib)
473
474 # rewrite the Built field to claim an R version we definitely aren't using
475 descpath <- file.path(userlib, "bread", "DESCRIPTION")
476 text <- readLines(descpath)
477 text <- sub("^Built: R [0-9.]+", "Built: R 0.0.0", text)
478 writeLines(text, descpath)
479
480 templib <- renv_scope_tempfile("renv-library-")
481 ensure_directory(templib)
482 renv_scope_libpaths(c(templib, .libPaths()))
483
484 record <- list(
485 Package = "bread",
486 Version = "1.0.0",
487 Source = "Repository",
488 Repository = "CRAN"
489 )
490
491 renv_scope_restore(
492 project = getwd(),
493 library = templib,
494 records = list(bread = record),
495 packages = "bread",
496 recursive = TRUE
497 )
498
499 expect_false(renv_retrieve_libpaths_impl(record, userlib))
500
501 })