mirror of
https://github.com/rust-lang/cargo
synced 2024-10-04 06:49:15 +00:00
1876326b6b
This is to help with #9930 Example changes: ```diff -[LOCKING] 4 packages +[LOCKING] 4 packages to latest version -[LOCKING] 2 packages +[LOCKING] 2 packages to latest Rust 1.60.0 compatible versions -[LOCKING] 2 packages +[LOCKING] 2 packages to earliest versions ``` Benefits - The package count is of "added" packages and this makes that more logically clear - This gives users transparency into what is happening, especially with - what rust-version is use - the transition to this feature in the new edition - whether the planned config was applied or not (as I don't want it to require an MSRV bump) - Will make it easier in tests to show what changed - Provides more motiviation to show this message in `cargo update` and `cargo install` (that will be explored in a follow up PR) This does come at the cost of more verbose output but hopefully not too verbose. This is why I left off other factors, like avoid-dev-deps.
236 lines
5.9 KiB
Rust
236 lines
5.9 KiB
Rust
//! Tests for `paths` overrides.
|
|
|
|
use cargo_test_support::registry::Package;
|
|
use cargo_test_support::{basic_manifest, project};
|
|
|
|
#[cargo_test]
|
|
fn broken_path_override_warns() {
|
|
Package::new("bar", "0.1.0").publish();
|
|
Package::new("bar", "0.2.0").publish();
|
|
|
|
let p = project()
|
|
.file(
|
|
"Cargo.toml",
|
|
r#"
|
|
[package]
|
|
name = "foo"
|
|
version = "0.0.1"
|
|
edition = "2015"
|
|
authors = []
|
|
|
|
[dependencies]
|
|
a = { path = "a1" }
|
|
"#,
|
|
)
|
|
.file("src/lib.rs", "")
|
|
.file(
|
|
"a1/Cargo.toml",
|
|
r#"
|
|
[package]
|
|
name = "a"
|
|
version = "0.0.1"
|
|
edition = "2015"
|
|
authors = []
|
|
|
|
[dependencies]
|
|
bar = "0.1"
|
|
"#,
|
|
)
|
|
.file("a1/src/lib.rs", "")
|
|
.file(
|
|
"a2/Cargo.toml",
|
|
r#"
|
|
[package]
|
|
name = "a"
|
|
version = "0.0.1"
|
|
edition = "2015"
|
|
authors = []
|
|
|
|
[dependencies]
|
|
bar = "0.2"
|
|
"#,
|
|
)
|
|
.file("a2/src/lib.rs", "")
|
|
.file(".cargo/config.toml", r#"paths = ["a2"]"#)
|
|
.build();
|
|
|
|
p.cargo("check")
|
|
.with_stderr(
|
|
"\
|
|
[UPDATING] [..]
|
|
[LOCKING] 3 packages to latest compatible versions
|
|
[ADDING] bar v0.1.0 (latest: v0.2.0)
|
|
warning: path override for crate `a` has altered the original list of
|
|
dependencies; the dependency on `bar` was either added or
|
|
modified to not match the previously resolved version
|
|
|
|
This is currently allowed but is known to produce buggy behavior with spurious
|
|
recompiles and changes to the crate graph. Path overrides unfortunately were
|
|
never intended to support this feature, so for now this message is just a
|
|
warning. In the future, however, this message will become a hard error.
|
|
|
|
To change the dependency graph via an override it's recommended to use the
|
|
`[patch]` feature of Cargo instead of the path override feature. This is
|
|
documented online at the url below for more information.
|
|
|
|
https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html
|
|
|
|
[DOWNLOADING] crates ...
|
|
[DOWNLOADED] [..]
|
|
[CHECKING] [..]
|
|
[CHECKING] [..]
|
|
[CHECKING] [..]
|
|
[FINISHED] [..]
|
|
",
|
|
)
|
|
.run();
|
|
}
|
|
|
|
#[cargo_test]
|
|
fn override_to_path_dep() {
|
|
Package::new("bar", "0.1.0").dep("baz", "0.1").publish();
|
|
Package::new("baz", "0.1.0").publish();
|
|
|
|
let p = project()
|
|
.file(
|
|
"Cargo.toml",
|
|
r#"
|
|
[package]
|
|
name = "foo"
|
|
version = "0.0.1"
|
|
authors = []
|
|
|
|
[dependencies]
|
|
bar = "0.1.0"
|
|
"#,
|
|
)
|
|
.file("src/lib.rs", "")
|
|
.file(
|
|
"bar/Cargo.toml",
|
|
r#"
|
|
[package]
|
|
name = "bar"
|
|
version = "0.0.1"
|
|
authors = []
|
|
|
|
[dependencies]
|
|
baz = { path = "baz" }
|
|
"#,
|
|
)
|
|
.file("bar/src/lib.rs", "")
|
|
.file("bar/baz/Cargo.toml", &basic_manifest("baz", "0.0.1"))
|
|
.file("bar/baz/src/lib.rs", "")
|
|
.file(".cargo/config.toml", r#"paths = ["bar"]"#)
|
|
.build();
|
|
|
|
p.cargo("check").run();
|
|
}
|
|
|
|
#[cargo_test]
|
|
fn paths_ok_with_optional() {
|
|
Package::new("baz", "0.1.0").publish();
|
|
|
|
let p = project()
|
|
.file(
|
|
"Cargo.toml",
|
|
r#"
|
|
[package]
|
|
name = "foo"
|
|
version = "0.0.1"
|
|
edition = "2015"
|
|
authors = []
|
|
|
|
[dependencies]
|
|
bar = { path = "bar" }
|
|
"#,
|
|
)
|
|
.file("src/lib.rs", "")
|
|
.file(
|
|
"bar/Cargo.toml",
|
|
r#"
|
|
[package]
|
|
name = "bar"
|
|
version = "0.1.0"
|
|
edition = "2015"
|
|
authors = []
|
|
|
|
[dependencies]
|
|
baz = { version = "0.1", optional = true }
|
|
"#,
|
|
)
|
|
.file("bar/src/lib.rs", "")
|
|
.file(
|
|
"bar2/Cargo.toml",
|
|
r#"
|
|
[package]
|
|
name = "bar"
|
|
version = "0.1.0"
|
|
edition = "2015"
|
|
authors = []
|
|
|
|
[dependencies]
|
|
baz = { version = "0.1", optional = true }
|
|
"#,
|
|
)
|
|
.file("bar2/src/lib.rs", "")
|
|
.file(".cargo/config.toml", r#"paths = ["bar2"]"#)
|
|
.build();
|
|
|
|
p.cargo("check")
|
|
.with_stderr(
|
|
"\
|
|
[LOCKING] 2 packages to latest compatible versions
|
|
[CHECKING] bar v0.1.0 ([..]bar2)
|
|
[CHECKING] foo v0.0.1 ([..])
|
|
[FINISHED] [..]
|
|
",
|
|
)
|
|
.run();
|
|
}
|
|
|
|
#[cargo_test]
|
|
fn paths_add_optional_bad() {
|
|
Package::new("baz", "0.1.0").publish();
|
|
|
|
let p = project()
|
|
.file(
|
|
"Cargo.toml",
|
|
r#"
|
|
[package]
|
|
name = "foo"
|
|
version = "0.0.1"
|
|
authors = []
|
|
|
|
[dependencies]
|
|
bar = { path = "bar" }
|
|
"#,
|
|
)
|
|
.file("src/lib.rs", "")
|
|
.file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
|
|
.file("bar/src/lib.rs", "")
|
|
.file(
|
|
"bar2/Cargo.toml",
|
|
r#"
|
|
[package]
|
|
name = "bar"
|
|
version = "0.1.0"
|
|
authors = []
|
|
|
|
[dependencies]
|
|
baz = { version = "0.1", optional = true }
|
|
"#,
|
|
)
|
|
.file("bar2/src/lib.rs", "")
|
|
.file(".cargo/config.toml", r#"paths = ["bar2"]"#)
|
|
.build();
|
|
|
|
p.cargo("check")
|
|
.with_stderr_contains(
|
|
"\
|
|
warning: path override for crate `bar` has altered the original list of
|
|
dependencies; the dependency on `baz` was either added or\
|
|
",
|
|
)
|
|
.run();
|
|
}
|