]>
Commit | Line | Data |
---|---|---|
04ddd4d0 DW |
1 | use crate::support::git; |
2 | use crate::support::registry::Package; | |
3 | use crate::support::{basic_manifest, lines_match, project}; | |
5430db61 AC |
4 | |
5 | #[test] | |
6 | fn oldest_lockfile_still_works() { | |
1e682848 | 7 | let cargo_commands = vec!["build", "update"]; |
cab464ea RT |
8 | for cargo_command in cargo_commands { |
9 | oldest_lockfile_still_works_with_command(cargo_command); | |
10 | } | |
11 | } | |
12 | ||
13 | fn oldest_lockfile_still_works_with_command(cargo_command: &str) { | |
f8c9928c | 14 | Package::new("bar", "0.1.0").publish(); |
5430db61 | 15 | |
1e682848 | 16 | let expected_lockfile = r#"[[package]] |
f8c9928c | 17 | name = "bar" |
89023dce MS |
18 | version = "0.1.0" |
19 | source = "registry+https://github.com/rust-lang/crates.io-index" | |
20 | ||
21 | [[package]] | |
f8c9928c | 22 | name = "foo" |
850fbdc0 RT |
23 | version = "0.0.1" |
24 | dependencies = [ | |
f8c9928c | 25 | "bar 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", |
850fbdc0 RT |
26 | ] |
27 | ||
850fbdc0 | 28 | [metadata] |
f8c9928c | 29 | "checksum bar 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "[..]" |
850fbdc0 RT |
30 | "#; |
31 | ||
1e682848 | 32 | let old_lockfile = r#"[root] |
f8c9928c | 33 | name = "foo" |
5430db61 AC |
34 | version = "0.0.1" |
35 | dependencies = [ | |
f8c9928c | 36 | "bar 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", |
5430db61 AC |
37 | ] |
38 | ||
39 | [[package]] | |
f8c9928c | 40 | name = "bar" |
5430db61 AC |
41 | version = "0.1.0" |
42 | source = "registry+https://github.com/rust-lang/crates.io-index" | |
43 | "#; | |
191358fe | 44 | |
f8c9928c | 45 | let p = project() |
1e682848 AC |
46 | .file( |
47 | "Cargo.toml", | |
48 | r#" | |
191358fe | 49 | [project] |
f8c9928c | 50 | name = "foo" |
191358fe AK |
51 | version = "0.0.1" |
52 | authors = [] | |
53 | ||
54 | [dependencies] | |
f8c9928c | 55 | bar = "0.1.0" |
1e682848 | 56 | "#, |
85984a87 | 57 | ).file("src/lib.rs", "") |
63d83e8e AK |
58 | .file("Cargo.lock", old_lockfile) |
59 | .build(); | |
f5fbf730 | 60 | |
85984a87 | 61 | p.cargo(cargo_command).run(); |
850fbdc0 | 62 | |
cab464ea RT |
63 | let lock = p.read_lockfile(); |
64 | for (l, r) in expected_lockfile.lines().zip(lock.lines()) { | |
65 | assert!(lines_match(l, r), "Lines differ:\n{}\n\n{}", l, r); | |
f5fbf730 | 66 | } |
cab464ea RT |
67 | |
68 | assert_eq!(lock.lines().count(), expected_lockfile.lines().count()); | |
5430db61 AC |
69 | } |
70 | ||
63d83e8e AK |
71 | #[test] |
72 | fn frozen_flag_preserves_old_lockfile() { | |
f8c9928c | 73 | let cksum = Package::new("bar", "0.1.0").publish(); |
63d83e8e | 74 | |
a0dfbb7a | 75 | let old_lockfile = format!( |
63d83e8e | 76 | r#"[root] |
f8c9928c | 77 | name = "foo" |
63d83e8e AK |
78 | version = "0.0.1" |
79 | dependencies = [ | |
f8c9928c | 80 | "bar 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", |
63d83e8e AK |
81 | ] |
82 | ||
83 | [[package]] | |
f8c9928c | 84 | name = "bar" |
63d83e8e AK |
85 | version = "0.1.0" |
86 | source = "registry+https://github.com/rust-lang/crates.io-index" | |
87 | ||
88 | [metadata] | |
f8c9928c | 89 | "checksum bar 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "{}" |
a0dfbb7a | 90 | "#, |
1e682848 | 91 | cksum, |
a0dfbb7a | 92 | ); |
63d83e8e | 93 | |
f8c9928c | 94 | let p = project() |
1e682848 AC |
95 | .file( |
96 | "Cargo.toml", | |
97 | r#" | |
63d83e8e | 98 | [project] |
f8c9928c | 99 | name = "foo" |
63d83e8e AK |
100 | version = "0.0.1" |
101 | authors = [] | |
102 | ||
103 | [dependencies] | |
f8c9928c | 104 | bar = "0.1.0" |
1e682848 | 105 | "#, |
85984a87 | 106 | ).file("src/lib.rs", "") |
a0dfbb7a | 107 | .file("Cargo.lock", &old_lockfile) |
63d83e8e AK |
108 | .build(); |
109 | ||
85984a87 | 110 | p.cargo("build --locked").run(); |
63d83e8e AK |
111 | |
112 | let lock = p.read_lockfile(); | |
113 | for (l, r) in old_lockfile.lines().zip(lock.lines()) { | |
114 | assert!(lines_match(l, r), "Lines differ:\n{}\n\n{}", l, r); | |
115 | } | |
116 | ||
117 | assert_eq!(lock.lines().count(), old_lockfile.lines().count()); | |
118 | } | |
119 | ||
5430db61 AC |
120 | #[test] |
121 | fn totally_wild_checksums_works() { | |
f8c9928c | 122 | Package::new("bar", "0.1.0").publish(); |
5430db61 | 123 | |
f8c9928c | 124 | let p = project() |
1e682848 AC |
125 | .file( |
126 | "Cargo.toml", | |
127 | r#" | |
5430db61 | 128 | [project] |
f8c9928c | 129 | name = "foo" |
5430db61 AC |
130 | version = "0.0.1" |
131 | authors = [] | |
132 | ||
133 | [dependencies] | |
f8c9928c | 134 | bar = "0.1.0" |
1e682848 | 135 | "#, |
85984a87 | 136 | ).file("src/lib.rs", "") |
1e682848 AC |
137 | .file( |
138 | "Cargo.lock", | |
139 | r#" | |
850fbdc0 | 140 | [[package]] |
f8c9928c | 141 | name = "foo" |
5430db61 AC |
142 | version = "0.0.1" |
143 | dependencies = [ | |
f8c9928c | 144 | "bar 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", |
5430db61 AC |
145 | ] |
146 | ||
147 | [[package]] | |
f8c9928c | 148 | name = "bar" |
5430db61 AC |
149 | version = "0.1.0" |
150 | source = "registry+https://github.com/rust-lang/crates.io-index" | |
151 | ||
152 | [metadata] | |
153 | "checksum baz 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "checksum" | |
f8c9928c | 154 | "checksum bar 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "checksum" |
1e682848 AC |
155 | "#, |
156 | ); | |
191358fe | 157 | |
d43ee1dd | 158 | let p = p.build(); |
5430db61 | 159 | |
85984a87 | 160 | p.cargo("build").run(); |
5430db61 | 161 | |
191358fe | 162 | let lock = p.read_lockfile(); |
1e682848 AC |
163 | assert!( |
164 | lock.starts_with( | |
165 | r#" | |
850fbdc0 | 166 | [[package]] |
5430db61 | 167 | name = "bar" |
f8c9928c DW |
168 | version = "0.1.0" |
169 | source = "registry+https://github.com/rust-lang/crates.io-index" | |
5430db61 AC |
170 | |
171 | [[package]] | |
172 | name = "foo" | |
f8c9928c DW |
173 | version = "0.0.1" |
174 | dependencies = [ | |
175 | "bar 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", | |
176 | ] | |
5430db61 AC |
177 | |
178 | [metadata] | |
1e682848 AC |
179 | "#.trim() |
180 | ) | |
181 | ); | |
5430db61 AC |
182 | } |
183 | ||
184 | #[test] | |
185 | fn wrong_checksum_is_an_error() { | |
f8c9928c | 186 | Package::new("bar", "0.1.0").publish(); |
5430db61 | 187 | |
f8c9928c | 188 | let p = project() |
1e682848 AC |
189 | .file( |
190 | "Cargo.toml", | |
191 | r#" | |
5430db61 | 192 | [project] |
f8c9928c | 193 | name = "foo" |
5430db61 AC |
194 | version = "0.0.1" |
195 | authors = [] | |
196 | ||
197 | [dependencies] | |
f8c9928c | 198 | bar = "0.1.0" |
1e682848 | 199 | "#, |
85984a87 | 200 | ).file("src/lib.rs", "") |
1e682848 AC |
201 | .file( |
202 | "Cargo.lock", | |
203 | r#" | |
850fbdc0 | 204 | [[package]] |
f8c9928c | 205 | name = "foo" |
5430db61 AC |
206 | version = "0.0.1" |
207 | dependencies = [ | |
f8c9928c | 208 | "bar 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", |
5430db61 AC |
209 | ] |
210 | ||
211 | [[package]] | |
f8c9928c | 212 | name = "bar" |
5430db61 AC |
213 | version = "0.1.0" |
214 | source = "registry+https://github.com/rust-lang/crates.io-index" | |
215 | ||
216 | [metadata] | |
f8c9928c | 217 | "checksum bar 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "checksum" |
1e682848 AC |
218 | "#, |
219 | ); | |
191358fe | 220 | |
d43ee1dd | 221 | let p = p.build(); |
5430db61 | 222 | |
85984a87 DW |
223 | p.cargo("build") |
224 | .with_status(101) | |
225 | .with_stderr( | |
1e682848 | 226 | "\ |
41aa6fba | 227 | [UPDATING] `[..]` index |
f8c9928c | 228 | error: checksum for `bar v0.1.0` changed between lock files |
5430db61 AC |
229 | |
230 | this could be indicative of a few possible errors: | |
231 | ||
232 | * the lock file is corrupt | |
233 | * a replacement source in use (e.g. a mirror) returned a different checksum | |
234 | * the source itself may be corrupt in one way or another | |
235 | ||
f8c9928c | 236 | unable to verify that `bar v0.1.0` is the same as when the lockfile was generated |
5430db61 | 237 | |
1e682848 | 238 | ", |
85984a87 | 239 | ).run(); |
5430db61 AC |
240 | } |
241 | ||
242 | // If the checksum is unlisted in the lockfile (e.g. <none>) yet we can | |
243 | // calculate it (e.g. it's a registry dep), then we should in theory just fill | |
244 | // it in. | |
245 | #[test] | |
246 | fn unlisted_checksum_is_bad_if_we_calculate() { | |
f8c9928c | 247 | Package::new("bar", "0.1.0").publish(); |
5430db61 | 248 | |
f8c9928c | 249 | let p = project() |
1e682848 AC |
250 | .file( |
251 | "Cargo.toml", | |
252 | r#" | |
5430db61 | 253 | [project] |
f8c9928c | 254 | name = "foo" |
5430db61 AC |
255 | version = "0.0.1" |
256 | authors = [] | |
257 | ||
258 | [dependencies] | |
f8c9928c | 259 | bar = "0.1.0" |
1e682848 | 260 | "#, |
85984a87 | 261 | ).file("src/lib.rs", "") |
1e682848 AC |
262 | .file( |
263 | "Cargo.lock", | |
264 | r#" | |
850fbdc0 | 265 | [[package]] |
f8c9928c | 266 | name = "foo" |
5430db61 AC |
267 | version = "0.0.1" |
268 | dependencies = [ | |
f8c9928c | 269 | "bar 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", |
5430db61 AC |
270 | ] |
271 | ||
272 | [[package]] | |
f8c9928c | 273 | name = "bar" |
5430db61 AC |
274 | version = "0.1.0" |
275 | source = "registry+https://github.com/rust-lang/crates.io-index" | |
276 | ||
277 | [metadata] | |
f8c9928c | 278 | "checksum bar 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "<none>" |
1e682848 AC |
279 | "#, |
280 | ); | |
d43ee1dd | 281 | let p = p.build(); |
5430db61 | 282 | |
85984a87 DW |
283 | p.cargo("fetch") |
284 | .with_status(101) | |
285 | .with_stderr( | |
1e682848 | 286 | "\ |
41aa6fba | 287 | [UPDATING] `[..]` index |
f8c9928c | 288 | error: checksum for `bar v0.1.0` was not previously calculated, but a checksum \ |
5430db61 AC |
289 | could now be calculated |
290 | ||
291 | this could be indicative of a few possible situations: | |
292 | ||
293 | * the source `[..]` did not previously support checksums, | |
294 | but was replaced with one that does | |
295 | * newer Cargo implementations know how to checksum this source, but this | |
296 | older implementation does not | |
297 | * the lock file is corrupt | |
298 | ||
1e682848 | 299 | ", |
85984a87 | 300 | ).run(); |
5430db61 AC |
301 | } |
302 | ||
303 | // If the checksum is listed in the lockfile yet we cannot calculate it (e.g. | |
304 | // git dependencies as of today), then make sure we choke. | |
305 | #[test] | |
306 | fn listed_checksum_bad_if_we_cannot_compute() { | |
f8c9928c | 307 | let git = git::new("bar", |p| { |
ab19c483 | 308 | p.file("Cargo.toml", &basic_manifest("bar", "0.1.0")) |
85984a87 | 309 | .file("src/lib.rs", "") |
5430db61 AC |
310 | }).unwrap(); |
311 | ||
f8c9928c | 312 | let p = project() |
1e682848 AC |
313 | .file( |
314 | "Cargo.toml", | |
315 | &format!( | |
316 | r#" | |
5430db61 | 317 | [project] |
f8c9928c | 318 | name = "foo" |
5430db61 AC |
319 | version = "0.0.1" |
320 | authors = [] | |
321 | ||
322 | [dependencies] | |
f8c9928c | 323 | bar = {{ git = '{}' }} |
1e682848 AC |
324 | "#, |
325 | git.url() | |
326 | ), | |
85984a87 | 327 | ).file("src/lib.rs", "") |
1e682848 AC |
328 | .file( |
329 | "Cargo.lock", | |
330 | &format!( | |
331 | r#" | |
850fbdc0 | 332 | [[package]] |
f8c9928c | 333 | name = "foo" |
5430db61 AC |
334 | version = "0.0.1" |
335 | dependencies = [ | |
f8c9928c | 336 | "bar 0.1.0 (git+{0})" |
5430db61 AC |
337 | ] |
338 | ||
339 | [[package]] | |
f8c9928c | 340 | name = "bar" |
5430db61 AC |
341 | version = "0.1.0" |
342 | source = "git+{0}" | |
343 | ||
344 | [metadata] | |
f8c9928c | 345 | "checksum bar 0.1.0 (git+{0})" = "checksum" |
1e682848 AC |
346 | "#, |
347 | git.url() | |
348 | ), | |
349 | ); | |
191358fe | 350 | |
d43ee1dd | 351 | let p = p.build(); |
5430db61 | 352 | |
85984a87 DW |
353 | p.cargo("fetch") |
354 | .with_status(101) | |
355 | .with_stderr( | |
1e682848 | 356 | "\ |
5430db61 | 357 | [UPDATING] git repository `[..]` |
f8c9928c | 358 | error: checksum for `bar v0.1.0 ([..])` could not be calculated, but a \ |
5430db61 AC |
359 | checksum is listed in the existing lock file[..] |
360 | ||
361 | this could be indicative of a few possible situations: | |
362 | ||
363 | * the source `[..]` supports checksums, | |
364 | but was replaced with one that doesn't | |
365 | * the lock file is corrupt | |
366 | ||
f8c9928c | 367 | unable to verify that `bar v0.1.0 ([..])` is the same as when the lockfile was generated |
5430db61 | 368 | |
1e682848 | 369 | ", |
85984a87 | 370 | ).run(); |
5430db61 | 371 | } |
5e644df1 | 372 | |
9c5d4da2 AK |
373 | #[test] |
374 | fn current_lockfile_format() { | |
f8c9928c | 375 | Package::new("bar", "0.1.0").publish(); |
9c5d4da2 | 376 | |
f8c9928c | 377 | let p = project() |
1e682848 AC |
378 | .file( |
379 | "Cargo.toml", | |
380 | r#" | |
9c5d4da2 | 381 | [package] |
f8c9928c | 382 | name = "foo" |
9c5d4da2 AK |
383 | version = "0.0.1" |
384 | authors = [] | |
385 | ||
386 | [dependencies] | |
f8c9928c | 387 | bar = "0.1.0" |
1e682848 | 388 | "#, |
85984a87 | 389 | ).file("src/lib.rs", ""); |
d43ee1dd | 390 | let p = p.build(); |
9c5d4da2 | 391 | |
85984a87 | 392 | p.cargo("build").run(); |
9c5d4da2 | 393 | |
191358fe | 394 | let actual = p.read_lockfile(); |
9c5d4da2 AK |
395 | |
396 | let expected = "\ | |
850fbdc0 | 397 | [[package]] |
9c5d4da2 | 398 | name = \"bar\" |
f8c9928c DW |
399 | version = \"0.1.0\" |
400 | source = \"registry+https://github.com/rust-lang/crates.io-index\" | |
9c5d4da2 AK |
401 | |
402 | [[package]] | |
403 | name = \"foo\" | |
f8c9928c DW |
404 | version = \"0.0.1\" |
405 | dependencies = [ | |
406 | \"bar 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)\", | |
407 | ] | |
9c5d4da2 AK |
408 | |
409 | [metadata] | |
f8c9928c | 410 | \"checksum bar 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)\" = \"[..]\""; |
9c5d4da2 AK |
411 | |
412 | for (l, r) in expected.lines().zip(actual.lines()) { | |
413 | assert!(lines_match(l, r), "Lines differ:\n{}\n\n{}", l, r); | |
414 | } | |
415 | ||
416 | assert_eq!(actual.lines().count(), expected.lines().count()); | |
417 | } | |
418 | ||
5e644df1 AK |
419 | #[test] |
420 | fn lockfile_without_root() { | |
f8c9928c | 421 | Package::new("bar", "0.1.0").publish(); |
5e644df1 | 422 | |
5e644df1 AK |
423 | let lockfile = r#"[[package]] |
424 | name = "bar" | |
f8c9928c DW |
425 | version = "0.1.0" |
426 | source = "registry+https://github.com/rust-lang/crates.io-index" | |
5e644df1 AK |
427 | |
428 | [[package]] | |
429 | name = "foo" | |
f8c9928c DW |
430 | version = "0.0.1" |
431 | dependencies = [ | |
432 | "bar 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", | |
433 | ] | |
5e644df1 | 434 | "#; |
191358fe | 435 | |
f8c9928c | 436 | let p = project() |
1e682848 AC |
437 | .file( |
438 | "Cargo.toml", | |
439 | r#" | |
191358fe | 440 | [package] |
f8c9928c | 441 | name = "foo" |
191358fe AK |
442 | version = "0.0.1" |
443 | authors = [] | |
444 | ||
445 | [dependencies] | |
f8c9928c | 446 | bar = "0.1.0" |
1e682848 | 447 | "#, |
85984a87 | 448 | ).file("src/lib.rs", "") |
191358fe AK |
449 | .file("Cargo.lock", lockfile); |
450 | ||
d43ee1dd | 451 | let p = p.build(); |
5e644df1 | 452 | |
85984a87 | 453 | p.cargo("build").run(); |
5e644df1 | 454 | |
191358fe | 455 | let lock = p.read_lockfile(); |
5e644df1 AK |
456 | assert!(lock.starts_with(lockfile.trim())); |
457 | } | |
3f4d7e75 RJ |
458 | |
459 | #[test] | |
460 | fn locked_correct_error() { | |
f8c9928c | 461 | Package::new("bar", "0.1.0").publish(); |
3f4d7e75 | 462 | |
f8c9928c | 463 | let p = project() |
1e682848 AC |
464 | .file( |
465 | "Cargo.toml", | |
466 | r#" | |
3f4d7e75 | 467 | [project] |
f8c9928c | 468 | name = "foo" |
3f4d7e75 RJ |
469 | version = "0.0.1" |
470 | authors = [] | |
471 | ||
472 | [dependencies] | |
f8c9928c | 473 | bar = "0.1.0" |
1e682848 | 474 | "#, |
85984a87 | 475 | ).file("src/lib.rs", ""); |
d43ee1dd | 476 | let p = p.build(); |
3f4d7e75 | 477 | |
85984a87 DW |
478 | p.cargo("build --locked") |
479 | .with_status(101) | |
480 | .with_stderr( | |
1e682848 | 481 | "\ |
41aa6fba | 482 | [UPDATING] `[..]` index |
b8c24f3e | 483 | error: the lock file [CWD]/Cargo.lock needs to be updated but --locked was passed to prevent this |
1e682848 | 484 | ", |
85984a87 | 485 | ).run(); |
3f4d7e75 | 486 | } |