1 //! Tests for `[patch]` table source replacement.
3 use cargo_test_support
::git
;
4 use cargo_test_support
::paths
;
5 use cargo_test_support
::registry
::{self, Package}
;
6 use cargo_test_support
::{basic_manifest, project}
;
11 Package
::new("bar", "0.1.0").publish();
12 Package
::new("baz", "0.1.0")
15 "extern crate bar; pub fn baz() { bar::bar(); }",
34 bar = { path = "bar" }
48 .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
49 .file("bar/src/lib.rs", "pub fn bar() {}")
55 [UPDATING] `dummy-registry` index
56 [DOWNLOADING] crates ...
57 [DOWNLOADED] baz v0.1.0 ([..])
58 [CHECKING] bar v0.1.0 ([CWD]/bar)
60 [CHECKING] foo v0.0.1 ([CWD])
61 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
66 p
.cargo("check").with_stderr("[FINISHED] [..]").run();
71 Package
::new("bar", "0.1.0").publish();
90 bar = { path = 'bar' }
93 .file("src/lib.rs", "")
94 .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.1"))
95 .file("bar/src/lib.rs", r
#""#)
101 [UPDATING] `dummy-registry` index
102 [CHECKING] bar v0.1.1 ([..])
103 [CHECKING] foo v0.0.1 ([CWD])
104 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
111 fn from_config_relative() {
112 Package
::new("bar", "0.1.0").publish();
128 "../.cargo/config.toml",
131 bar = { path = 'foo/bar' }
134 .file("src/lib.rs", "")
135 .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.1"))
136 .file("bar/src/lib.rs", r
#""#)
142 [UPDATING] `dummy-registry` index
143 [CHECKING] bar v0.1.1 ([..])
144 [CHECKING] foo v0.0.1 ([CWD])
145 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
152 fn from_config_precedence() {
153 Package
::new("bar", "0.1.0").publish();
168 bar = { path = 'no-such-path' }
172 ".cargo/config.toml",
175 bar = { path = 'bar' }
178 .file("src/lib.rs", "")
179 .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.1"))
180 .file("bar/src/lib.rs", r
#""#)
186 [UPDATING] `dummy-registry` index
187 [CHECKING] bar v0.1.1 ([..])
188 [CHECKING] foo v0.0.1 ([CWD])
189 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
197 Package
::new("baz", "0.1.0").publish();
212 bar = { path = "bar" }
217 "extern crate bar; pub fn foo() { bar::bar(); }",
219 .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
220 .file("bar/src/lib.rs", "pub fn bar() {}")
226 [UPDATING] `dummy-registry` index
227 [CHECKING] bar v0.1.0 ([CWD]/bar)
228 [CHECKING] foo v0.0.1 ([CWD])
229 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
233 p
.cargo("check").with_stderr("[FINISHED] [..]").run();
238 let bar
= git
::repo(&paths
::root().join("override"))
239 .file("Cargo.toml", &basic_manifest("bar", "0.1.0"))
240 .file("src/lib.rs", "")
254 bar = {{ git = '{}' }}
257 bar = {{ path = "bar" }}
264 "extern crate bar; pub fn foo() { bar::bar(); }",
266 .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
267 .file("bar/src/lib.rs", "pub fn bar() {}")
273 [UPDATING] git repository `file://[..]`
274 [CHECKING] bar v0.1.0 ([CWD]/bar)
275 [CHECKING] foo v0.0.1 ([CWD])
276 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
280 p
.cargo("check").with_stderr("[FINISHED] [..]").run();
285 let bar
= git
::repo(&paths
::root().join("override"))
286 .file("Cargo.toml", &basic_manifest("bar", "0.1.0"))
287 .file("src/lib.rs", "pub fn bar() {}")
290 Package
::new("bar", "0.1.0").publish();
306 bar = {{ git = '{}' }}
313 "extern crate bar; pub fn foo() { bar::bar(); }",
320 [UPDATING] git repository `file://[..]`
321 [UPDATING] `dummy-registry` index
322 [CHECKING] bar v0.1.0 (file://[..])
323 [CHECKING] foo v0.0.1 ([CWD])
324 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
328 p
.cargo("check").with_stderr("[FINISHED] [..]").run();
333 Package
::new("bar", "0.1.0").publish();
348 bar = { path = "bar" }
351 .file("src/lib.rs", "")
352 .file("bar/Cargo.toml", &basic_manifest("bar", "0.2.0"))
353 .file("bar/src/lib.rs", "not rust code")
359 [UPDATING] `dummy-registry` index
360 [WARNING] Patch `bar v0.2.0 ([CWD]/bar)` was not used in the crate graph.
365 [DOWNLOADING] crates ...
366 [DOWNLOADED] bar v0.1.0 [..]
367 [CHECKING] bar v0.1.0
368 [CHECKING] foo v0.0.1 ([CWD])
369 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
376 [WARNING] Patch `bar v0.2.0 ([CWD]/bar)` was not used in the crate graph.
386 // unused patch should be in the lock file
387 let lock
= p
.read_lockfile();
388 let toml
: toml
::Table
= toml
::from_str(&lock
).unwrap();
389 assert_eq
!(toml
["patch"]["unused"].as_array().unwrap().len(), 1);
390 assert_eq
!(toml
["patch"]["unused"][0]["name"].as_str(), Some("bar"));
392 toml
["patch"]["unused"][0]["version"].as_str(),
398 fn unused_with_mismatch_source_being_patched() {
399 registry
::alt_init();
400 Package
::new("bar", "0.1.0").publish();
415 bar = { path = "bar" }
418 bar = { path = "baz" }
421 .file("src/lib.rs", "")
422 .file("bar/Cargo.toml", &basic_manifest("bar", "0.2.0"))
423 .file("bar/src/lib.rs", "not rust code")
424 .file("baz/Cargo.toml", &basic_manifest("bar", "0.3.0"))
425 .file("baz/src/lib.rs", "not rust code")
431 [UPDATING] `dummy-registry` index
432 [WARNING] Patch `bar v0.2.0 ([CWD]/bar)` was not used in the crate graph.
433 Perhaps you misspelled the source URL being patched.
434 Possible URLs for `[patch.<URL>]`:
436 [WARNING] Patch `bar v0.3.0 ([CWD]/baz)` was not used in the crate graph.
441 [DOWNLOADING] crates ...
442 [DOWNLOADED] bar v0.1.0 [..]
443 [CHECKING] bar v0.1.0
444 [CHECKING] foo v0.0.1 ([CWD])
445 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
452 fn prefer_patch_version() {
453 Package
::new("bar", "0.1.2").publish();
468 bar = { path = "bar" }
471 .file("src/lib.rs", "")
472 .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.1"))
473 .file("bar/src/lib.rs", "")
479 [UPDATING] `dummy-registry` index
480 [CHECKING] bar v0.1.1 ([CWD]/bar)
481 [CHECKING] foo v0.0.1 ([CWD])
482 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
494 // there should be no patch.unused in the toml file
495 let lock
= p
.read_lockfile();
496 let toml
: toml
::Table
= toml
::from_str(&lock
).unwrap();
497 assert
!(toml
.get("patch").is_none());
501 fn unused_from_config() {
502 Package
::new("bar", "0.1.0").publish();
518 ".cargo/config.toml",
521 bar = { path = "bar" }
524 .file("src/lib.rs", "")
525 .file("bar/Cargo.toml", &basic_manifest("bar", "0.2.0"))
526 .file("bar/src/lib.rs", "not rust code")
532 [UPDATING] `dummy-registry` index
533 [WARNING] Patch `bar v0.2.0 ([CWD]/bar)` was not used in the crate graph.
538 [DOWNLOADING] crates ...
539 [DOWNLOADED] bar v0.1.0 [..]
540 [CHECKING] bar v0.1.0
541 [CHECKING] foo v0.0.1 ([CWD])
542 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
549 [WARNING] Patch `bar v0.2.0 ([CWD]/bar)` was not used in the crate graph.
559 // unused patch should be in the lock file
560 let lock
= p
.read_lockfile();
561 let toml
: toml
::Table
= toml
::from_str(&lock
).unwrap();
562 assert_eq
!(toml
["patch"]["unused"].as_array().unwrap().len(), 1);
563 assert_eq
!(toml
["patch"]["unused"][0]["name"].as_str(), Some("bar"));
565 toml
["patch"]["unused"][0]["version"].as_str(),
572 Package
::new("bar", "0.1.0").publish();
574 let foo
= git
::repo(&paths
::root().join("override"))
575 .file("Cargo.toml", &basic_manifest("bar", "0.2.0"))
576 .file("src/lib.rs", "")
593 bar = {{ git = '{}' }}
598 .file("src/lib.rs", "")
604 [UPDATING] git repository `file://[..]`
605 [UPDATING] `dummy-registry` index
606 [WARNING] Patch `bar v0.2.0 ([..])` was not used in the crate graph.
611 [DOWNLOADING] crates ...
612 [DOWNLOADED] bar v0.1.0 [..]
613 [CHECKING] bar v0.1.0
614 [CHECKING] foo v0.0.1 ([CWD])
615 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
622 [WARNING] Patch `bar v0.2.0 ([..])` was not used in the crate graph.
635 Package
::new("bar", "0.1.0").publish();
650 .file("src/lib.rs", "")
651 .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
652 .file("bar/src/lib.rs", r
#""#)
658 [UPDATING] `dummy-registry` index
659 [DOWNLOADING] crates ...
660 [DOWNLOADED] bar v0.1.0 [..]
661 [CHECKING] bar v0.1.0
662 [CHECKING] foo v0.0.1 ([CWD])
663 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
667 p
.cargo("check").with_stderr("[FINISHED] [..]").run();
681 bar = { path = 'bar' }
688 [CHECKING] bar v0.1.0 ([CWD]/bar)
689 [CHECKING] foo v0.0.1 ([CWD])
690 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
694 p
.cargo("check").with_stderr("[FINISHED] [..]").run();
698 fn add_patch_from_config() {
699 Package
::new("bar", "0.1.0").publish();
714 .file("src/lib.rs", "")
715 .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
716 .file("bar/src/lib.rs", r
#""#)
722 [UPDATING] `dummy-registry` index
723 [DOWNLOADING] crates ...
724 [DOWNLOADED] bar v0.1.0 [..]
725 [CHECKING] bar v0.1.0
726 [CHECKING] foo v0.0.1 ([CWD])
727 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
731 p
.cargo("check").with_stderr("[FINISHED] [..]").run();
734 ".cargo/config.toml",
737 bar = { path = 'bar' }
744 [CHECKING] bar v0.1.0 ([CWD]/bar)
745 [CHECKING] foo v0.0.1 ([CWD])
746 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
750 p
.cargo("check").with_stderr("[FINISHED] [..]").run();
754 fn add_ignored_patch() {
755 Package
::new("bar", "0.1.0").publish();
770 .file("src/lib.rs", "")
771 .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.1"))
772 .file("bar/src/lib.rs", r
#""#)
778 [UPDATING] `dummy-registry` index
779 [DOWNLOADING] crates ...
780 [DOWNLOADED] bar v0.1.0 [..]
781 [CHECKING] bar v0.1.0
782 [CHECKING] foo v0.0.1 ([CWD])
783 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
787 p
.cargo("check").with_stderr("[FINISHED] [..]").run();
801 bar = { path = 'bar' }
808 [WARNING] Patch `bar v0.1.1 ([CWD]/bar)` was not used in the crate graph.
813 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]",
819 [WARNING] Patch `bar v0.1.1 ([CWD]/bar)` was not used in the crate graph.
828 p
.cargo("update").run();
832 [CHECKING] bar v0.1.1 ([CWD]/bar)
833 [CHECKING] foo v0.0.1 ([CWD])
841 fn add_patch_with_features() {
842 Package
::new("bar", "0.1.0").publish();
857 bar = { path = 'bar', features = ["some_feature"] }
860 .file("src/lib.rs", "")
861 .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
862 .file("bar/src/lib.rs", r
#""#)
868 [WARNING] patch for `bar` uses the features mechanism. \
869 default-features and features will not take effect because the patch dependency does not support this mechanism
870 [UPDATING] `dummy-registry` index
871 [CHECKING] bar v0.1.0 ([CWD]/bar)
872 [CHECKING] foo v0.0.1 ([CWD])
873 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
880 [WARNING] patch for `bar` uses the features mechanism. \
881 default-features and features will not take effect because the patch dependency does not support this mechanism
889 fn add_patch_with_setting_default_features() {
890 Package
::new("bar", "0.1.0").publish();
905 bar = { path = 'bar', default-features = false, features = ["none_default_feature"] }
908 .file("src/lib.rs", "")
909 .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
910 .file("bar/src/lib.rs", r
#""#)
916 [WARNING] patch for `bar` uses the features mechanism. \
917 default-features and features will not take effect because the patch dependency does not support this mechanism
918 [UPDATING] `dummy-registry` index
919 [CHECKING] bar v0.1.0 ([CWD]/bar)
920 [CHECKING] foo v0.0.1 ([CWD])
921 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
928 [WARNING] patch for `bar` uses the features mechanism. \
929 default-features and features will not take effect because the patch dependency does not support this mechanism
937 fn no_warn_ws_patch() {
938 Package
::new("c", "0.1.0").publish();
940 // Don't issue an unused patch warning when the patch isn't used when
941 // partially building a workspace.
947 members = ["a", "b", "c"]
953 .file("a/Cargo.toml", &basic_manifest("a", "0.1.0"))
954 .file("a/src/lib.rs", "")
965 .file("b/src/lib.rs", "")
966 .file("c/Cargo.toml", &basic_manifest("c", "0.1.0"))
967 .file("c/src/lib.rs", "")
970 p
.cargo("check -p a")
982 Package
::new("bar", "0.1.0").publish();
997 bar = { path = 'bar' }
1000 .file("src/lib.rs", "")
1001 .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.1"))
1002 .file("bar/src/lib.rs", r
#""#)
1008 [UPDATING] `dummy-registry` index
1009 [CHECKING] bar v0.1.1 [..]
1010 [CHECKING] foo v0.0.1 ([CWD])
1011 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
1018 fn transitive_new_minor() {
1019 Package
::new("baz", "0.1.0").publish();
1031 bar = { path = 'bar' }
1034 baz = { path = 'baz' }
1037 .file("src/lib.rs", "")
1050 .file("bar/src/lib.rs", r
#""#)
1051 .file("baz/Cargo.toml", &basic_manifest("baz", "0.1.1"))
1052 .file("baz/src/lib.rs", r
#""#)
1058 [UPDATING] `dummy-registry` index
1059 [CHECKING] baz v0.1.1 [..]
1060 [CHECKING] bar v0.1.0 [..]
1061 [CHECKING] foo v0.0.1 ([CWD])
1062 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
1070 Package
::new("bar", "0.1.0").publish();
1085 bar = { path = 'bar' }
1088 .file("src/lib.rs", "")
1089 .file("bar/Cargo.toml", &basic_manifest("bar", "0.2.0"))
1090 .file("bar/src/lib.rs", r
#""#)
1096 [UPDATING] `dummy-registry` index
1097 [CHECKING] bar v0.2.0 [..]
1098 [CHECKING] foo v0.0.1 ([CWD])
1099 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
1104 Package
::new("bar", "0.2.0").publish();
1105 p
.cargo("update").run();
1107 .with_stderr("[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]")
1125 [UPDATING] `dummy-registry` index
1126 [DOWNLOADING] crates ...
1127 [DOWNLOADED] bar v0.2.0 [..]
1128 [CHECKING] bar v0.2.0
1129 [CHECKING] foo v0.0.1 ([CWD])
1130 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
1137 fn transitive_new_major() {
1138 Package
::new("baz", "0.1.0").publish();
1150 bar = { path = 'bar' }
1153 baz = { path = 'baz' }
1156 .file("src/lib.rs", "")
1169 .file("bar/src/lib.rs", r
#""#)
1170 .file("baz/Cargo.toml", &basic_manifest("baz", "0.2.0"))
1171 .file("baz/src/lib.rs", r
#""#)
1177 [UPDATING] `dummy-registry` index
1178 [CHECKING] baz v0.2.0 [..]
1179 [CHECKING] bar v0.1.0 [..]
1180 [CHECKING] foo v0.0.1 ([CWD])
1181 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
1188 fn shared_by_transitive() {
1189 Package
::new("baz", "0.1.1").publish();
1191 let baz
= git
::repo(&paths
::root().join("override"))
1192 .file("Cargo.toml", &basic_manifest("baz", "0.1.2"))
1193 .file("src/lib.rs", "")
1206 bar = {{ path = "bar" }}
1210 baz = {{ git = "{}", version = "0.1" }}
1215 .file("src
/lib
.rs
", "")
1227 .file("bar
/src
/lib
.rs
", "")
1233 [UPDATING
] git repository `file
://[..]`
1234 [UPDATING
] `dummy
-registry` index
1235 [CHECKING
] baz v0
.1
.2 [..]
1236 [CHECKING
] bar v0
.1
.0 [..]
1237 [CHECKING
] foo v0
.1
.0 ([CWD
])
1238 [FINISHED
] dev
[unoptimized
+ debuginfo
] target(s
) in [..]
1246 Package::new("foo
", "0.1.0").publish();
1247 Package::new("bar
", "0.1.0").publish();
1262 foo
= { path = 'foo' }
1263 bar
= { path = 'bar' }
1266 .file("src
/lib
.rs
", "")
1267 .file("bar
/Cargo
.toml
", &basic_manifest("bar
", "0.1.0"))
1268 .file("bar
/src
/lib
.rs
", r#""#)
1269 .file("foo
/Cargo
.toml
", &basic_manifest("foo
", "0.1.0"))
1270 .file("foo
/src
/lib
.rs
", r#""#)
1273 // Generate a lock file where `foo` is unused
1274 p.cargo("check
").run();
1275 let lock_file1 = p.read_lockfile();
1277 // Remove `foo` and generate a new lock file form the old one
1290 bar
= { path = 'bar' }
1293 p.cargo("check
").run();
1294 let lock_file2 = p.read_lockfile();
1296 // Remove the lock file and build from scratch
1297 fs::remove_file(p.root().join("Cargo
.lock
")).unwrap();
1298 p.cargo("check
").run();
1299 let lock_file3 = p.read_lockfile();
1301 assert!(lock_file1.contains("foo
"));
1302 assert_eq!(lock_file2, lock_file3);
1303 assert_ne!(lock_file1, lock_file2);
1307 fn non_crates_io() {
1308 Package::new("bar
", "0.1.0").publish();
1319 [patch
.some
-other
-source
]
1320 bar
= { path = 'bar' }
1323 .file("src
/lib
.rs
", "")
1324 .file("bar
/Cargo
.toml
", &basic_manifest("bar
", "0.1.0"))
1325 .file("bar
/src
/lib
.rs
", r#""#)
1332 error
: failed to parse manifest at `
[..]`
1335 [patch
] entry `some
-other
-source` should be a URL or registry name
1338 invalid url `some
-other
-source`
: relative URL without a base
1345 fn replace_with_crates_io() {
1346 Package::new("bar
", "0.1.0").publish();
1361 .file("src
/lib
.rs
", "")
1362 .file("bar
/Cargo
.toml
", &basic_manifest("bar
", "0.1.0"))
1363 .file("bar
/src
/lib
.rs
", r#""#)
1371 error
: failed to resolve patches
for `
[..]`
1374 patch
for `bar`
in `
[..]` points to the same source
, but patches must point
\
1375 to different sources
1382 fn patch_in_virtual() {
1383 Package::new("bar
", "0.1.0").publish();
1393 bar
= { path = "bar" }
1396 .file("bar
/Cargo
.toml
", &basic_manifest("bar
", "0.1.0"))
1397 .file("bar
/src
/lib
.rs
", r#""#)
1410 .file("foo
/src
/lib
.rs
", r#""#)
1413 p.cargo("check
").run();
1414 p.cargo("check
").with_stderr("[FINISHED
] [..]").run();
1418 fn patch_depends_on_another_patch() {
1419 Package::new("bar
", "0.1.0")
1420 .file("src
/lib
.rs
", "broken code
")
1423 Package::new("baz
", "0.1.0")
1425 .file("src
/lib
.rs
", "broken code
")
1442 bar
= { path = "bar" }
1443 baz
= { path = "baz" }
1446 .file("src
/lib
.rs
", "")
1447 .file("bar
/Cargo
.toml
", &basic_manifest("bar
", "0.1.1"))
1448 .file("bar
/src
/lib
.rs
", r#""#)
1461 .file("baz
/src
/lib
.rs
", r#""#)
1464 p.cargo("check
").run();
1466 // Nothing should be rebuilt, no registry should be updated.
1467 p.cargo("check
").with_stderr("[FINISHED
] [..]").run();
1471 fn replace_prerelease() {
1472 Package::new("baz
", "1.1.0-pre
.1").publish();
1481 baz
= { path = "./baz" }
1498 "extern crate baz
; fn main() { baz::baz() }
",
1505 version
= "1.1.0-pre.1"
1510 .file("baz
/src
/lib
.rs
", "pub fn baz() {}
")
1513 p.cargo("check
").run();
1518 Package::new("baz
", "1.0.2").publish();
1529 bar
= { path = 'bar' }
1533 baz
= { path = "./baz" }
1536 .file("src
/lib
.rs
", "")
1549 .file("bar
/src
/lib
.rs
", "")
1559 .file("baz
/src
/lib
.rs
", "")
1566 [CHECKING
] baz v1
.0
.1 [..]
1567 [CHECKING
] bar v0
.5
.0 [..]
1568 [CHECKING
] foo v0
.1
.0 [..]
1577 Package::new("a
", "1.0.0").publish();
1578 Package::new("b
", "1.0.0").publish();
1584 members
= ["a", "b"]
1602 .file("a
/src
/lib
.rs
", "")
1614 .file("b
/src
/lib
.rs
", "")
1622 [ERROR
] cyclic package dependency
: [..]
1624 ... which satisfies dependency `
[..]` of package `
[..]`
1625 ... which satisfies dependency `
[..]` of package `
[..]`
1633 Package::new("a
", "1.0.0").publish();
1634 Package::new("a
", "2.0.0").publish();
1644 a1
= { version = "1", package = "a" }
1645 a2
= { version = "2", package = "a" }
1648 b1
= { path = "a1", package = "a" }
1649 b2
= { path = "a2", package = "a" }
1652 .file("src
/lib
.rs
", "pub fn foo() { a1::f1(); a2::f2(); }
")
1661 .file("a1
/src
/lib
.rs
", "pub fn f1() {}
")
1670 .file("a2
/src
/lib
.rs
", "pub fn f2() {}
")
1673 p.cargo("check
").run();
1677 fn patch_same_version() {
1678 let bar = git::repo(&paths::root().join("override"))
1679 .file("Cargo
.toml
", &basic_manifest("bar
", "0.1.0"))
1680 .file("src
/lib
.rs
", "")
1683 cargo_test_support::registry::init();
1696 bar
= {{ path = "bar" }
}
1697 bar2
= {{ git = '{}'
, package
= 'bar'
}}
1702 .file("src
/lib
.rs
", "")
1711 .file("bar
/src
/lib
.rs
", "")
1719 error
: cannot have two `
[patch
]` entries which both resolve to `bar v0
.1
.0`
1726 fn two_semver_compatible() {
1727 let bar = git::repo(&paths::root().join("override"))
1728 .file("Cargo
.toml
", &basic_manifest("bar
", "0.1.1"))
1729 .file("src
/lib
.rs
", "")
1732 cargo_test_support::registry::init();
1745 bar
= {{ path = "bar" }
}
1746 bar2
= {{ git = '{}'
, package
= 'bar'
}}
1751 .file("src
/lib
.rs
", "pub fn foo() { bar::foo() }
")
1760 .file("bar
/src
/lib
.rs
", "pub fn foo() {}
")
1763 // assert the build succeeds and doesn't panic anywhere, and then afterwards
1764 // assert that the build succeeds again without updating anything or
1765 // building anything else.
1766 p.cargo("check
").run();
1770 warning
: Patch `bar v0
.1
.1 [..]` was not used
in the
crate graph
.
1771 Perhaps you misspelled the source URL being patched
.
1772 Possible URLs
for `
[patch
.<URL
>]`
:
1780 fn multipatch_select_big() {
1781 let bar = git::repo(&paths::root().join("override"))
1782 .file("Cargo
.toml
", &basic_manifest("bar
", "0.1.0"))
1783 .file("src
/lib
.rs
", "")
1786 cargo_test_support::registry::init();
1799 bar
= {{ path = "bar" }
}
1800 bar2
= {{ git = '{}'
, package
= 'bar'
}}
1805 .file("src
/lib
.rs
", "pub fn foo() { bar::foo() }
")
1814 .file("bar
/src
/lib
.rs
", "pub fn foo() {}
")
1817 // assert the build succeeds, which is only possible if 0.2.0 is selected
1818 // since 0.1.0 is missing the function we need. Afterwards assert that the
1819 // build succeeds again without updating anything or building anything else.
1820 p.cargo("check
").run();
1824 warning
: Patch `bar v0
.1
.0 [..]` was not used
in the
crate graph
.
1825 Perhaps you misspelled the source URL being patched
.
1826 Possible URLs
for `
[patch
.<URL
>]`
:
1834 fn canonicalize_a_bunch() {
1835 let base = git::repo(&paths::root().join("base
"))
1836 .file("Cargo
.toml
", &basic_manifest("base
", "0.1.0"))
1837 .file("src
/lib
.rs
", "")
1840 let intermediate = git::repo(&paths::root().join("intermediate
"))
1846 name
= "intermediate"
1850 # Note the lack of trailing slash
1851 base
= {{ git = '{}'
}}
1856 .file("src
/lib
.rs
", "pub fn f() { base::f() }
")
1859 let newbase = git::repo(&paths::root().join("newbase
"))
1860 .file("Cargo
.toml
", &basic_manifest("base
", "0.1.0"))
1861 .file("src
/lib
.rs
", "pub fn f() {}
")
1874 # Note the trailing slashes
1875 base
= {{ git = '{base}
/'
}}
1876 intermediate
= {{ git = '{intermediate}
/'
}}
1878 [patch
.'{base}'
] # Note the lack of trailing slash
1879 base
= {{ git = '{newbase}'
}}
1882 intermediate = intermediate.url(),
1883 newbase = newbase.url(),
1886 .file("src
/lib
.rs
", "pub fn a() { base::f(); intermediate::f() }
")
1889 // Once to make sure it actually works
1890 p.cargo("check
").run();
1892 // Then a few more times for good measure to ensure no weird warnings about
1893 // `[patch]` are printed.
1894 p.cargo("check
").with_stderr("[FINISHED
] [..]").run();
1895 p.cargo("check
").with_stderr("[FINISHED
] [..]").run();
1899 fn update_unused_new_version() {
1900 // If there is an unused patch entry, and then you update the patch,
1901 // make sure `cargo update` will be able to fix the lock file.
1902 Package::new("bar
", "0.1.5").publish();
1904 // Start with a lock file to 0.1.5, and an "unused
" patch because the
1905 // version is too old.
1918 bar
= { path = "../bar" }
1921 .file("src
/lib
.rs
", "")
1924 // Patch is too old.
1927 .file("Cargo
.toml
", &basic_manifest("bar
", "0.1.4"))
1928 .file("src
/lib
.rs
", "")
1932 .with_stderr_contains("[WARNING
] Patch `bar v0
.1
.4 [..] was not used
in the
crate graph
.")
1934 // unused patch should be in the lock file
1935 let lock = p.read_lockfile();
1936 let toml: toml::Table = toml::from_str(&lock).unwrap();
1937 assert_eq!(toml["patch
"]["unused
"].as_array().unwrap().len(), 1);
1938 assert_eq!(toml["patch
"]["unused
"][0]["name
"].as_str(), Some("bar
"));
1940 toml["patch
"]["unused
"][0]["version
"].as_str(),
1944 // Oh, OK, let's update to the latest version.
1945 bar.change_file("Cargo
.toml
", &basic_manifest("bar
", "0.1.6"));
1947 // Create a backup so we can test it with different options.
1948 fs::copy(p.root().join("Cargo
.lock
"), p.root().join("Cargo
.lock
.bak
")).unwrap();
1950 // Try to build again, this should automatically update Cargo.lock.
1954 [UPDATING
] `dummy
-registry` index
1955 [CHECKING
] bar v0
.1
.6 ([..]/bar
)
1956 [CHECKING
] foo v0
.0
.1 ([..]/foo
)
1961 // This should not update any registry.
1962 p.cargo("check
").with_stderr("[FINISHED
] [..]").run();
1963 assert!(!p.read_lockfile().contains("unused
"));
1965 // Restore the lock file, and see if `update` will work, too.
1966 fs::copy(p.root().join("Cargo
.lock
.bak
"), p.root().join("Cargo
.lock
")).unwrap();
1969 p.cargo("update
-p bar
")
1972 [UPDATING
] `dummy
-registry` index
1973 [ADDING
] bar v0
.1
.6 ([..]/bar
)
1974 [REMOVING
] bar v0
.1
.5
1979 // Try with bare `cargo update`.
1980 fs::copy(p.root().join("Cargo
.lock
.bak
"), p.root().join("Cargo
.lock
")).unwrap();
1984 [UPDATING
] `dummy
-registry` index
1985 [ADDING
] bar v0
.1
.6 ([..]/bar
)
1986 [REMOVING
] bar v0
.1
.5
1993 fn too_many_matches() {
1994 // The patch locations has multiple versions that match.
1995 registry::alt_init();
1996 Package::new("bar
", "0.1.0").publish();
1997 Package::new("bar
", "0.1.0").alternative(true).publish();
1998 Package::new("bar
", "0.1.1").alternative(true).publish();
2012 bar
= { version = "0.1", registry = "alternative" }
2015 .file("src
/lib
.rs
", "")
2018 // Picks 0.1.1, the most recent version.
2023 [UPDATING
] `alternative` index
2024 [ERROR
] failed to resolve patches
for `https
://github.com/rust-lang/crates.io-index`
2027 patch
for `bar`
in `https
://github.com/rust-lang/crates.io-index` failed to resolve
2030 patch
for `bar`
in `registry `alternative`` resolved to more than one candidate
2031 Found versions
: 0.1.0, 0.1.1
2032 Update the patch definition to select only one package
.
2033 For example
, add an `
=` version requirement to the patch definition
, such
as `version
= \"=0.1.1\"`
.
2041 // A patch to a location that does not contain the named package.
2054 bar
= { path = "bar" }
2057 .file("src
/lib
.rs
", "")
2058 .file("bar
/Cargo
.toml
", &basic_manifest("abc
", "0.1.0"))
2059 .file("bar
/src
/lib
.rs
", "")
2066 error
: failed to resolve patches
for `https
://github.com/rust-lang/crates.io-index`
2069 patch
for `bar`
in `https
://github.com/rust-lang/crates.io-index` failed to resolve
2072 The patch location `
[..]/foo
/bar` does not appear to contain any packages matching the name `bar`
.
2079 fn mismatched_version() {
2080 // A patch to a location that has an old version.
2093 bar
= { path = "bar", version = "0.1.1" }
2096 .file("src
/lib
.rs
", "")
2097 .file("bar
/Cargo
.toml
", &basic_manifest("bar
", "0.1.0"))
2098 .file("bar
/src
/lib
.rs
", "")
2105 [ERROR
] failed to resolve patches
for `https
://github.com/rust-lang/crates.io-index`
2108 patch
for `bar`
in `https
://github.com/rust-lang/crates.io-index` failed to resolve
2111 The patch location `
[..]/foo
/bar` contains a `bar` package with version `
0.1.0`
, \
2112 but the patch definition requires `^
0.1.1`
.
2113 Check that the version
in the patch location is what you expect
, \
2114 and update the patch definition to
match.
2121 fn patch_walks_backwards() {
2122 // Starting with a locked patch, change the patch so it points to an older version.
2123 Package::new("bar
", "0.1.0").publish();
2140 .file("src
/lib
.rs
", "")
2141 .file("bar
/Cargo
.toml
", &basic_manifest("bar
", "0.1.1"))
2142 .file("bar
/src
/lib
.rs
", "")
2148 [UPDATING
] `dummy
-registry` index
2149 [CHECKING
] bar v0
.1
.1 ([..]/foo
/bar
)
2150 [CHECKING
] foo v0
.1
.0 ([..]/foo
)
2156 // Somehow the user changes the version backwards.
2157 p.change_file("bar
/Cargo
.toml
", &basic_manifest("bar
", "0.1.0"));
2162 [UPDATING
] `dummy
-registry` index
2163 [CHECKING
] bar v0
.1
.0 ([..]/foo
/bar
)
2164 [CHECKING
] foo v0
.1
.0 ([..]/foo
)
2172 fn patch_walks_backwards_restricted() {
2173 // This is the same as `patch_walks_backwards`, but the patch contains a
2174 // `version` qualifier. This is unusual, just checking a strange edge case.
2175 Package::new("bar
", "0.1.0").publish();
2189 bar
= {path="bar", version="0.1.1"}
2192 .file("src
/lib
.rs
", "")
2193 .file("bar
/Cargo
.toml
", &basic_manifest("bar
", "0.1.1"))
2194 .file("bar
/src
/lib
.rs
", "")
2200 [UPDATING
] `dummy
-registry` index
2201 [CHECKING
] bar v0
.1
.1 ([..]/foo
/bar
)
2202 [CHECKING
] foo v0
.1
.0 ([..]/foo
)
2208 // Somehow the user changes the version backwards.
2209 p.change_file("bar
/Cargo
.toml
", &basic_manifest("bar
", "0.1.0"));
2215 error
: failed to resolve patches
for `https
://github.com/rust-lang/crates.io-index`
2218 patch
for `bar`
in `https
://github.com/rust-lang/crates.io-index` failed to resolve
2221 The patch location `
[..]/foo
/bar` contains a `bar` package with version `
0.1.0`
, but the patch definition requires `^
0.1.1`
.
2222 Check that the version
in the patch location is what you expect
, and update the patch definition to
match.
2229 fn patched_dep_new_version() {
2230 // What happens when a patch is locked, and then one of the patched
2231 // dependencies needs to be updated. In this case, the baz requirement
2232 // gets updated from 0.1.0 to 0.1.1.
2233 Package::new("bar
", "0.1.0").dep("baz
", "0.1.0").publish();
2234 Package::new("baz
", "0.1.0").publish();
2251 .file("src
/lib
.rs
", "")
2263 .file("bar
/src
/lib
.rs
", "")
2270 [UPDATING
] `dummy
-registry` index
2271 [DOWNLOADING
] crates
...
2272 [DOWNLOADED
] baz v0
.1
.0 [..]
2273 [CHECKING
] baz v0
.1
.0
2274 [CHECKING
] bar v0
.1
.0 ([..]/foo
/bar
)
2275 [CHECKING
] foo v0
.1
.0 ([..]/foo
)
2281 Package::new("baz
", "0.1.1").publish();
2283 // Just the presence of the new version should not have changed anything.
2284 p.cargo("check
").with_stderr("[FINISHED
] [..]").run();
2286 // Modify the patch so it requires the new version.
2299 // Should unlock and update cleanly.
2303 [UPDATING
] `dummy
-registry` index
2304 [DOWNLOADING
] crates
...
2305 [DOWNLOADED
] baz v0
.1
.1 (registry `dummy
-registry`
)
2306 [CHECKING
] baz v0
.1
.1
2307 [CHECKING
] bar v0
.1
.0 ([..]/foo
/bar
)
2308 [CHECKING
] foo v0
.1
.0 ([..]/foo
)
2316 fn patch_update_doesnt_update_other_sources() {
2317 // Very extreme edge case, make sure a patch update doesn't update other
2319 registry::alt_init();
2320 Package::new("bar
", "0.1.0").publish();
2321 Package::new("bar
", "0.1.0").alternative(true).publish();
2333 bar_alt
= { version = "0.1", registry = "alternative", package = "bar" }
2336 bar
= { path = "bar" }
2339 .file("src
/lib
.rs
", "")
2340 .file("bar
/Cargo
.toml
", &basic_manifest("bar
", "0.1.0"))
2341 .file("bar
/src
/lib
.rs
", "")
2345 .with_stderr_unordered(
2347 [UPDATING
] `dummy
-registry` index
2348 [UPDATING
] `alternative` index
2349 [DOWNLOADING
] crates
...
2350 [DOWNLOADED
] bar v0
.1
.0 (registry `alternative`
)
2351 [CHECKING
] bar v0
.1
.0 (registry `alternative`
)
2352 [CHECKING
] bar v0
.1
.0 ([..]/foo
/bar
)
2353 [CHECKING
] foo v0
.1
.0 ([..]/foo
)
2359 // Publish new versions in both sources.
2360 Package::new("bar
", "0.1.1").publish();
2361 Package::new("bar
", "0.1.1").alternative(true).publish();
2363 // Since it is locked, nothing should change.
2364 p.cargo("check
").with_stderr("[FINISHED
] [..]").run();
2366 // Require new version on crates.io.
2367 p.change_file("bar
/Cargo
.toml
", &basic_manifest("bar
", "0.1.1"));
2369 // This should not update bar_alt.
2373 [UPDATING
] `dummy
-registry` index
2374 [CHECKING
] bar v0
.1
.1 ([..]/foo
/bar
)
2375 [CHECKING
] foo v0
.1
.0 ([..]/foo
)
2383 fn can_update_with_alt_reg() {
2384 // A patch to an alt reg can update.
2385 registry::alt_init();
2386 Package::new("bar
", "0.1.0").publish();
2387 Package::new("bar
", "0.1.0").alternative(true).publish();
2388 Package::new("bar
", "0.1.1").alternative(true).publish();
2402 bar
= { version = "=0.1.1", registry = "alternative" }
2405 .file("src
/lib
.rs
", "")
2411 [UPDATING
] `alternative` index
2412 [UPDATING
] `dummy
-registry` index
2413 [DOWNLOADING
] crates
...
2414 [DOWNLOADED
] bar v0
.1
.1 (registry `alternative`
)
2415 [CHECKING
] bar v0
.1
.1 (registry `alternative`
)
2416 [CHECKING
] foo v0
.1
.0 ([..]/foo
)
2422 Package::new("bar
", "0.1.2").alternative(true).publish();
2424 // Should remain locked.
2425 p.cargo("check
").with_stderr("[FINISHED
] [..]").run();
2427 // This does nothing, due to `=` requirement.
2428 p.cargo("update
-p bar
")
2431 [UPDATING
] `alternative` index
2432 [UPDATING
] `dummy
-registry` index
2449 bar
= { version = "=0.1.2", registry = "alternative" }
2456 [UPDATING
] `alternative` index
2457 [UPDATING
] `dummy
-registry` index
2458 [DOWNLOADING
] crates
...
2459 [DOWNLOADED
] bar v0
.1
.2 (registry `alternative`
)
2460 [CHECKING
] bar v0
.1
.2 (registry `alternative`
)
2461 [CHECKING
] foo v0
.1
.0 ([..]/foo
)
2469 fn old_git_patch() {
2470 // Example where an old lockfile with an explicit branch="master
" in Cargo.toml.
2471 Package::new("bar
", "1.0.0").publish();
2472 let (bar, bar_repo) = git::new_repo("bar
", |p| {
2473 p.file("Cargo
.toml
", &basic_manifest("bar
", "1.0.0"))
2474 .file("src
/lib
.rs
", "")
2477 let bar_oid = bar_repo.head().unwrap().target().unwrap();
2492 bar
= {{ git = "{}
", branch = "master
" }}
2501 # This file is automatically @generated by Cargo.
2502 # It is not intended for manual editing.
2506 source = "git+{}#{}"
2519 .file("src/lib.rs", "")
2522 bar
.change_file("Cargo.toml", &basic_manifest("bar", "2.0.0"));
2523 git
::add(&bar_repo
);
2524 git
::commit(&bar_repo
);
2526 // This *should* keep the old lock.
2528 // .env("CARGO_LOG", "trace")
2535 .with_stdout(format
!(
2538 └── bar v1.0.0 (file:///[..]branch=master#{})
2540 &bar_oid
.to_string()[..8]
2545 // From https://github.com/rust-lang/cargo/issues/7463
2547 fn patch_eq_conflict_panic() {
2548 Package
::new("bar", "0.1.0").publish();
2549 Package
::new("bar", "0.1.1").publish();
2568 .file("src/lib.rs", "")
2569 .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.1"))
2570 .file("bar/src/lib.rs", "")
2573 p
.cargo("generate-lockfile")
2576 r
#"[UPDATING] `dummy-registry` index
2577 [ERROR] failed to select a version for `bar`.
2578 ... required by package `foo v0.1.0 ([..])`
2579 versions that meet the requirements `=0.1.1` are: 0.1.1
2581 all possible versions conflict with previously selected packages.
2583 previously selected package `bar v0.1.0`
2584 ... which satisfies dependency `bar = "=0.1.0"` of package `foo v0.1.0 ([..])`
2586 failed to select a version for `bar` which could resolve this conflict
2592 // From https://github.com/rust-lang/cargo/issues/11336
2594 fn mismatched_version2() {
2595 Package
::new("qux", "0.1.0-beta.1").publish();
2596 Package
::new("qux", "0.1.0-beta.2").publish();
2597 Package
::new("bar", "0.1.0")
2598 .dep("qux", "=0.1.0-beta.1")
2610 qux = "0.1.0-beta.2"
2613 qux = { path = "qux" }
2616 .file("src/lib.rs", "")
2622 version = "0.1.0-beta.1"
2625 .file("qux/src/lib.rs", "")
2628 p
.cargo("generate-lockfile")
2631 r
#"[UPDATING] `dummy-registry` index
2632 [ERROR] failed to select a version for `qux`.
2633 ... required by package `bar v0.1.0`
2634 ... which satisfies dependency `bar = "^0.1.0"` of package `foo v0.1.0 ([..])`
2635 versions that meet the requirements `=0.1.0-beta.1` are: 0.1.0-beta.1
2637 all possible versions conflict with previously selected packages.
2639 previously selected package `qux v0.1.0-beta.2`
2640 ... which satisfies dependency `qux = "^0.1.0-beta.2"` of package `foo v0.1.0 ([..])`
2642 failed to select a version for `qux` which could resolve this conflict"#,