]>
Commit | Line | Data |
---|---|---|
1408eecc | 1 | use std::fs::File; |
51d23560 AC |
2 | use std::io::prelude::*; |
3 | ||
04ddd4d0 DW |
4 | use crate::support::registry::Package; |
5 | use crate::support::{basic_manifest, project}; | |
51d23560 AC |
6 | |
7 | #[test] | |
8 | fn minor_update_two_places() { | |
9 | Package::new("log", "0.1.0").publish(); | |
7fe2fbc8 | 10 | let p = project() |
51d23560 AC |
11 | .file( |
12 | "Cargo.toml", | |
13 | r#" | |
14 | [package] | |
15 | name = "bar" | |
16 | version = "0.0.1" | |
17 | authors = [] | |
18 | ||
19 | [dependencies] | |
20 | log = "0.1" | |
21 | foo = { path = "foo" } | |
22 | "#, | |
fecb7246 AC |
23 | ) |
24 | .file("src/lib.rs", "") | |
51d23560 AC |
25 | .file( |
26 | "foo/Cargo.toml", | |
27 | r#" | |
28 | [package] | |
29 | name = "foo" | |
30 | version = "0.0.1" | |
31 | authors = [] | |
32 | ||
33 | [dependencies] | |
34 | log = "0.1" | |
35 | "#, | |
fecb7246 AC |
36 | ) |
37 | .file("foo/src/lib.rs", "") | |
51d23560 AC |
38 | .build(); |
39 | ||
85984a87 | 40 | p.cargo("build").run(); |
51d23560 AC |
41 | Package::new("log", "0.1.1").publish(); |
42 | ||
43 | File::create(p.root().join("foo/Cargo.toml")) | |
44 | .unwrap() | |
45 | .write_all( | |
46 | br#" | |
47 | [package] | |
48 | name = "foo" | |
49 | version = "0.0.1" | |
50 | authors = [] | |
51 | ||
52 | [dependencies] | |
53 | log = "0.1.1" | |
54 | "#, | |
fecb7246 AC |
55 | ) |
56 | .unwrap(); | |
51d23560 | 57 | |
85984a87 | 58 | p.cargo("build").run(); |
51d23560 AC |
59 | } |
60 | ||
61 | #[test] | |
62 | fn transitive_minor_update() { | |
63 | Package::new("log", "0.1.0").publish(); | |
64 | Package::new("serde", "0.1.0").dep("log", "0.1").publish(); | |
65 | ||
7fe2fbc8 | 66 | let p = project() |
51d23560 AC |
67 | .file( |
68 | "Cargo.toml", | |
69 | r#" | |
70 | [package] | |
71 | name = "bar" | |
72 | version = "0.0.1" | |
73 | authors = [] | |
74 | ||
75 | [dependencies] | |
76 | serde = "0.1" | |
77 | log = "0.1" | |
78 | foo = { path = "foo" } | |
79 | "#, | |
fecb7246 AC |
80 | ) |
81 | .file("src/lib.rs", "") | |
51d23560 AC |
82 | .file( |
83 | "foo/Cargo.toml", | |
84 | r#" | |
85 | [package] | |
86 | name = "foo" | |
87 | version = "0.0.1" | |
88 | authors = [] | |
89 | ||
90 | [dependencies] | |
91 | serde = "0.1" | |
92 | "#, | |
fecb7246 AC |
93 | ) |
94 | .file("foo/src/lib.rs", "") | |
51d23560 AC |
95 | .build(); |
96 | ||
85984a87 | 97 | p.cargo("build").run(); |
51d23560 AC |
98 | |
99 | Package::new("log", "0.1.1").publish(); | |
100 | Package::new("serde", "0.1.1").dep("log", "0.1.1").publish(); | |
101 | ||
102 | // Note that `serde` isn't actually updated here! The default behavior for | |
103 | // `update` right now is to as conservatively as possible attempt to satisfy | |
104 | // an update. In this case we previously locked the dependency graph to `log | |
105 | // 0.1.0`, but nothing on the command line says we're allowed to update | |
106 | // that. As a result the update of `serde` here shouldn't update to `serde | |
107 | // 0.1.1` as that would also force an update to `log 0.1.1`. | |
108 | // | |
109 | // Also note that this is probably counterintuitive and weird. We may wish | |
110 | // to change this one day. | |
85984a87 DW |
111 | p.cargo("update -p serde") |
112 | .with_stderr( | |
51d23560 | 113 | "\ |
41aa6fba | 114 | [UPDATING] `[..]` index |
51d23560 | 115 | ", |
fecb7246 AC |
116 | ) |
117 | .run(); | |
51d23560 AC |
118 | } |
119 | ||
120 | #[test] | |
121 | fn conservative() { | |
122 | Package::new("log", "0.1.0").publish(); | |
123 | Package::new("serde", "0.1.0").dep("log", "0.1").publish(); | |
124 | ||
7fe2fbc8 | 125 | let p = project() |
51d23560 AC |
126 | .file( |
127 | "Cargo.toml", | |
128 | r#" | |
129 | [package] | |
130 | name = "bar" | |
131 | version = "0.0.1" | |
132 | authors = [] | |
133 | ||
134 | [dependencies] | |
135 | serde = "0.1" | |
136 | log = "0.1" | |
137 | foo = { path = "foo" } | |
138 | "#, | |
fecb7246 AC |
139 | ) |
140 | .file("src/lib.rs", "") | |
51d23560 AC |
141 | .file( |
142 | "foo/Cargo.toml", | |
143 | r#" | |
144 | [package] | |
145 | name = "foo" | |
146 | version = "0.0.1" | |
147 | authors = [] | |
148 | ||
149 | [dependencies] | |
150 | serde = "0.1" | |
151 | "#, | |
fecb7246 AC |
152 | ) |
153 | .file("foo/src/lib.rs", "") | |
51d23560 AC |
154 | .build(); |
155 | ||
85984a87 | 156 | p.cargo("build").run(); |
51d23560 AC |
157 | |
158 | Package::new("log", "0.1.1").publish(); | |
159 | Package::new("serde", "0.1.1").dep("log", "0.1").publish(); | |
160 | ||
85984a87 DW |
161 | p.cargo("update -p serde") |
162 | .with_stderr( | |
51d23560 | 163 | "\ |
41aa6fba | 164 | [UPDATING] `[..]` index |
51d23560 AC |
165 | [UPDATING] serde v0.1.0 -> v0.1.1 |
166 | ", | |
fecb7246 AC |
167 | ) |
168 | .run(); | |
51d23560 AC |
169 | } |
170 | ||
171 | #[test] | |
172 | fn update_via_new_dep() { | |
173 | Package::new("log", "0.1.0").publish(); | |
7fe2fbc8 | 174 | let p = project() |
51d23560 AC |
175 | .file( |
176 | "Cargo.toml", | |
177 | r#" | |
178 | [package] | |
179 | name = "bar" | |
180 | version = "0.0.1" | |
181 | authors = [] | |
182 | ||
183 | [dependencies] | |
184 | log = "0.1" | |
185 | # foo = { path = "foo" } | |
186 | "#, | |
fecb7246 AC |
187 | ) |
188 | .file("src/lib.rs", "") | |
51d23560 AC |
189 | .file( |
190 | "foo/Cargo.toml", | |
191 | r#" | |
192 | [package] | |
193 | name = "foo" | |
194 | version = "0.0.1" | |
195 | authors = [] | |
196 | ||
197 | [dependencies] | |
198 | log = "0.1.1" | |
199 | "#, | |
fecb7246 AC |
200 | ) |
201 | .file("foo/src/lib.rs", "") | |
51d23560 AC |
202 | .build(); |
203 | ||
85984a87 | 204 | p.cargo("build").run(); |
51d23560 AC |
205 | Package::new("log", "0.1.1").publish(); |
206 | ||
207 | p.uncomment_root_manifest(); | |
85984a87 | 208 | p.cargo("build").env("RUST_LOG", "cargo=trace").run(); |
51d23560 AC |
209 | } |
210 | ||
211 | #[test] | |
212 | fn update_via_new_member() { | |
213 | Package::new("log", "0.1.0").publish(); | |
7fe2fbc8 | 214 | let p = project() |
51d23560 AC |
215 | .file( |
216 | "Cargo.toml", | |
217 | r#" | |
218 | [package] | |
219 | name = "bar" | |
220 | version = "0.0.1" | |
221 | authors = [] | |
222 | ||
223 | [workspace] | |
224 | # members = [ "foo" ] | |
225 | ||
226 | [dependencies] | |
227 | log = "0.1" | |
228 | "#, | |
fecb7246 AC |
229 | ) |
230 | .file("src/lib.rs", "") | |
51d23560 AC |
231 | .file( |
232 | "foo/Cargo.toml", | |
233 | r#" | |
234 | [package] | |
235 | name = "foo" | |
236 | version = "0.0.1" | |
237 | authors = [] | |
238 | ||
239 | [dependencies] | |
240 | log = "0.1.1" | |
241 | "#, | |
fecb7246 AC |
242 | ) |
243 | .file("foo/src/lib.rs", "") | |
51d23560 AC |
244 | .build(); |
245 | ||
85984a87 | 246 | p.cargo("build").run(); |
51d23560 AC |
247 | Package::new("log", "0.1.1").publish(); |
248 | ||
249 | p.uncomment_root_manifest(); | |
85984a87 | 250 | p.cargo("build").run(); |
51d23560 AC |
251 | } |
252 | ||
253 | #[test] | |
254 | fn add_dep_deep_new_requirement() { | |
255 | Package::new("log", "0.1.0").publish(); | |
7fe2fbc8 | 256 | let p = project() |
51d23560 AC |
257 | .file( |
258 | "Cargo.toml", | |
259 | r#" | |
260 | [package] | |
261 | name = "bar" | |
262 | version = "0.0.1" | |
263 | authors = [] | |
264 | ||
265 | [dependencies] | |
266 | log = "0.1" | |
267 | # bar = "0.1" | |
268 | "#, | |
fecb7246 AC |
269 | ) |
270 | .file("src/lib.rs", "") | |
51d23560 AC |
271 | .build(); |
272 | ||
85984a87 | 273 | p.cargo("build").run(); |
51d23560 AC |
274 | |
275 | Package::new("log", "0.1.1").publish(); | |
276 | Package::new("bar", "0.1.0").dep("log", "0.1.1").publish(); | |
277 | ||
278 | p.uncomment_root_manifest(); | |
85984a87 | 279 | p.cargo("build").run(); |
51d23560 AC |
280 | } |
281 | ||
282 | #[test] | |
283 | fn everything_real_deep() { | |
284 | Package::new("log", "0.1.0").publish(); | |
285 | Package::new("foo", "0.1.0").dep("log", "0.1").publish(); | |
7fe2fbc8 | 286 | let p = project() |
51d23560 AC |
287 | .file( |
288 | "Cargo.toml", | |
289 | r#" | |
290 | [package] | |
291 | name = "bar" | |
292 | version = "0.0.1" | |
293 | authors = [] | |
294 | ||
295 | [dependencies] | |
296 | foo = "0.1" | |
297 | # bar = "0.1" | |
298 | "#, | |
fecb7246 AC |
299 | ) |
300 | .file("src/lib.rs", "") | |
51d23560 AC |
301 | .build(); |
302 | ||
85984a87 | 303 | p.cargo("build").run(); |
51d23560 AC |
304 | |
305 | Package::new("log", "0.1.1").publish(); | |
306 | Package::new("bar", "0.1.0").dep("log", "0.1.1").publish(); | |
307 | ||
308 | p.uncomment_root_manifest(); | |
85984a87 | 309 | p.cargo("build").run(); |
51d23560 | 310 | } |
0deaae9e AC |
311 | |
312 | #[test] | |
313 | fn change_package_version() { | |
7fe2fbc8 | 314 | let p = project() |
0deaae9e AC |
315 | .file( |
316 | "Cargo.toml", | |
317 | r#" | |
318 | [package] | |
319 | name = "a-foo" | |
320 | version = "0.2.0-alpha" | |
321 | authors = [] | |
322 | ||
323 | [dependencies] | |
324 | bar = { path = "bar", version = "0.2.0-alpha" } | |
325 | "#, | |
fecb7246 AC |
326 | ) |
327 | .file("src/lib.rs", "") | |
ab19c483 | 328 | .file("bar/Cargo.toml", &basic_manifest("bar", "0.2.0-alpha")) |
0deaae9e AC |
329 | .file("bar/src/lib.rs", "") |
330 | .file( | |
331 | "Cargo.lock", | |
332 | r#" | |
333 | [[package]] | |
334 | name = "foo" | |
335 | version = "0.2.0" | |
336 | dependencies = ["bar 0.2.0"] | |
337 | ||
338 | [[package]] | |
339 | name = "bar" | |
340 | version = "0.2.0" | |
341 | "#, | |
fecb7246 AC |
342 | ) |
343 | .build(); | |
0deaae9e | 344 | |
85984a87 | 345 | p.cargo("build").run(); |
0deaae9e | 346 | } |
1a26e86c | 347 | |
348 | #[test] | |
349 | fn update_precise() { | |
350 | Package::new("log", "0.1.0").publish(); | |
351 | Package::new("serde", "0.1.0").publish(); | |
352 | Package::new("serde", "0.2.1").publish(); | |
353 | ||
7fe2fbc8 | 354 | let p = project() |
1a26e86c | 355 | .file( |
356 | "Cargo.toml", | |
357 | r#" | |
358 | [package] | |
359 | name = "bar" | |
360 | version = "0.0.1" | |
361 | authors = [] | |
362 | ||
363 | [dependencies] | |
364 | serde = "0.2" | |
365 | foo = { path = "foo" } | |
366 | "#, | |
fecb7246 AC |
367 | ) |
368 | .file("src/lib.rs", "") | |
1a26e86c | 369 | .file( |
370 | "foo/Cargo.toml", | |
371 | r#" | |
372 | [package] | |
373 | name = "foo" | |
374 | version = "0.0.1" | |
375 | authors = [] | |
376 | ||
377 | [dependencies] | |
378 | serde = "0.1" | |
379 | "#, | |
fecb7246 AC |
380 | ) |
381 | .file("foo/src/lib.rs", "") | |
1a26e86c | 382 | .build(); |
383 | ||
85984a87 | 384 | p.cargo("build").run(); |
1a26e86c | 385 | |
386 | Package::new("serde", "0.2.0").publish(); | |
387 | ||
85984a87 DW |
388 | p.cargo("update -p serde:0.2.1 --precise 0.2.0") |
389 | .with_stderr( | |
1a26e86c | 390 | "\ |
41aa6fba | 391 | [UPDATING] `[..]` index |
1a26e86c | 392 | [UPDATING] serde v0.2.1 -> v0.2.0 |
393 | ", | |
fecb7246 AC |
394 | ) |
395 | .run(); | |
1a26e86c | 396 | } |
851e20b2 | 397 | |
f299d1c1 AH |
398 | // cargo update should respect its arguments even without a lockfile. |
399 | // See issue "Running cargo update without a Cargo.lock ignores arguments" | |
400 | // at <https://github.com/rust-lang/cargo/issues/6872>. | |
401 | #[test] | |
402 | fn update_precise_first_run() { | |
403 | Package::new("serde", "0.1.0").publish(); | |
404 | Package::new("serde", "0.2.0").publish(); | |
405 | Package::new("serde", "0.2.1").publish(); | |
406 | ||
407 | let p = project() | |
408 | .file( | |
409 | "Cargo.toml", | |
410 | r#" | |
411 | [package] | |
412 | name = "bar" | |
413 | version = "0.0.1" | |
414 | ||
415 | [dependencies] | |
416 | serde = "0.2" | |
417 | "#, | |
418 | ) | |
419 | .file("src/lib.rs", "") | |
420 | .build(); | |
421 | ||
422 | p.cargo("update -p serde --precise 0.2.0") | |
423 | .with_stderr( | |
424 | "\ | |
425 | [UPDATING] `[..]` index | |
426 | ", | |
427 | ) | |
428 | .run(); | |
429 | ||
430 | // Assert `cargo metadata` shows serde 0.2.0 | |
431 | p.cargo("metadata") | |
432 | .with_json( | |
433 | r#"{ | |
434 | "packages": [ | |
435 | { | |
436 | "authors": [], | |
437 | "categories": [], | |
438 | "dependencies": [], | |
439 | "description": null, | |
440 | "edition": "2015", | |
441 | "features": {}, | |
442 | "id": "serde 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", | |
443 | "keywords": [], | |
444 | "license": null, | |
445 | "license_file": null, | |
446 | "links": null, | |
447 | "manifest_path": "[..]/home/.cargo/registry/src/-[..]/serde-0.2.0/Cargo.toml", | |
448 | "metadata": null, | |
449 | "name": "serde", | |
450 | "readme": null, | |
451 | "repository": null, | |
452 | "source": "registry+https://github.com/rust-lang/crates.io-index", | |
453 | "targets": [ | |
454 | { | |
455 | "crate_types": [ | |
456 | "lib" | |
457 | ], | |
458 | "edition": "2015", | |
459 | "kind": [ | |
460 | "lib" | |
461 | ], | |
462 | "name": "serde", | |
463 | "src_path": "[..]/home/.cargo/registry/src/-[..]/serde-0.2.0/src/lib.rs" | |
464 | } | |
465 | ], | |
466 | "version": "0.2.0" | |
467 | }, | |
468 | { | |
469 | "authors": [], | |
470 | "categories": [], | |
471 | "dependencies": [ | |
472 | { | |
473 | "features": [], | |
474 | "kind": null, | |
475 | "name": "serde", | |
476 | "optional": false, | |
477 | "registry": null, | |
478 | "rename": null, | |
479 | "req": "^0.2", | |
480 | "source": "registry+https://github.com/rust-lang/crates.io-index", | |
481 | "target": null, | |
482 | "uses_default_features": true | |
483 | } | |
484 | ], | |
485 | "description": null, | |
486 | "edition": "2015", | |
487 | "features": {}, | |
488 | "id": "bar 0.0.1 (path+file://[..]/foo)", | |
489 | "keywords": [], | |
490 | "license": null, | |
491 | "license_file": null, | |
492 | "links": null, | |
493 | "manifest_path": "[..]/foo/Cargo.toml", | |
494 | "metadata": null, | |
495 | "name": "bar", | |
496 | "readme": null, | |
497 | "repository": null, | |
498 | "source": null, | |
499 | "targets": [ | |
500 | { | |
501 | "crate_types": [ | |
502 | "lib" | |
503 | ], | |
504 | "edition": "2015", | |
505 | "kind": [ | |
506 | "lib" | |
507 | ], | |
508 | "name": "bar", | |
509 | "src_path": "[..]/foo/src/lib.rs" | |
510 | } | |
511 | ], | |
512 | "version": "0.0.1" | |
513 | } | |
514 | ], | |
515 | "resolve": { | |
516 | "nodes": [ | |
517 | { | |
518 | "dependencies": [ | |
519 | "serde 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" | |
520 | ], | |
521 | "deps": [ | |
522 | { | |
523 | "name": "serde", | |
524 | "pkg": "serde 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" | |
525 | } | |
526 | ], | |
527 | "features": [], | |
528 | "id": "bar 0.0.1 (path+file://[..]/foo)" | |
529 | }, | |
530 | { | |
531 | "dependencies": [], | |
532 | "deps": [], | |
533 | "features": [], | |
534 | "id": "serde 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" | |
535 | } | |
536 | ], | |
537 | "root": "bar 0.0.1 (path+file://[..]/foo)" | |
538 | }, | |
539 | "target_directory": "[..]/foo/target", | |
540 | "version": 1, | |
541 | "workspace_members": [ | |
542 | "bar 0.0.1 (path+file://[..]/foo)" | |
543 | ], | |
544 | "workspace_root": "[..]/foo" | |
545 | }"#, | |
546 | ) | |
547 | .run(); | |
548 | ||
549 | p.cargo("update -p serde --precise 0.2.0") | |
550 | .with_stderr( | |
551 | "\ | |
552 | [UPDATING] `[..]` index | |
553 | ", | |
554 | ) | |
555 | .run(); | |
556 | ||
557 | } | |
558 | ||
851e20b2 DW |
559 | #[test] |
560 | fn preserve_top_comment() { | |
561 | let p = project().file("src/lib.rs", "").build(); | |
562 | ||
563 | p.cargo("update").run(); | |
564 | ||
bd0e4a08 DW |
565 | let lockfile = p.read_lockfile(); |
566 | assert!(lockfile.starts_with("# This file is automatically @generated by Cargo.\n# It is not intended for manual editing.\n")); | |
567 | ||
568 | let mut lines = lockfile.lines().collect::<Vec<_>>(); | |
569 | lines.insert(2, "# some other comment"); | |
570 | let mut lockfile = lines.join("\n"); | |
571 | lockfile.push_str("\n"); // .lines/.join loses the last newline | |
851e20b2 DW |
572 | println!("saving Cargo.lock contents:\n{}", lockfile); |
573 | ||
574 | p.change_file("Cargo.lock", &lockfile); | |
575 | ||
576 | p.cargo("update").run(); | |
577 | ||
bd0e4a08 | 578 | let lockfile2 = p.read_lockfile(); |
851e20b2 DW |
579 | println!("loaded Cargo.lock contents:\n{}", lockfile2); |
580 | ||
bd0e4a08 | 581 | assert_eq!(lockfile, lockfile2); |
851e20b2 | 582 | } |
7be09e3c AK |
583 | |
584 | #[test] | |
585 | fn dry_run_update() { | |
586 | Package::new("log", "0.1.0").publish(); | |
587 | Package::new("serde", "0.1.0").dep("log", "0.1").publish(); | |
588 | ||
589 | let p = project() | |
590 | .file( | |
591 | "Cargo.toml", | |
592 | r#" | |
593 | [package] | |
594 | name = "bar" | |
595 | version = "0.0.1" | |
596 | authors = [] | |
597 | ||
598 | [dependencies] | |
599 | serde = "0.1" | |
600 | log = "0.1" | |
601 | foo = { path = "foo" } | |
602 | "#, | |
603 | ) | |
604 | .file("src/lib.rs", "") | |
605 | .file( | |
606 | "foo/Cargo.toml", | |
607 | r#" | |
608 | [package] | |
609 | name = "foo" | |
610 | version = "0.0.1" | |
611 | authors = [] | |
612 | ||
613 | [dependencies] | |
614 | serde = "0.1" | |
615 | "#, | |
616 | ) | |
617 | .file("foo/src/lib.rs", "") | |
618 | .build(); | |
619 | ||
620 | p.cargo("build").run(); | |
621 | let old_lockfile = p.read_file("Cargo.lock"); | |
622 | ||
623 | Package::new("log", "0.1.1").publish(); | |
624 | Package::new("serde", "0.1.1").dep("log", "0.1").publish(); | |
625 | ||
626 | p.cargo("update -p serde --dry-run") | |
627 | .with_stderr( | |
628 | "\ | |
629 | [UPDATING] `[..]` index | |
630 | [UPDATING] serde v0.1.0 -> v0.1.1 | |
631 | [WARNING] not updating lockfile due to dry run | |
632 | ", | |
633 | ) | |
634 | .run(); | |
635 | let new_lockfile = p.read_file("Cargo.lock"); | |
636 | assert_eq!(old_lockfile, new_lockfile) | |
637 | } |