| 1 |
|
| 2 |
test_that("available_packages() returns NULL when no repos set", { |
| 3 |
skip_on_cran() |
| 4 |
|
| 5 |
local({ |
| 6 |
renv_scope_options(repos = character()) |
| 7 |
expect_null(available_packages(type = "source")) |
| 8 |
}) |
| 9 |
|
| 10 |
local({ |
| 11 |
renv_scope_options(repos = list()) |
| 12 |
expect_null(available_packages(type = "source")) |
| 13 |
}) |
| 14 |
|
| 15 |
local({ |
| 16 |
renv_scope_options(repos = NULL) |
| 17 |
expect_null(available_packages(type = "source")) |
| 18 |
}) |
| 19 |
|
| 20 |
}) |
| 21 |
|
| 22 |
test_that("renv handles multiple available source packages", { |
| 23 |
skip_on_cran() |
| 24 |
|
| 25 |
renv_tests_scope() |
| 26 |
|
| 27 |
dbs <- available_packages(type = "source") |
| 28 |
cran <- dbs[["CRAN"]] |
| 29 |
entries <- cran[cran$Package == "breakfast", ] |
| 30 |
expect_true(nrow(entries) == 3) |
| 31 |
|
| 32 |
entry <- renv_available_packages_entry( |
| 33 |
package = "breakfast", |
| 34 |
type = "source" |
| 35 |
) |
| 36 |
|
| 37 |
expect_true(nrow(entry) == 1) |
| 38 |
expect_true(entry$Package == "breakfast") |
| 39 |
expect_true(entry$Version == "1.0.0") |
| 40 |
|
| 41 |
}) |
| 42 |
|
| 43 |
test_that("available_packages() succeeds with unnamed repositories", { |
| 44 |
skip_on_cran() |
| 45 |
renv_tests_scope() |
| 46 |
|
| 47 |
entry <- renv_available_packages_entry( |
| 48 |
package = "breakfast", |
| 49 |
type = "source", |
| 50 |
filter = "1.0.0" |
| 51 |
) |
| 52 |
|
| 53 |
expect_identical(entry$Package, "breakfast") |
| 54 |
expect_identical(entry$Version, "1.0.0") |
| 55 |
|
| 56 |
}) |
| 57 |
|
| 58 |
test_that("renv_available_packages_latest() respects pkgType option", { |
| 59 |
|
| 60 |
skip_on_cran() |
| 61 |
skip_if(.Platform$pkgType == "source") |
| 62 |
|
| 63 |
renv_tests_scope() |
| 64 |
|
| 65 |
renv_scope_options(pkgType = "source") |
| 66 |
record <- renv_available_packages_latest("breakfast") |
| 67 |
expect_identical(attr(record, "type"), "source") |
| 68 |
|
| 69 |
renv_scope_options(renv.config.ppm.enabled = FALSE) |
| 70 |
renv_scope_options(pkgType = "binary") |
| 71 |
record <- renv_available_packages_latest("breakfast") |
| 72 |
expect_identical(attr(record, "type"), "binary") |
| 73 |
|
| 74 |
}) |
| 75 |
|
| 76 |
test_that("pkgType = 'both' on source-only platforms yields a source record (#2275)", { |
| 77 |
|
| 78 |
skip_on_cran() |
| 79 |
skip_if_not(.Platform$pkgType == "source") |
| 80 |
|
| 81 |
renv_tests_scope() |
| 82 |
|
| 83 |
renv_scope_options(pkgType = "both") |
| 84 |
record <- renv_available_packages_latest("breakfast") |
| 85 |
expect_identical(attr(record, "type"), "source") |
| 86 |
|
| 87 |
}) |
| 88 |
|
| 89 |
test_that("local sources are preferred when available", { |
| 90 |
|
| 91 |
skip_on_cran() |
| 92 |
renv_tests_scope() |
| 93 |
|
| 94 |
renv_scope_envvars(RENV_PATHS_LOCAL = renv_tests_path("local")) |
| 95 |
|
| 96 |
record <- renv_available_packages_latest(package = "skeleton", type = "source") |
| 97 |
expect_identical(record$Source, "Cellar") |
| 98 |
|
| 99 |
}) |
| 100 |
|
| 101 |
test_that("available packages database refreshed on http_proxy change", { |
| 102 |
|
| 103 |
skip_on_cran() |
| 104 |
skip_on_os("windows") |
| 105 |
|
| 106 |
renv_tests_scope_repos() |
| 107 |
renv_scope_envvars("https_proxy" = "123") |
| 108 |
available_packages(type = "source") |
| 109 |
|
| 110 |
count <- 0L |
| 111 |
renv_scope_trace( |
| 112 |
what = renv:::renv_available_packages_query, |
| 113 |
tracer = function() { count <<- count + 1L } |
| 114 |
) |
| 115 |
|
| 116 |
renv_scope_envvars("https_proxy" = "") |
| 117 |
available_packages(type = "source") |
| 118 |
expect_identical(count, 1L) |
| 119 |
|
| 120 |
}) |
| 121 |
|
| 122 |
test_that("available packages prefer tagged repository", { |
| 123 |
|
| 124 |
skip_on_cran() |
| 125 |
skip_on_os("windows") |
| 126 |
|
| 127 |
renv_tests_scope() |
| 128 |
|
| 129 |
repos <- getOption("repos")[[1L]] |
| 130 |
renv_scope_options(repos = c(CRAN = repos, ALT = repos)) |
| 131 |
|
| 132 |
entry <- renv_available_packages_entry( |
| 133 |
package = "breakfast", |
| 134 |
type = "source", |
| 135 |
prefer = "ALT", |
| 136 |
quiet = TRUE |
| 137 |
) |
| 138 |
|
| 139 |
expect_equal(entry$Name, "ALT") |
| 140 |
|
| 141 |
}) |
| 142 |
|
| 143 |
test_that("we're compatible with R", { |
| 144 |
|
| 145 |
skip_on_cran() |
| 146 |
renv_tests_scope() |
| 147 |
repos <- getOption("repos")[1L] |
| 148 |
|
| 149 |
lhs <- as.data.frame( |
| 150 |
available.packages( |
| 151 |
type = "source", |
| 152 |
repos = repos, |
| 153 |
filters = c("R_version", "OS_type") |
| 154 |
), |
| 155 |
row.names = FALSE, |
| 156 |
stringsAsFactors = FALSE |
| 157 |
) |
| 158 |
|
| 159 |
rhs <- available_packages( |
| 160 |
type = "source", |
| 161 |
repos = repos |
| 162 |
)[[1L]] |
| 163 |
|
| 164 |
row.names(lhs) <- row.names(rhs) <- NULL |
| 165 |
fields <- c("Package", "Version") |
| 166 |
expect_equal(lhs[fields], rhs[fields]) |
| 167 |
|
| 168 |
}) |
| 169 |
|
| 170 |
test_that("we can query the R universe", { |
| 171 |
skip_on_cran() |
| 172 |
|
| 173 |
lhs <- as.data.frame( |
| 174 |
available.packages( |
| 175 |
type = "source", |
| 176 |
repos = "https://rstudio.r-universe.dev" |
| 177 |
), |
| 178 |
stringsAsFactors = FALSE |
| 179 |
) |
| 180 |
|
| 181 |
rhs <- available_packages( |
| 182 |
type = "source", |
| 183 |
repos = "https://rstudio.r-universe.dev/" |
| 184 |
)[[1L]] |
| 185 |
|
| 186 |
# skip renv, since we just updated it |
| 187 |
lhs <- lhs[lhs$Package != "renv", ] |
| 188 |
rhs <- rhs[rhs$Package != "renv", ] |
| 189 |
|
| 190 |
# reduce risk of false positive test failures |
| 191 |
rownames(lhs) <- rownames(rhs) <- NULL |
| 192 |
lhs$MD5sum <- rhs$MD5sum <- NULL |
| 193 |
lhs$Remotes <- rhs$Remotes <- NULL |
| 194 |
|
| 195 |
# R-devel may add new columns to available.packages(); |
| 196 |
# restrict comparison to the columns renv produces |
| 197 |
lhs <- lhs[intersect(names(lhs), names(rhs))] |
| 198 |
|
| 199 |
# otherwise, check they're identical |
| 200 |
expect_identical(lhs, rhs) |
| 201 |
|
| 202 |
}) |
| 203 |
|
| 204 |
test_that("available_packages() tolerates missing repositories", { |
| 205 |
renv_tests_scope() |
| 206 |
|
| 207 |
repos <- getOption("repos") |
| 208 |
repos[["NARC"]] <- file.path(repos[["CRAN"]], "missing") |
| 209 |
renv_scope_options(repos = repos) |
| 210 |
|
| 211 |
dbs <- available_packages(type = "source") |
| 212 |
expect_false(is.null(dbs[["CRAN"]])) |
| 213 |
expect_true(is.null(dbs[["NARC"]])) |
| 214 |
}) |
| 215 |
|
| 216 |
test_that("crandb query returns R-compatible versions", { |
| 217 |
skip_on_cran() |
| 218 |
skip_if_offline() |
| 219 |
skip_if_offline(host = "r-pkg.org") |
| 220 |
renv_scope_options(renv.config.crandb.enabled = TRUE) |
| 221 |
|
| 222 |
# Query crandb for a package with known R version requirements |
| 223 |
json <- renv_available_packages_crandb_query("forcats") |
| 224 |
expect_type(json, "list") |
| 225 |
expect_true("versions" %in% names(json)) |
| 226 |
|
| 227 |
# Test R compatibility checking |
| 228 |
# forcats 1.0.1 requires R >= 4.1 |
| 229 |
entry_101 <- json$versions[["1.0.1"]] |
| 230 |
expect_true(renv_available_packages_crandb_r_compatible(entry_101, "4.5.0")) |
| 231 |
expect_true(renv_available_packages_crandb_r_compatible(entry_101, "4.1.0")) |
| 232 |
expect_false(renv_available_packages_crandb_r_compatible(entry_101, "4.0.0")) |
| 233 |
|
| 234 |
# forcats 1.0.0 requires R >= 3.4 |
| 235 |
entry_100 <- json$versions[["1.0.0"]] |
| 236 |
expect_true(renv_available_packages_crandb_r_compatible(entry_100, "4.0.0")) |
| 237 |
expect_true(renv_available_packages_crandb_r_compatible(entry_100, "3.4.0")) |
| 238 |
expect_false(renv_available_packages_crandb_r_compatible(entry_100, "3.3.0")) |
| 239 |
|
| 240 |
}) |
| 241 |
|
| 242 |
test_that("crandb returns newest compatible version", { |
| 243 |
skip_on_cran() |
| 244 |
skip_if_offline() |
| 245 |
skip_if_offline(host = "r-pkg.org") |
| 246 |
renv_scope_options(renv.config.crandb.enabled = TRUE) |
| 247 |
|
| 248 |
# Test that we get the newest compatible version |
| 249 |
result <- renv_available_packages_latest_crandb("forcats") |
| 250 |
expect_type(result, "list") |
| 251 |
expect_equal(result$Package, "forcats") |
| 252 |
expect_equal(result$Source, "Repository") |
| 253 |
expect_equal(result$Repository, "CRAN") |
| 254 |
|
| 255 |
# Version should be valid |
| 256 |
|
| 257 |
expect_true(nzchar(result$Version)) |
| 258 |
expect_no_error(numeric_version(result$Version)) |
| 259 |
}) |
| 260 |
|
| 261 |
test_that("when crandb is enabled, repos entry is preferred when versions match (tagged record)", { |
| 262 |
skip_on_cran() |
| 263 |
skip_if_offline() |
| 264 |
skip_if_offline(host = "r-pkg.org") |
| 265 |
|
| 266 |
# Use real CRAN so both repos and crandb can return the same package version |
| 267 |
renv_scope_options( |
| 268 |
repos = c(CRAN = "https://cloud.r-project.org"), |
| 269 |
renv.config.crandb.enabled = TRUE, |
| 270 |
pkgType = "source" |
| 271 |
) |
| 272 |
|
| 273 |
# For a package live on CRAN, both repos and crandb return the same version. |
| 274 |
# We must get the repos (tagged) entry so retrieval uses the current URL, |
| 275 |
# not the archive (#1735). |
| 276 |
record <- renv_available_packages_latest("RColorBrewer", type = "source") |
| 277 |
expect_true(renv_record_tagged(record), info = "record should be from repos (tagged), not crandb (untagged)") |
| 278 |
expect_equal(record$Package, "RColorBrewer") |
| 279 |
expect_true(nzchar(record$Version)) |
| 280 |
}) |
| 281 |
|
| 282 |
test_that("version requirement parsing works correctly", { |
| 283 |
|
| 284 |
# Test various requirement formats |
| 285 |
expect_true(renv_version_requirement_satisfied("4.0.0", ">= 3.4")) |
| 286 |
expect_true(renv_version_requirement_satisfied("4.0.0", ">= 4.0")) |
| 287 |
expect_true(renv_version_requirement_satisfied("4.0.0", ">= 4.0.0")) |
| 288 |
expect_false(renv_version_requirement_satisfied("4.0.0", ">= 4.1")) |
| 289 |
|
| 290 |
expect_true(renv_version_requirement_satisfied("3.6.0", "> 3.5")) |
| 291 |
expect_false(renv_version_requirement_satisfied("3.5.0", "> 3.5")) |
| 292 |
|
| 293 |
expect_true(renv_version_requirement_satisfied("4.0.0", "<= 4.0")) |
| 294 |
expect_false(renv_version_requirement_satisfied("4.1.0", "<= 4.0")) |
| 295 |
|
| 296 |
# Empty/null requirements should be satisfied |
| 297 |
expect_true(renv_version_requirement_satisfied("4.0.0", NULL)) |
| 298 |
expect_true(renv_version_requirement_satisfied("4.0.0", "*")) |
| 299 |
expect_true(renv_version_requirement_satisfied("4.0.0", "")) |
| 300 |
|
| 301 |
}) |