test: reproduce transitive bindep dependency bug

This is a unit test reproducing the bindep transitive dependency bug based upon examples from
- https://github.com/rust-lang/cargo/issues/10837
- https://github.com/rust-lang/cargo/issues/11463

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
This commit is contained in:
Roman Volosatovs 2022-12-13 20:29:14 +01:00
parent 74c7aab19a
commit 4677a7cce5
No known key found for this signature in database
GPG Key ID: 216DD5F8CA6618A1

View File

@ -2447,3 +2447,226 @@ fn with_assumed_host_target_and_optional_build_dep() {
)
.run();
}
#[cargo_test]
fn decouple_same_target_transitive_dep_from_artifact_dep() {
// See https://github.com/rust-lang/cargo/issues/11463
let target = rustc_host();
let p = project()
.file(
"Cargo.toml",
&format!(
r#"
[package]
name = "foo"
version = "0.1.0"
edition = "2021"
[dependencies]
a = {{ path = "a" }}
bar = {{ path = "bar", artifact = "bin", target = "{target}" }}
"#
),
)
.file(
"src/main.rs",
r#"
fn main() {}
"#,
)
.file(
"bar/Cargo.toml",
r#"
[package]
name = "bar"
version = "0.1.0"
[dependencies]
a = { path = "../a", features = ["feature"] }
"#,
)
.file(
"bar/src/main.rs",
r#"
fn main() {}
"#,
)
.file(
"a/Cargo.toml",
r#"
[package]
name = "a"
version = "0.1.0"
edition = "2021"
[dependencies]
b = { path = "../b" }
c = { path = "../c" }
[features]
feature = ["c/feature"]
"#,
)
.file(
"a/src/lib.rs",
r#"
use b::Trait as _;
pub fn use_b_trait(x: &impl c::Trait) {
x.b();
}
"#,
)
.file(
"b/Cargo.toml",
r#"
[package]
name = "b"
version = "0.1.0"
[dependencies]
c = { path = "../c" }
"#,
)
.file(
"b/src/lib.rs",
r#"
pub trait Trait {
fn b(&self) {}
}
impl<T: c::Trait> Trait for T {}
"#,
)
.file(
"c/Cargo.toml",
r#"
[package]
name = "c"
version = "0.1.0"
[features]
feature = []
"#,
)
.file(
"c/src/lib.rs",
r#"
pub trait Trait {}
"#,
)
.build();
p.cargo("build -Z bindeps")
.masquerade_as_nightly_cargo(&["bindeps"])
.with_stderr(
"\
[COMPILING] c v0.1.0 ([CWD]/c)
[COMPILING] b v0.1.0 ([CWD]/b)
[COMPILING] a v0.1.0 ([CWD]/a)
[COMPILING] bar v0.1.0 ([CWD]/bar)
[COMPILING] foo v0.1.0 ([CWD])
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
",
)
.run();
}
#[cargo_test]
fn decouple_same_target_transitive_dep_from_artifact_dep_lib() {
// See https://github.com/rust-lang/cargo/issues/10837
let target = rustc_host();
let p = project()
.file(
"Cargo.toml",
&format!(
r#"
[package]
name = "foo"
version = "0.1.0"
edition = "2021"
[dependencies]
a = {{ path = "a" }}
b = {{ path = "b", features = ["feature"] }}
bar = {{ path = "bar", artifact = "bin", lib = true, target = "{target}" }}
"#
),
)
.file("src/lib.rs", "")
.file(
"bar/Cargo.toml",
r#"
[package]
name = "bar"
version = "0.1.0"
edition = "2021"
[dependencies]
a = { path = "../a", features = ["b"] }
b = { path = "../b" }
"#,
)
.file("bar/src/lib.rs", "")
.file(
"bar/src/main.rs",
r#"
use b::Trait;
fn main() {
a::A.b()
}
"#,
)
.file(
"a/Cargo.toml",
r#"
[package]
name = "a"
version = "0.1.0"
[dependencies]
b = { path = "../b", optional = true }
"#,
)
.file(
"a/src/lib.rs",
r#"
pub struct A;
#[cfg(feature = "b")]
impl b::Trait for A {}
"#,
)
.file(
"b/Cargo.toml",
r#"
[package]
name = "b"
version = "0.1.0"
[features]
feature = []
"#,
)
.file(
"b/src/lib.rs",
r#"
pub trait Trait {
fn b(&self) {}
}
"#,
)
.build();
p.cargo("build -Z bindeps")
.masquerade_as_nightly_cargo(&["bindeps"])
.with_stderr(
"\
[COMPILING] b v0.1.0 ([CWD]/b)
[COMPILING] a v0.1.0 ([CWD]/a)
[COMPILING] bar v0.1.0 ([CWD]/bar)
[COMPILING] foo v0.1.0 ([CWD])
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
",
)
.run();
}