Debian Codegraph @

tests/testthat/test-config.R

raw
1
2 test_that("config variables read from appropriate scope", {
3
4 local({
5 renv_scope_options(renv.config.test = "hello")
6 expect_equal(renv_config_get("test"), "hello")
7 })
8
9 local({
10 renv_scope_envvars(RENV_CONFIG_TEST = "hello")
11 expect_equal(renv_config_get("test"), "hello")
12 })
13
14 })
15
16 test_that("invalid configuration options are reported", {
17
18 local({
19 renv_scope_options(renv.config.test = "apple")
20 expect_warning(renv_config_get("test", type = "integer[1]"))
21 })
22
23 })
24
25 test_that("values are coerced as appropriate", {
26
27 local({
28 renv_scope_options(renv.config.test = 1)
29 expect_identical(renv_config_get("test", type = "numeric[1]"), 1)
30 expect_identical(renv_config_get("test", type = "integer[1]"), 1L)
31 expect_identical(renv_config_get("test", type = "logical[1]"), TRUE)
32 })
33
34 local({
35 renv_scope_options(renv.config.test = 0)
36 expect_identical(renv_config_get("test", type = "numeric[1]"), 0)
37 expect_identical(renv_config_get("test", type = "integer[1]"), 0L)
38 expect_identical(renv_config_get("test", type = "logical[1]"), FALSE)
39 })
40
41 })
42
43 test_that("functions are returned as-is for '*' types", {
44
45 local({
46 helper <- function() {}
47 renv_scope_options(renv.config.helper = helper)
48 value <- renv_config_get("helper", type = "*")
49 expect_identical(value, helper)
50 })
51
52 })
53
54 test_that("we can query options without warnings", {
55
56 local({
57 renv_scope_envvars(RENV_CONFIG_EXTERNAL_LIBRARIES = "/tmp")
58 expect_identical(config$external.libraries(), "/tmp")
59 })
60
61 })
62
63 test_that("invalid configuration options trigger a warning", {
64
65 local({
66 renv_scope_options(renv.config.connect.timeout = "oops")
67 expect_warning(config$connect.timeout())
68 })
69
70 })
71
72 test_that("we can query the default configuration values without issue", {
73
74 for (key in names(config))
75 config[[key]]()
76
77 expect_true(TRUE)
78
79 })
80
81 test_that("multiple library paths can be set in RENV_CONFIG_EXTERNAL_LIBRARIES", {
82
83 renv_scope_envvars(RENV_CONFIG_EXTERNAL_LIBRARIES = "/a:/b:/c")
84 libpaths <- config$external.libraries()
85 expect_equal(libpaths, c("/a", "/b", "/c"))
86
87 })
88
89 test_that("cache symlinks are disabled if the cache and project library lie in different volumes", {
90
91 skip_on_cran()
92 skip_if(renv_platform_unix())
93
94 project <- renv_tests_scope()
95
96 renv_scope_envvars(RENV_PATHS_CACHE = "//network/drive")
97 expect_false(renv_cache_config_symlinks(project = project))
98
99 projlib <- renv_paths_library(project = project)
100 renv_scope_envvars(RENV_PATHS_CACHE = dirname(projlib))
101 expect_true(renv_cache_config_symlinks(project = project))
102
103
104 })
105
106 test_that("RENV_CONFIG_EXTERNAL_LIBRARIES is decoded appropriately", {
107
108 envname <- "RENV_CONFIG_EXTERNAL_LIBRARIES"
109
110 expect_equal(
111 renv_config_decode_envvar(envname, "/apple"),
112 "/apple"
113 )
114
115 expect_equal(
116 renv_config_decode_envvar(envname, "C:/apple"),
117 "C:/apple"
118 )
119
120 expect_equal(
121 renv_config_decode_envvar(envname, "C:/apple:C:/banana"),
122 c("C:/apple", "C:/banana")
123 )
124
125 expect_equal(
126 renv_config_decode_envvar(envname, "C:/apple;C:/banana"),
127 c("C:/apple", "C:/banana")
128 )
129
130 expect_equal(
131 renv_config_decode_envvar(envname, "C:/apple,C:/banana"),
132 c("C:/apple", "C:/banana")
133 )
134
135 expect_equal(
136 renv_config_decode_envvar(envname, "/apple:/banana"),
137 c("/apple", "/banana")
138 )
139
140 expect_equal(
141 renv_config_decode_envvar(envname, "/apple;/banana"),
142 c("/apple", "/banana")
143 )
144
145 expect_equal(
146 renv_config_decode_envvar(envname, "/apple,/banana"),
147 c("/apple", "/banana")
148 )
149
150 })
151
152 test_that("RENV_CONFIG_REPOS_OVERRIDE is decoded appropriately", {
153
154 envname <- "RENV_CONFIG_REPOS_OVERRIDE"
155
156 # single unnamed repository becomes CRAN
157 expect_equal(
158 renv_config_decode_envvar(envname, "https://cloud.r-project.org"),
159 c(CRAN = "https://cloud.r-project.org")
160 )
161
162 # single named repository
163 expect_equal(
164 renv_config_decode_envvar(envname, "CRAN=https://cloud.r-project.org"),
165 c(CRAN = "https://cloud.r-project.org")
166 )
167
168 # multiple named repositories
169 expect_equal(
170 renv_config_decode_envvar(envname, "CRAN=https://cran.r-project.org;RSPM=https://packagemanager.posit.co"),
171 c(CRAN = "https://cran.r-project.org", RSPM = "https://packagemanager.posit.co")
172 )
173
174 # multiple repositories with different names
175 expect_equal(
176 renv_config_decode_envvar(envname, "Repo1=https://repo1.com;Repo2=https://repo2.com;Repo3=https://repo3.com"),
177 c(Repo1 = "https://repo1.com", Repo2 = "https://repo2.com", Repo3 = "https://repo3.com")
178 )
179
180 })