Skip to content

Commit

Permalink
Add feature gate test for check-cfg config, build script and override
Browse files Browse the repository at this point in the history
  • Loading branch information
Urgau committed Oct 27, 2023
1 parent fd7b674 commit e396904
Showing 1 changed file with 92 additions and 0 deletions.
92 changes: 92 additions & 0 deletions tests/testsuite/check_cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,41 @@ fn build_script_override() {
.run();
}

#[cargo_test]
fn build_script_override_feature_gate() {
let target = cargo_test_support::rustc_host();

let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
links = "a"
"#,
)
.file("src/main.rs", "fn main() {}")
.file("build.rs", "fn main() {}")
.file(
".cargo/config",
&format!(
r#"
[target.{}.a]
rustc-check-cfg = ["cfg(foo)"]
"#,
target
),
)
.build();

p.cargo("check")
.with_stderr_contains(
"warning: target config[..]rustc-check-cfg[..] requires -Zcheck-cfg flag",
)
.run();
}

#[cargo_test(nightly, reason = "--check-cfg is unstable")]
fn build_script_test() {
let p = project()
Expand Down Expand Up @@ -409,6 +444,34 @@ fn build_script_test() {
.run();
}

#[cargo_test]
fn build_script_feature_gate() {
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
build = "build.rs"
"#,
)
.file(
"build.rs",
r#"fn main() {
println!("cargo:rustc-check-cfg=cfg(foo)");
println!("cargo:rustc-cfg=foo");
}"#,
)
.file("src/main.rs", "fn main() {}")
.build();

p.cargo("check")
.with_stderr_contains("warning[..]cargo:rustc-check-cfg requires -Zcheck-cfg flag")
.with_status(0)
.run();
}

#[cargo_test(nightly, reason = "--check-cfg is unstable")]
fn config_valid() {
let p = project()
Expand Down Expand Up @@ -467,3 +530,32 @@ fn config_invalid() {
.with_status(101)
.run();
}

#[cargo_test]
fn config_feature_gate() {
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
[features]
f_a = []
"#,
)
.file("src/main.rs", "fn main() {}")
.file(
".cargo/config.toml",
r#"
[unstable]
check-cfg = true
"#,
)
.build();

p.cargo("check -v")
.with_stderr_does_not_contain("--check-cfg")
.run();
}

0 comments on commit e396904

Please sign in to comment.