diff --git a/Cargo.lock b/Cargo.lock index a8db752..1d0948e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -767,6 +767,12 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "maplit" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" + [[package]] name = "memchr" version = "2.3.4" @@ -1516,6 +1522,7 @@ dependencies = [ "itertools 0.10.0", "kstring", "log", + "maplit", "once_cell", "phf", "predicates", diff --git a/Cargo.toml b/Cargo.toml index 01fd4da..7019987 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -65,6 +65,7 @@ typed-arena = "2.0.1" assert_fs = "1.0" predicates = "1.0" criterion = "0.3" +maplit = "1.0" [profile.dev] panic = "abort" diff --git a/src/policy.rs b/src/policy.rs index ea789be..5faddf9 100644 --- a/src/policy.rs +++ b/src/policy.rs @@ -133,7 +133,6 @@ impl<'s> ConfigEngine<'s> { let mut types = Default::default(); std::mem::swap(&mut types, &mut config.type_); - let mut types = types .into_iter() .map(|(type_, type_engine)| { @@ -338,3 +337,57 @@ impl<'t, 'd> Default for Policy<'t, 'd> { } } } + +#[cfg(test)] +mod test { + use super::*; + + #[test] + fn test_load_config_applies_overrides() { + let storage = ConfigStorage::new(); + let mut engine = ConfigEngine::new(&storage); + engine.set_isolated(true); + + let type_name = kstring::KString::from_static("toml"); + + let config = crate::config::Config { + default: crate::config::EngineConfig { + binary: Some(true), + check_filename: Some(true), + ..Default::default() + }, + type_: maplit::hashmap! { + type_name.clone() => crate::config::TypeEngineConfig { + engine: crate::config::EngineConfig { + check_filename: Some(false), + check_file: Some(true), + ..Default::default() + }, + ..Default::default() + }, + }, + overrides: crate::config::EngineConfig { + binary: Some(false), + check_file: Some(false), + ..Default::default() + }, + ..Default::default() + }; + engine.set_overrides(config); + + let cwd = std::path::Path::new("."); + let loaded = engine.load_config(&cwd).unwrap(); + assert_eq!(loaded.default.binary, Some(false)); + assert_eq!(loaded.default.check_filename, Some(true)); + assert_eq!(loaded.default.check_file, Some(false)); + assert_eq!(loaded.type_[type_name.as_str()].engine.binary, Some(false)); + assert_eq!( + loaded.type_[type_name.as_str()].engine.check_filename, + Some(false) + ); + assert_eq!( + loaded.type_[type_name.as_str()].engine.check_file, + Some(false) + ); + } +}