Skip to content

Commit 4677a7c

Browse files
committed
test: reproduce transitive bindep dependency bug
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>
1 parent 74c7aab commit 4677a7c

File tree

1 file changed

+223
-0
lines changed

1 file changed

+223
-0
lines changed

tests/testsuite/artifact_dep.rs

+223
Original file line numberDiff line numberDiff line change
@@ -2447,3 +2447,226 @@ fn with_assumed_host_target_and_optional_build_dep() {
24472447
)
24482448
.run();
24492449
}
2450+
2451+
#[cargo_test]
2452+
fn decouple_same_target_transitive_dep_from_artifact_dep() {
2453+
// See https://github.com/rust-lang/cargo/issues/11463
2454+
let target = rustc_host();
2455+
let p = project()
2456+
.file(
2457+
"Cargo.toml",
2458+
&format!(
2459+
r#"
2460+
[package]
2461+
name = "foo"
2462+
version = "0.1.0"
2463+
edition = "2021"
2464+
2465+
[dependencies]
2466+
a = {{ path = "a" }}
2467+
bar = {{ path = "bar", artifact = "bin", target = "{target}" }}
2468+
"#
2469+
),
2470+
)
2471+
.file(
2472+
"src/main.rs",
2473+
r#"
2474+
fn main() {}
2475+
"#,
2476+
)
2477+
.file(
2478+
"bar/Cargo.toml",
2479+
r#"
2480+
[package]
2481+
name = "bar"
2482+
version = "0.1.0"
2483+
2484+
[dependencies]
2485+
a = { path = "../a", features = ["feature"] }
2486+
"#,
2487+
)
2488+
.file(
2489+
"bar/src/main.rs",
2490+
r#"
2491+
fn main() {}
2492+
"#,
2493+
)
2494+
.file(
2495+
"a/Cargo.toml",
2496+
r#"
2497+
[package]
2498+
name = "a"
2499+
version = "0.1.0"
2500+
edition = "2021"
2501+
2502+
[dependencies]
2503+
b = { path = "../b" }
2504+
c = { path = "../c" }
2505+
2506+
[features]
2507+
feature = ["c/feature"]
2508+
"#,
2509+
)
2510+
.file(
2511+
"a/src/lib.rs",
2512+
r#"
2513+
use b::Trait as _;
2514+
2515+
pub fn use_b_trait(x: &impl c::Trait) {
2516+
x.b();
2517+
}
2518+
"#,
2519+
)
2520+
.file(
2521+
"b/Cargo.toml",
2522+
r#"
2523+
[package]
2524+
name = "b"
2525+
version = "0.1.0"
2526+
2527+
[dependencies]
2528+
c = { path = "../c" }
2529+
"#,
2530+
)
2531+
.file(
2532+
"b/src/lib.rs",
2533+
r#"
2534+
pub trait Trait {
2535+
fn b(&self) {}
2536+
}
2537+
2538+
impl<T: c::Trait> Trait for T {}
2539+
"#,
2540+
)
2541+
.file(
2542+
"c/Cargo.toml",
2543+
r#"
2544+
[package]
2545+
name = "c"
2546+
version = "0.1.0"
2547+
2548+
[features]
2549+
feature = []
2550+
"#,
2551+
)
2552+
.file(
2553+
"c/src/lib.rs",
2554+
r#"
2555+
pub trait Trait {}
2556+
"#,
2557+
)
2558+
.build();
2559+
p.cargo("build -Z bindeps")
2560+
.masquerade_as_nightly_cargo(&["bindeps"])
2561+
.with_stderr(
2562+
"\
2563+
[COMPILING] c v0.1.0 ([CWD]/c)
2564+
[COMPILING] b v0.1.0 ([CWD]/b)
2565+
[COMPILING] a v0.1.0 ([CWD]/a)
2566+
[COMPILING] bar v0.1.0 ([CWD]/bar)
2567+
[COMPILING] foo v0.1.0 ([CWD])
2568+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
2569+
",
2570+
)
2571+
.run();
2572+
}
2573+
2574+
#[cargo_test]
2575+
fn decouple_same_target_transitive_dep_from_artifact_dep_lib() {
2576+
// See https://github.com/rust-lang/cargo/issues/10837
2577+
let target = rustc_host();
2578+
let p = project()
2579+
.file(
2580+
"Cargo.toml",
2581+
&format!(
2582+
r#"
2583+
[package]
2584+
name = "foo"
2585+
version = "0.1.0"
2586+
edition = "2021"
2587+
2588+
[dependencies]
2589+
a = {{ path = "a" }}
2590+
b = {{ path = "b", features = ["feature"] }}
2591+
bar = {{ path = "bar", artifact = "bin", lib = true, target = "{target}" }}
2592+
"#
2593+
),
2594+
)
2595+
.file("src/lib.rs", "")
2596+
.file(
2597+
"bar/Cargo.toml",
2598+
r#"
2599+
[package]
2600+
name = "bar"
2601+
version = "0.1.0"
2602+
edition = "2021"
2603+
2604+
[dependencies]
2605+
a = { path = "../a", features = ["b"] }
2606+
b = { path = "../b" }
2607+
"#,
2608+
)
2609+
.file("bar/src/lib.rs", "")
2610+
.file(
2611+
"bar/src/main.rs",
2612+
r#"
2613+
use b::Trait;
2614+
2615+
fn main() {
2616+
a::A.b()
2617+
}
2618+
"#,
2619+
)
2620+
.file(
2621+
"a/Cargo.toml",
2622+
r#"
2623+
[package]
2624+
name = "a"
2625+
version = "0.1.0"
2626+
2627+
[dependencies]
2628+
b = { path = "../b", optional = true }
2629+
"#,
2630+
)
2631+
.file(
2632+
"a/src/lib.rs",
2633+
r#"
2634+
pub struct A;
2635+
2636+
#[cfg(feature = "b")]
2637+
impl b::Trait for A {}
2638+
"#,
2639+
)
2640+
.file(
2641+
"b/Cargo.toml",
2642+
r#"
2643+
[package]
2644+
name = "b"
2645+
version = "0.1.0"
2646+
2647+
[features]
2648+
feature = []
2649+
"#,
2650+
)
2651+
.file(
2652+
"b/src/lib.rs",
2653+
r#"
2654+
pub trait Trait {
2655+
fn b(&self) {}
2656+
}
2657+
"#,
2658+
)
2659+
.build();
2660+
p.cargo("build -Z bindeps")
2661+
.masquerade_as_nightly_cargo(&["bindeps"])
2662+
.with_stderr(
2663+
"\
2664+
[COMPILING] b v0.1.0 ([CWD]/b)
2665+
[COMPILING] a v0.1.0 ([CWD]/a)
2666+
[COMPILING] bar v0.1.0 ([CWD]/bar)
2667+
[COMPILING] foo v0.1.0 ([CWD])
2668+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
2669+
",
2670+
)
2671+
.run();
2672+
}

0 commit comments

Comments
 (0)