about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-09-26 01:38:08 +0000
committerbors <bors@rust-lang.org>2023-09-26 01:38:08 +0000
commitbf4c9981798a319487e57af4214807dffc5fc778 (patch)
tree029878e89a8ffae170829b8154cf20bd034c0f56
parent6c48ef3fc1a5ed259f1a12a80280702536dfdfbb (diff)
parent1972cc89c4e9db8f325137b58f7197aeef0a49d6 (diff)
downloadrust-bf4c9981798a319487e57af4214807dffc5fc778.tar.gz
rust-bf4c9981798a319487e57af4214807dffc5fc778.zip
Auto merge of #11564 - Alexendoo:config-test-test, r=giraffate
Test that each config value exists in a test clippy.toml

Inspired by #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
-rw-r--r--clippy_lints/Cargo.toml3
-rw-r--r--clippy_lints/src/utils/conf.rs41
2 files changed, 44 insertions, 0 deletions
diff --git a/clippy_lints/Cargo.toml b/clippy_lints/Cargo.toml
index dcd9a4adcbd..834753a2301 100644
--- a/clippy_lints/Cargo.toml
+++ b/clippy_lints/Cargo.toml
@@ -28,6 +28,9 @@ semver = "1.0"
 rustc-semver = "1.1"
 url = "2.2"
 
+[dev-dependencies]
+walkdir = "2.3"
+
 [features]
 deny-warnings = ["clippy_utils/deny-warnings"]
 # build clippy with internal lints enabled, off by default
diff --git a/clippy_lints/src/utils/conf.rs b/clippy_lints/src/utils/conf.rs
index 75c3c7a958a..c502e50d21f 100644
--- a/clippy_lints/src/utils/conf.rs
+++ b/clippy_lints/src/utils/conf.rs
@@ -744,3 +744,44 @@ fn calculate_dimensions(fields: &[&str]) -> (usize, Vec<usize>) {
 
     (rows, column_widths)
 }
+
+#[cfg(test)]
+mod tests {
+    use rustc_data_structures::fx::{FxHashMap, FxHashSet};
+    use serde::de::IgnoredAny;
+    use std::fs;
+    use walkdir::WalkDir;
+
+    #[test]
+    fn configs_are_tested() {
+        let mut names: FxHashSet<String> = super::metadata::get_configuration_metadata()
+            .into_iter()
+            .map(|meta| meta.name.replace('_', "-"))
+            .collect();
+
+        let toml_files = WalkDir::new("../tests")
+            .into_iter()
+            .map(Result::unwrap)
+            .filter(|entry| entry.file_name() == "clippy.toml");
+
+        for entry in toml_files {
+            let file = fs::read_to_string(entry.path()).unwrap();
+            #[allow(clippy::zero_sized_map_values)]
+            if let Ok(map) = toml::from_str::<FxHashMap<String, IgnoredAny>>(&file) {
+                for name in map.keys() {
+                    names.remove(name.as_str());
+                }
+            }
+        }
+
+        assert!(
+            names.remove("allow-one-hash-in-raw-strings"),
+            "remove this when #11481 is fixed"
+        );
+
+        assert!(
+            names.is_empty(),
+            "Configuration variable lacks test: {names:?}\nAdd a test to `tests/ui-toml`"
+        );
+    }
+}