Skip to content

Commit bf4c998

Browse files
committed
Auto merge of rust-lang#11564 - Alexendoo:config-test-test, r=giraffate
Test that each config value exists in a test clippy.toml Inspired by rust-lang#11560, adds a test that each config option exists in some form in a `clippy.toml` in `tests/` (currently some are in `ui-toml`, some in `ui-cargo`) changelog: none
2 parents 6c48ef3 + 1972cc8 commit bf4c998

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

clippy_lints/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ semver = "1.0"
2828
rustc-semver = "1.1"
2929
url = "2.2"
3030

31+
[dev-dependencies]
32+
walkdir = "2.3"
33+
3134
[features]
3235
deny-warnings = ["clippy_utils/deny-warnings"]
3336
# build clippy with internal lints enabled, off by default

clippy_lints/src/utils/conf.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,3 +744,44 @@ fn calculate_dimensions(fields: &[&str]) -> (usize, Vec<usize>) {
744744

745745
(rows, column_widths)
746746
}
747+
748+
#[cfg(test)]
749+
mod tests {
750+
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
751+
use serde::de::IgnoredAny;
752+
use std::fs;
753+
use walkdir::WalkDir;
754+
755+
#[test]
756+
fn configs_are_tested() {
757+
let mut names: FxHashSet<String> = super::metadata::get_configuration_metadata()
758+
.into_iter()
759+
.map(|meta| meta.name.replace('_', "-"))
760+
.collect();
761+
762+
let toml_files = WalkDir::new("../tests")
763+
.into_iter()
764+
.map(Result::unwrap)
765+
.filter(|entry| entry.file_name() == "clippy.toml");
766+
767+
for entry in toml_files {
768+
let file = fs::read_to_string(entry.path()).unwrap();
769+
#[allow(clippy::zero_sized_map_values)]
770+
if let Ok(map) = toml::from_str::<FxHashMap<String, IgnoredAny>>(&file) {
771+
for name in map.keys() {
772+
names.remove(name.as_str());
773+
}
774+
}
775+
}
776+
777+
assert!(
778+
names.remove("allow-one-hash-in-raw-strings"),
779+
"remove this when #11481 is fixed"
780+
);
781+
782+
assert!(
783+
names.is_empty(),
784+
"Configuration variable lacks test: {names:?}\nAdd a test to `tests/ui-toml`"
785+
);
786+
}
787+
}

0 commit comments

Comments
 (0)