Skip to content

Commit

Permalink
Add more tests for check-cfg lint sub-config
Browse files Browse the repository at this point in the history
  • Loading branch information
Urgau committed May 14, 2024
1 parent 41577ed commit 9df0f31
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions tests/testsuite/check_cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,81 @@ fn lint_table_config() {
.run();
}

#[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")]
fn lint_table_config_and_features() {
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
edition = "2015"
[features]
my_feature = []
alloc = []
[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ["cfg(has_foo)", "cfg(has_bar, values(\"yes\", \"no\"))"] }
"#,
)
.file("src/main.rs", "fn main() {}")
.build();

p.cargo("check -v")
.with_stderr_contains(x!("rustc" => "cfg" of "has_foo"))
.with_stderr_contains(x!("rustc" => "cfg" of "has_bar" with "yes" "no"))
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with "alloc" "my_feature"))
.run();
}

#[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")]
fn lint_table_config_doc() {
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
edition = "2015"
[lints.rust]
unexpected_cfgs = { check-cfg = ["cfg(has_foo)"] }
"#,
)
.file("src/main.rs", "fn main() {}")
.build();

p.cargo("doc -v")
.with_stderr_contains(x!("rustdoc" => "cfg" of "has_foo"))
.run();
}

#[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")]
fn lint_table_config_test() {
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
edition = "2015"
[lints.rust]
unexpected_cfgs = { check-cfg = ["cfg(has_foo)"] }
"#,
)
.file("src/main.rs", "fn main() {}")
.build();

p.cargo("test -v")
.with_stderr_contains(x!("rustc" => "cfg" of "has_foo"))
.run();
}

#[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")]
fn lint_table_config_without_level() {
let p = project()
Expand Down

0 comments on commit 9df0f31

Please sign in to comment.