Skip to content

Commit 902191e

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 b7b55ec commit 902191e

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

tests/testsuite/cfg.rs

+31-6
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.
380-
print!("{line},");
390+
println!("{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
)
@@ -472,7 +488,10 @@ lib___.rlib
472488
[..]___.[..]
473489
[..]___.[..]
474490
[..]
475-
[..],[..]
491+
[..]
492+
[..]
493+
[..]
494+
476495
___
477496
123
478497
@@ -482,6 +501,12 @@ Caused by:
482501
483502
"#]])
484503
.run();
504+
505+
p.cargo("check")
506+
.env("RUSTC", &funky_rustc)
507+
.env("FUNKY_MODE", "no-target-spec-json")
508+
.with_status(0)
509+
.run();
485510
}
486511

487512
#[cargo_test]

0 commit comments

Comments
 (0)