Skip to content

Commit

Permalink
test(cfg): add bad_cfg_discovery case for no-target-spec-json
Browse files Browse the repository at this point in the history
An additional rustc query is made in Cargo to collect the
target-spec-json from rustc to determine if the build target supports
compiling the standard library. As this functionality relies on a
nightly rustc, Cargo does not output any errors when parsing, and
continues as normal.

This commit adds a new test case to bad_cfg_discovery to ensure that
Cargo handles this properly. Unlike the other tests, there is no
expected output and an exit code 0.
  • Loading branch information
harmou01 committed Oct 15, 2024
1 parent b7b55ec commit 1f9e646
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions tests/testsuite/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,18 @@ fn bad_cfg_discovery() {
fn main() {
let mode = std::env::var("FUNKY_MODE").unwrap();
// Cargo may run the shim with parameters for building 'foo' when the mode is set to
// "no-target-spec-json". To avoid issues with this, just return in this case.
if std::env::args_os().any(|s| s.into_string().unwrap().contains("foo")) {
return;
}
// If Cargo has run the shim with "--print=target-spec-json", return so the test case
// receives the correct output
if std::env::args_os().any(|s| s.into_string().unwrap().contains("target-spec-json")) {
return;
}
if mode == "bad-version" {
println!("foo");
return;
Expand Down Expand Up @@ -375,16 +387,20 @@ fn bad_cfg_discovery() {
println!("\n{line}");
break;
} else {
// As the number split-debuginfo options varies,
// concat them into one line.
print!("{line},");
}
};
if mode != "bad-cfg" {
if mode == "bad-cfg" {
println!("123");
return;
}
for line in lines {
println!("{line}");
}
if mode != "no-target-spec-json" {
panic!("unexpected");
}
println!("123");
}
"#,
)
Expand Down Expand Up @@ -482,6 +498,12 @@ Caused by:
"#]])
.run();

p.cargo("check")
.env("RUSTC", &funky_rustc)
.env("FUNKY_MODE", "no-target-spec-json")
.with_status(0)
.run();
}

#[cargo_test]
Expand Down

0 comments on commit 1f9e646

Please sign in to comment.