| 1 |
|
| 2 |
test_that("renv_records_select() handles missing packages gracefully", { |
| 3 |
|
| 4 |
# simulate what happens during printing of records during install |
| 5 |
lhs <- list() |
| 6 |
rhs <- list(skeleton = list(Package = "skeleton")) |
| 7 |
|
| 8 |
actions <- c(skeleton = "install") |
| 9 |
action <- "install" |
| 10 |
|
| 11 |
expect_identical(renv_records_select(lhs, actions, action), lhs) |
| 12 |
expect_identical(renv_records_select(rhs, actions, action), rhs) |
| 13 |
|
| 14 |
}) |
| 15 |
|
| 16 |
test_that("we can format records in various ways", { |
| 17 |
|
| 18 |
old <- list( |
| 19 |
Package = "skeleton", |
| 20 |
Version = "1.0.0", |
| 21 |
Source = "Repository", |
| 22 |
Repository = "CRAN" |
| 23 |
) |
| 24 |
|
| 25 |
new <- list( |
| 26 |
Package = "skeleton", |
| 27 |
Version = "1.0.0", |
| 28 |
Source = "github", |
| 29 |
RemoteUsername = "kevinushey", |
| 30 |
RemoteRepo = "skeleton" |
| 31 |
) |
| 32 |
|
| 33 |
expect_equal(renv_record_format_short(old), "1.0.0") |
| 34 |
expect_equal(renv_record_format_short(new), "kevinushey/skeleton") |
| 35 |
|
| 36 |
expect_equal( |
| 37 |
renv_record_format_pair(old, new), |
| 38 |
"[1.0.0 -> kevinushey/skeleton]" |
| 39 |
) |
| 40 |
|
| 41 |
expect_equal( |
| 42 |
renv_record_format_pair(new, new), |
| 43 |
"[kevinushey/skeleton: unchanged]" |
| 44 |
) |
| 45 |
|
| 46 |
record <- list( |
| 47 |
Package = "skeleton", |
| 48 |
Version = "1.0.0", |
| 49 |
Source = "github", |
| 50 |
RemoteUsername = "kevinushey", |
| 51 |
RemoteRepo = "skeleton", |
| 52 |
RemoteRef = "feature/branch" |
| 53 |
) |
| 54 |
|
| 55 |
expect_equal( |
| 56 |
renv_record_format_short(record), |
| 57 |
"kevinushey/skeleton@feature/branch" |
| 58 |
) |
| 59 |
|
| 60 |
old <- list( |
| 61 |
Package = "skeleton", |
| 62 |
Version = "1.0.0", |
| 63 |
Source = "GitHub", |
| 64 |
RemoteUsername = "kevinushey", |
| 65 |
RemoteRepo = "skeleton" |
| 66 |
) |
| 67 |
|
| 68 |
new <- list( |
| 69 |
Package = "skeleton", |
| 70 |
Version = "1.0.0", |
| 71 |
Source = "Gitlab", |
| 72 |
RemoteUsername = "kevinushey", |
| 73 |
RemoteRepo = "skeleton" |
| 74 |
) |
| 75 |
|
| 76 |
expect_equal( |
| 77 |
renv_record_format_pair(old, new), |
| 78 |
"[1.0.0: GitHub -> Gitlab]" |
| 79 |
) |
| 80 |
|
| 81 |
}) |
| 82 |
|
| 83 |
test_that("renv_record_format_short handles missing Version", { |
| 84 |
|
| 85 |
record <- list(Package = "thispackagedoesnotexist") |
| 86 |
expect_equal(renv_record_format_short(record), "*") |
| 87 |
|
| 88 |
}) |
| 89 |
|
| 90 |
test_that("compatible records from pak are handled correctly", { |
| 91 |
|
| 92 |
lhs <- list( |
| 93 |
Package = "anytime", |
| 94 |
Version = "0.3.9", |
| 95 |
Source = "Repository", |
| 96 |
Depends = "R (>= 3.2.0)", |
| 97 |
Imports = "Rcpp (>= 0.12.9)", |
| 98 |
LinkingTo = c("Rcpp (>= 0.12.9)", "BH"), |
| 99 |
Repository = "CRAN", |
| 100 |
RemoteType = "standard", |
| 101 |
RemotePkgRef = "anytime", |
| 102 |
RemoteRef = "anytime", |
| 103 |
RemoteRepos = "https://cran.rstudio.com", |
| 104 |
RemotePkgPlatform = "aarch64-apple-darwin20", |
| 105 |
RemoteSha = "0.3.9", |
| 106 |
Hash = "74a64813f17b492da9c6afda6b128e3d" |
| 107 |
) |
| 108 |
|
| 109 |
rhs <- list( |
| 110 |
Package = "anytime", |
| 111 |
Version = "0.3.9", |
| 112 |
Source = "CRAN", |
| 113 |
Repository = "CRAN", |
| 114 |
RemoteType = "standard", |
| 115 |
RemotePkgRef = "anytime", |
| 116 |
RemoteRef = "anytime", |
| 117 |
RemoteRepos = "https://cran.rstudio.com", |
| 118 |
RemotePkgPlatform = "aarch64-apple-darwin20", |
| 119 |
RemoteSha = "0.3.9", |
| 120 |
Hash = "74a64813f17b492da9c6afda6b128e3d", |
| 121 |
Requirements = list() |
| 122 |
) |
| 123 |
|
| 124 |
change <- renv_lockfile_diff_record(lhs, rhs) |
| 125 |
expect_null(change) |
| 126 |
|
| 127 |
}) |
| 128 |
|
| 129 |
test_that("records with NULL versions are treated as crossgrades", { |
| 130 |
|
| 131 |
# https://github.com/rstudio/renv/issues/2248 |
| 132 |
before <- list(Package = "skeleton", Version = NULL) |
| 133 |
after <- list(Package = "skeleton", Version = "1.0.0") |
| 134 |
expect_equal(renv_lockfile_diff_record(before, after), "crossgrade") |
| 135 |
|
| 136 |
before <- list(Package = "skeleton", Version = "1.0.0") |
| 137 |
after <- list(Package = "skeleton", Version = NULL) |
| 138 |
expect_equal(renv_lockfile_diff_record(before, after), "crossgrade") |
| 139 |
|
| 140 |
before <- list(Package = "skeleton", Version = NULL) |
| 141 |
after <- list(Package = "skeleton", Version = NULL) |
| 142 |
expect_equal(renv_lockfile_diff_record(before, after), "crossgrade") |
| 143 |
|
| 144 |
}) |
| 145 |
|
| 146 |
test_that("pak's cran remotes are considered cranlike", { |
| 147 |
|
| 148 |
record <- list( |
| 149 |
Package = "rlang", |
| 150 |
Version = "1.0.0", |
| 151 |
RemoteType = "standard", |
| 152 |
RemotePkgRef = "rlang", |
| 153 |
RemoteRef = "rlang", |
| 154 |
RemoteRepos = "https://cloud.R-project.org", |
| 155 |
RemotePkgPlatform = "aarch64-apple-darwin20", |
| 156 |
RemoteSha = "1.1.3" |
| 157 |
) |
| 158 |
|
| 159 |
actual <- renv_record_normalize(record) |
| 160 |
expected <- list(Package = "rlang", Version = "1.0.0") |
| 161 |
expect_identical(!!actual, !!expected) |
| 162 |
|
| 163 |
}) |
| 164 |
|
| 165 |
test_that("we format github remotes appropriately", { |
| 166 |
|
| 167 |
record <- list( |
| 168 |
Package = "skeleton", |
| 169 |
Version = "1.1.0", |
| 170 |
RemoteType = "github", |
| 171 |
RemoteUsername = "kevinushey", |
| 172 |
RemoteRepo = "skeleton", |
| 173 |
RemoteRef = "main", |
| 174 |
RemoteSha = "e4aafb92b86ba7eba3b7036d9d96fdfb6c32761a", |
| 175 |
RemoteSubdir = "subdir" |
| 176 |
) |
| 177 |
|
| 178 |
remote <- renv_record_format_remote(record, compact = FALSE) |
| 179 |
expect_equal(remote, "kevinushey/skeleton:subdir@e4aafb92b86ba7eba3b7036d9d96fdfb6c32761a") |
| 180 |
|
| 181 |
remote <- renv_record_format_remote(record, compact = TRUE) |
| 182 |
expect_equal(remote, "kevinushey/skeleton:subdir") |
| 183 |
|
| 184 |
remote <- renv_record_format_remote(record, pak = TRUE) |
| 185 |
expect_equal(remote, "kevinushey/skeleton/subdir@e4aafb92b86ba7eba3b7036d9d96fdfb6c32761a") |
| 186 |
|
| 187 |
}) |
| 188 |
|
| 189 |
test_that("remote hosts are included when formatting", { |
| 190 |
|
| 191 |
record <- list( |
| 192 |
Package = "skeleton", |
| 193 |
Version = "1.1.0", |
| 194 |
RemoteType = "github", |
| 195 |
RemoteHost = "github.example.com", |
| 196 |
RemoteUsername = "kevinushey", |
| 197 |
RemoteRepo = "skeleton", |
| 198 |
RemoteRef = "main", |
| 199 |
RemoteSha = "e4aafb92b86ba7eba3b7036d9d96fdfb6c32761a" |
| 200 |
) |
| 201 |
|
| 202 |
remote <- renv_record_format_remote(record, compact = FALSE) |
| 203 |
expect_equal(remote, "[email protected]::kevinushey/skeleton@e4aafb92b86ba7eba3b7036d9d96fdfb6c32761a") |
| 204 |
|
| 205 |
remote <- renv_record_format_remote(record, compact = TRUE) |
| 206 |
expect_equal(remote, "[email protected]::kevinushey/skeleton") |
| 207 |
|
| 208 |
remote <- renv_record_format_remote(record, pak = TRUE) |
| 209 |
expect_equal(remote, "[email protected]::kevinushey/skeleton@e4aafb92b86ba7eba3b7036d9d96fdfb6c32761a") |
| 210 |
|
| 211 |
}) |
| 212 |
|
| 213 |
test_that("renv_record_source infers 'repository' from Repository field", { |
| 214 |
|
| 215 |
# a record with Source explicitly set uses that |
| 216 |
record <- list(Package = "skeleton", Version = "1.0.0", Source = "GitHub") |
| 217 |
expect_equal(renv_record_source(record), "github") |
| 218 |
|
| 219 |
# a record with no Source but a Repository field infers 'repository' |
| 220 |
record <- list(Package = "skeleton", Version = "1.0.0", Repository = "CRAN") |
| 221 |
expect_equal(renv_record_source(record), "repository") |
| 222 |
|
| 223 |
# a record with neither Source nor Repository falls back to 'unknown' |
| 224 |
record <- list(Package = "skeleton", Version = "1.0.0") |
| 225 |
expect_equal(renv_record_source(record), "unknown") |
| 226 |
|
| 227 |
}) |