Harden duplicates checking and add tests

This commit is contained in:
Andy Caldwell 2022-07-28 23:05:24 +01:00
parent 08e7ec4047
commit ea25ef10cf
No known key found for this signature in database
GPG key ID: D4204541AC1D228D
5 changed files with 24 additions and 4 deletions

View file

@ -92,8 +92,8 @@ impl fmt::Display for ConfError {
impl Error for ConfError {} impl Error for ConfError {}
fn conf_error(s: String) -> Box<dyn Error> { fn conf_error(s: impl Into<String>) -> Box<dyn Error> {
Box::new(ConfError(s)) Box::new(ConfError(s.into()))
} }
macro_rules! define_Conf { macro_rules! define_Conf {
@ -154,7 +154,13 @@ macro_rules! define_Conf {
$name = Some(value); $name = Some(value);
// $new_conf is the same as one of the defined `$name`s, so // $new_conf is the same as one of the defined `$name`s, so
// this variable is defined in line 2 of this function. // this variable is defined in line 2 of this function.
$($new_conf = Some(value);)? $(match $new_conf {
Some(_) => errors.push(conf_error(concat!(
"duplicate field `", stringify!($new_conf),
"` (provided as `", stringify!($name), "`)"
))),
None => $new_conf = Some(value),
})?
}, },
} }
} }

View file

@ -1,4 +1,4 @@
# that one is an error # that one is a warning
cyclomatic-complexity-threshold = 2 cyclomatic-complexity-threshold = 2
# that one is white-listed # that one is white-listed

View file

@ -0,0 +1,5 @@
cognitive-complexity-threshold = 2
# This is the deprecated name for the same key
cyclomatic-complexity-threshold = 3
# Check we get duplication warning regardless of order
cognitive-complexity-threshold = 4

View file

@ -0,0 +1 @@
fn main() {}

View file

@ -0,0 +1,8 @@
error: error reading Clippy's configuration file `$DIR/clippy.toml`: duplicate field `cognitive_complexity_threshold` (provided as `cyclomatic_complexity_threshold`)
error: error reading Clippy's configuration file `$DIR/clippy.toml`: duplicate field `cognitive-complexity-threshold`
warning: error reading Clippy's configuration file `$DIR/clippy.toml`: deprecated field `cyclomatic-complexity-threshold`. Please use `cognitive-complexity-threshold` instead
error: aborting due to 2 previous errors; 1 warning emitted