Debian Codegraph @

tests/testthat/test-repos.R

raw
1
2 test_that("we can query our local repository during tests", {
3
4 expected <- list.files("packages")
5 drop <- c("today", if (.Platform$OS.type == "unix") "windowsonly" else "unixonly")
6 expected <- setdiff(expected, drop)
7
8 renv_tests_scope()
9 ap <- available_packages(type = "source")[[1]]
10 expect_setequal(ap$Package, expected)
11
12 })
13
14 test_that("repository names are not lost in the lockfile", {
15
16 url <- "https://cloud.r-project.org"
17 renv_scope_options(repos = c(Example = url))
18 lockfile <- renv_lockfile_init(project = getwd())
19 expect_equal(lockfile$R$Repositories, list(Example = url))
20
21 })
22
23 test_that("trailing slashes are removed from repositories on load", {
24 renv_scope_options(repos = NULL)
25 renv_load_r_repos(list(CRAN = "https://cloud.r-project.org/"))
26 expect_equal(getOption("repos"), c(CRAN = "https://cloud.r-project.org"))
27 })
28
29 test_that("renv emits an error if repos option is malformed", {
30 renv_tests_scope()
31
32 # disallow malformed repos
33 expect_error(snapshot(repos = 1))
34
35 # disallow unnamed repositories
36 expect_error(snapshot(repos = c("a", "b")))
37
38 # allow zero-length repos
39 lockfile <- snapshot(repos = NULL, lockfile = NULL)
40 expect_true(empty(lockfile$R$Repositories))
41
42 # explicitly allow single unnamed repository
43 lockfile <- snapshot(repos = "https://cloud.r-project.org", lockfile = NULL)
44 expect_equal(lockfile$R$Repositories, list(CRAN = "https://cloud.r-project.org"))
45
46 # allow custom named repositories
47 repos <- list(
48 CRAN = "https://cran.rstudio.com",
49 RSPM = "https://packagemanager.rstudio.com/all/latest"
50 )
51
52 lockfile <- snapshot(repos = repos, lockfile = NULL)
53 expect_equal(lockfile$R$Repositories, repos)
54
55 })
56
57 test_that("renv_repos_baseurl strips contrib.url suffixes", {
58
59 expect_equal(
60 renv_repos_baseurl("https://cloud.r-project.org/src/contrib"),
61 "https://cloud.r-project.org"
62 )
63
64 expect_equal(
65 renv_repos_baseurl("https://cloud.r-project.org/bin/macosx/big-sur-arm64/contrib/4.4"),
66 "https://cloud.r-project.org"
67 )
68
69 expect_equal(
70 renv_repos_baseurl("https://cloud.r-project.org/bin/windows/contrib/4.4"),
71 "https://cloud.r-project.org"
72 )
73
74 })
75
76 test_that("repository names are always set", {
77
78 skip_on_cran()
79 renv_tests_scope()
80
81 repos <- c(
82 CRAN = "https://cran.r-project.org",
83 PPM = "https://packagemanager.posit.co",
84 "https://renv.github.io/drat"
85 )
86
87 expected <- c(
88 CRAN = "https://cran.r-project.org",
89 PPM = "https://packagemanager.posit.co",
90 "https://renv.github.io/drat" = "https://renv.github.io/drat"
91 )
92
93 actual <- renv_repos_normalize(repos)
94 expect_equal(actual, expected)
95
96 })
97