From 37a326ef500ef1b491020f1e8649f0e076d869ae Mon Sep 17 00:00:00 2001 From: Harry Moulton Date: Wed, 25 Sep 2024 11:38:04 +0100 Subject: [PATCH] test(cfg): add bad_cfg_discovery case for no-target-spec-json 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. --- tests/testsuite/cfg.rs | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/tests/testsuite/cfg.rs b/tests/testsuite/cfg.rs index 0b71e861b58..ac3c07a4b50 100644 --- a/tests/testsuite/cfg.rs +++ b/tests/testsuite/cfg.rs @@ -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; @@ -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"); } "#, ) @@ -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]