Skip to content

Commit

Permalink
refactor: simplify rust-lang#10525 test case
Browse files Browse the repository at this point in the history
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
  • Loading branch information
rvolosatovs committed Dec 19, 2022
1 parent 0c647a8 commit dca8c28
Showing 1 changed file with 49 additions and 58 deletions.
107 changes: 49 additions & 58 deletions tests/testsuite/artifact_dep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2672,147 +2672,138 @@ fn same_target_transitive_dependency_decouple_from_hostdep_lib() {
}

#[cargo_test]
fn issue_10525() {
fn same_target_transitive_dependency_decouple_from_hostdep_10525() {
// See https://github.com/rust-lang/cargo/issues/10525
let target = rustc_host();
let p = project()
.file(
"Cargo.toml",
&format!(
r#"
[package]
name = "mycrate"
name = "foo"
version = "0.0.0"
edition = "2021"
[dependencies]
structopt-derive = {{ path = "structopt-derive" }}
mybindep = {{ path = "mybindep", artifact = "bin", target = "{target}" }}
e = {{ path = "e" }}
bar = {{ path = "bar", artifact = "bin", target = "{target}" }}
"#
),
)
.file(
"src/main.rs",
r#"
fn main() {
env!("CARGO_BIN_FILE_MYBINDEP");
}
fn main() {}
"#,
)
.file(
"mybindep/Cargo.toml",
"bar/Cargo.toml",
r#"
[package]
name = "mybindep"
name = "bar"
version = "0.0.0"
edition = "2021"
[dependencies]
clap_derive = { path = "../clap_derive" }
b = { path = "../b" }
"#,
)
.file("mybindep/src/main.rs", "fn main() {}")
.file("bar/src/main.rs", "fn main() {}")
.file(
"clap_derive/Cargo.toml",
"b/Cargo.toml",
r#"
[package]
name = "clap_derive"
name = "b"
version = "0.0.0"
edition = "2021"
[dependencies]
proc-macro-error = { path = "../proc-macro-error" }
[lib]
proc-macro = true
c = { path = "../c" }
"#,
)
.file("clap_derive/src/lib.rs", "")
.file("b/src/lib.rs", "")
.file(
"structopt-derive/Cargo.toml",
// NOTE: Calling this package `a` does not trigger
// https://github.com/rust-lang/cargo/issues/10525
"e/Cargo.toml",
r#"
[package]
name = "structopt-derive"
name = "e"
version = "0.0.0"
edition = "2021"
[dependencies]
syn = { path = "../syn", features = ["parsing"] }
proc-macro-error = { path = "../proc-macro-error" }
[lib]
proc-macro = true
c = { path = "../c" }
d = { path = "../d", features = ["feature"] }
"#,
)
.file(
"structopt-derive/src/lib.rs",
"e/src/lib.rs",
r#"
use proc_macro_error::ResultExt;
use c::Trait;
fn _parse_structopt_attributes() {
Ok::<(), syn::Error>(()).unwrap_or_abort()
pub fn b() {
d::D.c();
}
"#,
)
.file(
"proc-macro-error/Cargo.toml",
"c/Cargo.toml",
r#"
[package]
name = "proc-macro-error"
name = "c"
version = "0.0.0"
edition = "2021"
[dependencies]
syn = { path = "../syn" }
d = { path = "../d" }
"#,
)
.file(
"proc-macro-error/src/lib.rs",
"c/src/lib.rs",
r#"
pub trait ResultExt<T> {
fn unwrap_or_abort(self) -> T;
pub trait Trait<T> {
fn c(self) -> T;
}
impl<T, E: Into<Diagnostic>> ResultExt<T> for Result<T, E> {
fn unwrap_or_abort(self) -> T {
panic!()
impl<T: Into<C>> Trait<T> for T {
fn c(self) -> T {
self
}
}
pub struct Diagnostic;
pub struct C;
impl From<syn::Error> for Diagnostic {
fn from(_: syn::Error) -> Self {
panic!()
impl From<d::D> for C {
fn from(_: d::D) -> Self {
Self
}
}
"#,
)
.file(
"syn/Cargo.toml",
"d/Cargo.toml",
r#"
[package]
name = "syn"
name = "d"
version = "0.0.0"
edition = "2021"
[features]
parsing = []
feature = []
"#,
)
.file("syn/src/lib.rs", "pub struct Error;")
.file("d/src/lib.rs", "pub struct D;")
.build();

p.cargo("build -Z bindeps")
.masquerade_as_nightly_cargo(&["bindeps"])
.with_stderr_unordered(
.with_stderr(
"\
[COMPILING] mycrate v0.0.0 ([CWD])
[COMPILING] mybindep v0.0.0 ([CWD]/mybindep)
[COMPILING] clap_derive v0.0.0 ([CWD]/clap_derive)
[COMPILING] structopt-derive v0.0.0 ([CWD]/structopt-derive)
[COMPILING] proc-macro-error v0.0.0 ([CWD]/proc-macro-error)
[COMPILING] syn v0.0.0 ([CWD]/syn)
[FINISHED] dev [..]
[COMPILING] d v0.0.0 ([CWD]/d)
[COMPILING] c v0.0.0 ([CWD]/c)
[COMPILING] b v0.0.0 ([CWD]/b)
[COMPILING] e v0.0.0 ([CWD]/e)
[COMPILING] bar v0.0.0 ([CWD]/bar)
[COMPILING] foo v0.0.0 ([CWD])
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
",
)
.run();
Expand Down

0 comments on commit dca8c28

Please sign in to comment.