Skip to content

Commit 23f59d4

Browse files
committed
Add regression tests for check-cfg unstable config
1 parent c08a666 commit 23f59d4

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

tests/testsuite/check_cfg.rs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,3 +629,74 @@ fn build_script_test() {
629629
.masquerade_as_nightly_cargo()
630630
.run();
631631
}
632+
633+
#[cargo_test]
634+
fn config_valid() {
635+
if !is_nightly() {
636+
// --check-cfg is a nightly only rustc command line
637+
return;
638+
}
639+
640+
let p = project()
641+
.file(
642+
"Cargo.toml",
643+
r#"
644+
[project]
645+
name = "foo"
646+
version = "0.1.0"
647+
648+
[features]
649+
f_a = []
650+
f_b = []
651+
"#,
652+
)
653+
.file("src/main.rs", "fn main() {}")
654+
.file(
655+
".cargo/config.toml",
656+
r#"
657+
[unstable]
658+
check-cfg = ["features", "names", "values"]
659+
"#,
660+
)
661+
.build();
662+
663+
p.cargo("build -v -Zcheck-cfg=features,names,values")
664+
.masquerade_as_nightly_cargo()
665+
.with_stderr_contains(x!("rustc" => "names"))
666+
.with_stderr_contains(x!("rustc" => "values"))
667+
.with_stderr_contains(x!("rustc" => "values" of "feature" with "f_a" "f_b"))
668+
.run();
669+
}
670+
671+
#[cargo_test]
672+
fn config_invalid() {
673+
if !is_nightly() {
674+
// --check-cfg is a nightly only rustc command line
675+
return;
676+
}
677+
678+
let p = project()
679+
.file(
680+
"Cargo.toml",
681+
r#"
682+
[project]
683+
name = "foo"
684+
version = "0.1.0"
685+
"#,
686+
)
687+
.file("src/main.rs", "fn main() {}")
688+
.file(
689+
".cargo/config.toml",
690+
r#"
691+
[unstable]
692+
check-cfg = ["va"]
693+
"#,
694+
)
695+
.build();
696+
697+
p.cargo("build")
698+
.masquerade_as_nightly_cargo()
699+
.with_stderr_contains("error: unstable check-cfg only takes `features`, `names`, `values` or `output` as valid inputs")
700+
.with_status(101)
701+
.run();
702+
}

0 commit comments

Comments
 (0)