Skip to content

Commit 37a326e

Browse files
committed
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.
1 parent 820251e commit 37a326e

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

tests/testsuite/cfg.rs

+26-4
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,18 @@ fn bad_cfg_discovery() {
336336
337337
fn main() {
338338
let mode = std::env::var("FUNKY_MODE").unwrap();
339+
340+
// Cargo may run the shim with parameters for building 'foo' when the mode is set to
341+
// "no-target-spec-json". To avoid issues with this, just return in this case.
342+
if std::env::args_os().any(|s| s.into_string().unwrap().contains("foo")) {
343+
return;
344+
}
345+
346+
// If Cargo has run the shim with "--print=target-spec-json", return so the test case
347+
// receives the correct output
348+
if std::env::args_os().any(|s| s.into_string().unwrap().contains("target-spec-json")) {
349+
return;
350+
}
339351
if mode == "bad-version" {
340352
println!("foo");
341353
return;
@@ -375,16 +387,20 @@ fn bad_cfg_discovery() {
375387
println!("\n{line}");
376388
break;
377389
} else {
378-
// As the number split-debuginfo options varies,
379-
// concat them into one line.
380390
print!("{line},");
381391
}
382392
};
383393
384-
if mode != "bad-cfg" {
394+
if mode == "bad-cfg" {
395+
println!("123");
396+
return;
397+
}
398+
for line in lines {
399+
println!("{line}");
400+
}
401+
if mode != "no-target-spec-json" {
385402
panic!("unexpected");
386403
}
387-
println!("123");
388404
}
389405
"#,
390406
)
@@ -482,6 +498,12 @@ Caused by:
482498
483499
"#]])
484500
.run();
501+
502+
p.cargo("check")
503+
.env("RUSTC", &funky_rustc)
504+
.env("FUNKY_MODE", "no-target-spec-json")
505+
.with_status(0)
506+
.run();
485507
}
486508

487509
#[cargo_test]

0 commit comments

Comments
 (0)