test(cargo-rustc): show the current precedence

This commit is contained in:
Weihang Lo 2024-09-23 22:47:24 -04:00
parent cf781daeb7
commit 7ded268948
No known key found for this signature in database
GPG Key ID: D7DBF189825E82E7

View File

@ -795,3 +795,67 @@ windows
)
.run();
}
#[cargo_test]
fn precedence() {
// Ensure that the precedence of cargo-rustc is only lower than RUSTFLAGS,
// but higher than most flags set by cargo.
//
// See rust-lang/cargo#14346
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
edition = "2021"
[lints.rust]
unexpected_cfgs = "allow"
"#,
)
.file("src/lib.rs", "")
.build();
p.cargo("rustc --release -v -- --cfg cargo_rustc -C strip=symbols")
.env("RUSTFLAGS", "--cfg from_rustflags")
.with_stderr_data(
str![[r#"
[COMPILING] foo v0.0.0 ([ROOT]/foo)
[RUNNING] `rustc [..]--cfg cargo_rustc -C strip=symbols [..]-C strip=debuginfo [..]--cfg from_rustflags`
[FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s
"#]]
)
.run();
// Ensure the short-live env var to work
p.cargo("clean").run();
p.cargo("rustc --release -v -- --cfg cargo_rustc -C strip=symbols")
.env("RUSTFLAGS", "--cfg from_rustflags")
.env("__CARGO_RUSTC_ORIG_ARGS_PRIO", "1")
.masquerade_as_nightly_cargo(&["cargo-rustc-precedence"])
.with_stderr_data(
str![[r#"
[COMPILING] foo v0.0.0 ([ROOT]/foo)
[RUNNING] `rustc [..]--cfg cargo_rustc -C strip=symbols [..]-C strip=debuginfo [..]--cfg from_rustflags`
[FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s
"#]]
)
.run();
// Ensure non-nightly to work as before
p.cargo("clean").run();
p.cargo("rustc --release -v -- --cfg cargo_rustc -C strip=symbols")
.env("RUSTFLAGS", "--cfg from_rustflags")
.with_stderr_data(
str![[r#"
[COMPILING] foo v0.0.0 ([ROOT]/foo)
[RUNNING] `rustc [..]--cfg cargo_rustc -C strip=symbols [..]-C strip=debuginfo [..]--cfg from_rustflags`
[FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s
"#]]
)
.run();
}