Skip to content

Commit

Permalink
test: reproduce transitive bindep dependency bug
Browse files Browse the repository at this point in the history
This is a unit test reproducing the bindep transitive dependency bug based upon examples from
- rust-lang#10837
- rust-lang#11463

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
  • Loading branch information
rvolosatovs committed Dec 14, 2022
1 parent cc0a320 commit f65933c
Showing 1 changed file with 225 additions and 0 deletions.
225 changes: 225 additions & 0 deletions tests/testsuite/artifact_dep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2447,3 +2447,228 @@ fn with_assumed_host_target_and_optional_build_dep() {
)
.run();
}

#[cargo_test]
fn same_target_transitive_dependency_deduplication() {
// See:
// - https://github.com/rust-lang/cargo/issues/10837
// - 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 same_target_transitive_dependency_deduplication_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();
}

0 comments on commit f65933c

Please sign in to comment.