test(bindeps): target field specified and optional = true coexist

This commit is contained in:
Weihang Lo 2022-11-28 13:56:27 +00:00
parent 7bdb96929d
commit 437bed069a
No known key found for this signature in database
GPG Key ID: D7DBF189825E82E7

View File

@ -2342,3 +2342,55 @@ fn calc_bin_artifact_fingerprint() {
)
.run();
}
#[cargo_test]
fn with_target_and_optional() {
// This is a incorrect behaviour got to be fixed.
// See rust-lang/cargo#10526
if cross_compile::disabled() {
return;
}
let target = cross_compile::alternate();
let p = project()
.file(
"Cargo.toml",
&r#"
[package]
name = "foo"
version = "0.0.1"
edition = "2021"
[dependencies]
d1 = { path = "d1", artifact = "bin", optional = true, target = "$TARGET" }
"#
.replace("$TARGET", target),
)
.file(
"src/main.rs",
r#"
fn main() {
let _b = include_bytes!(env!("CARGO_BIN_FILE_D1"));
}
"#,
)
.file(
"d1/Cargo.toml",
r#"
[package]
name = "d1"
version = "0.0.1"
edition = "2021"
"#,
)
.file("d1/src/main.rs", "fn main() {}")
.build();
p.cargo("check -Z bindeps -F d1 -v")
.masquerade_as_nightly_cargo(&["bindeps"])
.with_stderr_contains(
"\
[ERROR] environment variable `CARGO_BIN_FILE_D1` not defined
",
)
.with_status(101)
.run();
}