From 4c5e431568550d1ffecc71de62ef07b8d3a9b080 Mon Sep 17 00:00:00 2001 From: Freddie Ridell Date: Wed, 4 Mar 2026 22:34:39 +0000 Subject: [PATCH] Replace clap with figue for config management --- Cargo.lock | 292 ++++++++++++++++++++------------ crates/bough-core/Cargo.toml | 2 +- crates/bough-core/SPEC.md | 12 ++ crates/bough-core/src/config.rs | 207 +++++++++------------- 4 files changed, 281 insertions(+), 232 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 475f7dfa..6bbae0eb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -18,61 +18,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" [[package]] -name = "anstream" -version = "0.6.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43d5b281e737544384e969a5ccad3f1cdd24b48086a0fc1b2a5262a26b8f4f4a" -dependencies = [ - "anstyle", - "anstyle-parse", - "anstyle-query", - "anstyle-wincon", - "colorchoice", - "is_terminal_polyfill", - "utf8parse", -] - -[[package]] -name = "anstyle" -version = "1.0.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5192cca8006f1fd4f7237516f40fa183bb07f8fbdfedaa0036de5ea9b0b45e78" - -[[package]] -name = "anstyle-parse" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2" -dependencies = [ - "utf8parse", -] - -[[package]] -name = "anstyle-query" -version = "1.1.5" +name = "anyhow" +version = "1.0.102" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" -dependencies = [ - "windows-sys", -] +checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" [[package]] -name = "anstyle-wincon" -version = "3.0.11" +name = "ariadne" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" +checksum = "8454c8a44ce2cb9cc7e7fae67fc6128465b343b92c6631e94beca3c8d1524ea5" dependencies = [ - "anstyle", - "once_cell_polyfill", - "windows-sys", + "unicode-width", + "yansi", ] -[[package]] -name = "anyhow" -version = "1.0.102" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" - [[package]] name = "autocfg" version = "1.5.0" @@ -99,11 +59,11 @@ name = "bough-core" version = "0.0.0" dependencies = [ "bough-typed-hash", - "clap", "facet", "facet-json", "facet-toml", "facet-value", + "figue", "glob", "rand", "tempfile", @@ -133,6 +93,12 @@ dependencies = [ "syn", ] +[[package]] +name = "camino" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e629a66d692cb9ff1a1c664e41771b3dcaf961985a9774c0eb0bd1b51cf60a48" + [[package]] name = "cc" version = "1.2.56" @@ -160,52 +126,6 @@ dependencies = [ "rand_core", ] -[[package]] -name = "clap" -version = "4.5.60" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2797f34da339ce31042b27d23607e051786132987f595b02ba4f6a6dffb7030a" -dependencies = [ - "clap_builder", - "clap_derive", -] - -[[package]] -name = "clap_builder" -version = "4.5.60" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24a241312cea5059b13574bb9b3861cabf758b879c15190b37b6d6fd63ab6876" -dependencies = [ - "anstream", - "anstyle", - "clap_lex", - "strsim", -] - -[[package]] -name = "clap_derive" -version = "4.5.55" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a92793da1a46a5f2a02a6f4c46c6496b28c43638adea8306fcb0caa1634f24e5" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "clap_lex" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a822ea5bc7590f9d40f1ba12c0dc3c2760f3482c6984db1573ad11031420831" - -[[package]] -name = "colorchoice" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" - [[package]] name = "const-fnv1a-hash" version = "1.1.0" @@ -284,9 +204,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf2c09e5a796b8989e7555cbe097ddd3c3ffa4c02392b9b4ad0d7cd48b1af5c2" dependencies = [ "autocfg", + "camino", "const-fnv1a-hash", "iddqd", "impls", + "indexmap", ] [[package]] @@ -299,6 +221,15 @@ dependencies = [ "facet-reflect", ] +[[package]] +name = "facet-error" +version = "0.44.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d19f1faf0c1074b7584a43774789e06234f839dc7207ff3fcf2fbd7902429f96" +dependencies = [ + "facet", +] + [[package]] name = "facet-format" version = "0.44.1" @@ -379,6 +310,17 @@ dependencies = [ "facet-core", ] +[[package]] +name = "facet-pretty" +version = "0.44.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "682119408855d2a5de7cc23b0477ed19e332e0272caa110063eeda82d8809cc2" +dependencies = [ + "facet-core", + "facet-reflect", + "owo-colors", +] + [[package]] name = "facet-reflect" version = "0.44.1" @@ -432,6 +374,41 @@ version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" +[[package]] +name = "figue" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f33f286df173a047e864b39279b14de5e08dc5c7c5c719f81e96a8602049d4dd" +dependencies = [ + "ariadne", + "camino", + "facet", + "facet-core", + "facet-error", + "facet-format", + "facet-json", + "facet-pretty", + "facet-reflect", + "figue-attrs", + "heck", + "indexmap", + "owo-colors", + "strip-ansi-escapes", + "strsim", + "supports-color 3.0.2", + "tracing", + "unicode-width", +] + +[[package]] +name = "figue-attrs" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b09be1cd2a5c7295aa5dae9dd5585db38b3ab59c751336ebd4d692b867415703" +dependencies = [ + "facet", +] + [[package]] name = "find-msvc-tools" version = "0.1.9" @@ -506,6 +483,12 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" +[[package]] +name = "hermit-abi" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc0fef456e4baa96da950455cd02c081ca953b141298e41db3fc7e36b1da849c" + [[package]] name = "id-arena" version = "2.3.0" @@ -544,10 +527,21 @@ dependencies = [ ] [[package]] -name = "is_terminal_polyfill" -version = "1.70.2" +name = "is-terminal" +version = "0.4.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3640c1c38b8e4e43584d8df18be5fc6b0aa314ce6ebf51b53313d4306cca8e46" +dependencies = [ + "hermit-abi", + "libc", + "windows-sys", +] + +[[package]] +name = "is_ci" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" +checksum = "7655c9839580ee829dfacba1d1278c2b7883e50a277ff7541299489d6bdfdc45" [[package]] name = "itoa" @@ -598,10 +592,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" [[package]] -name = "once_cell_polyfill" -version = "1.70.2" +name = "owo-colors" +version = "4.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d211803b9b6b570f68772237e415a029d5a50c65d382910b879fb19d3271f94d" +dependencies = [ + "supports-color 2.1.0", + "supports-color 3.0.2", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" [[package]] name = "prettyplease" @@ -780,12 +784,40 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b2231b7c3057d5e4ad0156fb3dc807d900806020c5ffa3ee6ff2c8c76fb8520" +[[package]] +name = "strip-ansi-escapes" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a8f8038e7e7969abb3f1b7c2a811225e9296da208539e0f79c5251d6cac0025" +dependencies = [ + "vte", +] + [[package]] name = "strsim" version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" +[[package]] +name = "supports-color" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6398cde53adc3c4557306a96ce67b302968513830a77a95b2b17305d9719a89" +dependencies = [ + "is-terminal", + "is_ci", +] + +[[package]] +name = "supports-color" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c64fc7232dd8d2e4ac5ce4ef302b1d81e0b80d055b9d77c7c4f51f6aa4c867d6" +dependencies = [ + "is_ci", +] + [[package]] name = "syn" version = "2.0.117" @@ -819,6 +851,37 @@ dependencies = [ "winnow", ] +[[package]] +name = "tracing" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" +dependencies = [ + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" +dependencies = [ + "once_cell", +] + [[package]] name = "tree-sitter" version = "0.26.5" @@ -871,6 +934,12 @@ version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" +[[package]] +name = "unicode-width" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254" + [[package]] name = "unicode-xid" version = "0.2.6" @@ -888,18 +957,21 @@ dependencies = [ "rustc-hash", ] -[[package]] -name = "utf8parse" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" - [[package]] name = "version_check" version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" +[[package]] +name = "vte" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "231fdcd7ef3037e8330d8e17e61011a2c244126acc0a982f4040ac3f9f0bc077" +dependencies = [ + "memchr", +] + [[package]] name = "wait-timeout" version = "0.2.1" @@ -1070,6 +1142,12 @@ dependencies = [ "wasmparser", ] +[[package]] +name = "yansi" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfe53a6657fd280eaa890a3bc59152892ffa3e30101319d168b781ed6529b049" + [[package]] name = "zmij" version = "1.0.21" diff --git a/crates/bough-core/Cargo.toml b/crates/bough-core/Cargo.toml index 7462d514..2354099f 100644 --- a/crates/bough-core/Cargo.toml +++ b/crates/bough-core/Cargo.toml @@ -6,11 +6,11 @@ license.workspace = true [dependencies] bough-typed-hash = { path = "../bough-typed-hash" } -clap = { version = "4.5.60", features = ["derive"] } facet = "0.44" facet-json = "0.44.1" facet-toml = "0.44" facet-value = "0.44" +figue = "2.0.0" glob = "0.3" rand = "0.10.0" tree-sitter = "0.26" diff --git a/crates/bough-core/SPEC.md b/crates/bough-core/SPEC.md index bd91cd2c..84fb6b68 100644 --- a/crates/bough-core/SPEC.md +++ b/crates/bough-core/SPEC.md @@ -184,6 +184,18 @@ MutantIter impls Iter core[mutant.iter.find] MutantIter uses its driver to walk its file and find all mutants we support +core[mutant.iter.skip.kind] +MutantIter should be configureable to skip all mutants of specific kinds + +core[mutant.iter.skip.kind.multiple] +it should be possible to skip multiple kinds of mutant + +core[mutant.iter.skip.query] +MutantIter should be configureable to skip all mutants that match a specified ts lisp-style query + +core[mutant.iter.skip.query.multiple] +it should be possible provide multiple skip ts queries + core[mutant.iter.find.js.statement] MutantIter finds javascript statement blocks diff --git a/crates/bough-core/src/config.rs b/crates/bough-core/src/config.rs index 1f56338d..6adcc95f 100644 --- a/crates/bough-core/src/config.rs +++ b/crates/bough-core/src/config.rs @@ -21,17 +21,14 @@ pub enum Outcome { PartialOrd, Ord, Facet, - clap::ValueEnum, bough_typed_hash::HashInto, )] #[facet(rename_all = "lowercase")] #[repr(u8)] pub enum LanguageId { #[facet(rename = "js")] - #[value(alias = "js")] Javascript, #[facet(rename = "ts")] - #[value(alias = "ts")] Typescript, } @@ -57,7 +54,7 @@ pub struct TimeoutConfig { pub(crate) relative: Option, } -#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Facet, clap::ValueEnum)] +#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Facet)] #[facet(rename_all = "lowercase")] #[repr(u8)] pub enum OrderingConfig { @@ -105,12 +102,13 @@ pub enum MutantSkipConfig { } #[derive(Debug, Clone, PartialEq, Facet)] +#[facet(default)] pub struct Config { #[facet(default = 1u32)] pub(crate) threads: u32, #[facet(default = PathBuf::from("./.bough"))] pub(crate) bough_dir: PathBuf, - #[facet(skip, default = PathBuf::new())] + #[facet(default = PathBuf::new())] pub(crate) source_dir: PathBuf, #[facet(default)] pub(crate) ordering: OrderingConfig, @@ -119,6 +117,7 @@ pub struct Config { pub(crate) pwd: Option, #[facet(default)] pub(crate) timeout: TimeoutConfig, + #[facet(default)] pub(crate) env: HashMap, pub(crate) init: Option, pub(crate) reset: Option, @@ -126,6 +125,7 @@ pub struct Config { pub(crate) test_ids: Option, #[facet(default)] pub(crate) files: FileSourceConfig, + #[facet(default)] pub(crate) mutate: HashMap, } @@ -150,81 +150,30 @@ impl Default for Config { } } -// core[impl config.partials] -pub struct ConfigBuilder { - value: facet_value::Value, - source_dir: PathBuf, -} +pub struct TomlFormat; -impl ConfigBuilder { - pub fn new(source_dir: PathBuf) -> Self { - Self { - value: facet_value::Value::from_iter(std::iter::empty::<(&str, facet_value::Value)>()), - source_dir, - } +impl figue::ConfigFormat for TomlFormat { + fn extensions(&self) -> &[&str] { + &["toml"] } - pub fn from_toml(self, toml_str: &str) -> Result { - let value: facet_value::Value = - facet_toml::from_str(toml_str).map_err(|e| ConfigError::Deserialize(e.to_string()))?; - Ok(Self { value, ..self }) + fn parse(&self, contents: &str) -> Result { + let value: facet_value::Value = facet_toml::from_str(contents) + .map_err(|e| figue::ConfigFormatError::new(e.to_string()))?; + let json_str = facet_json::to_string(&value) + .map_err(|e| figue::ConfigFormatError::new(e.to_string()))?; + figue::JsonFormat + .parse(&json_str) + .map_err(|e| figue::ConfigFormatError::new(e.to_string())) } - - pub fn override_with_toml(self, toml_str: &str) -> Result { - let patch: facet_value::Value = - facet_toml::from_str(toml_str).map_err(|e| ConfigError::Deserialize(e.to_string()))?; - Ok(Self { - value: Self::deep_merge(self.value, patch), - ..self - }) - } - - fn deep_merge(base: facet_value::Value, patch: facet_value::Value) -> facet_value::Value { - match (base.as_object(), patch.as_object()) { - (Some(base_obj), Some(patch_obj)) => { - let mut merged = base_obj.clone(); - for (k, v) in patch_obj.iter() { - let merged_val = if let Some(existing) = merged.remove(k) { - Self::deep_merge(existing, v.clone()) - } else { - v.clone() - }; - merged.insert(k.clone(), merged_val); - } - facet_value::Value::from(merged) - } - _ => patch, - } - } - - // core[impl config.source-dir] - pub fn build(self) -> Result { - let json_str = facet_json::to_string(&self.value) - .map_err(|e| ConfigError::Serialize(e.to_string()))?; - let mut config: Config = - facet_json::from_str(&json_str).map_err(|e| ConfigError::Deserialize(e.to_string()))?; - config.source_dir = self.source_dir; - Ok(config) - } -} - -#[derive(Debug)] -pub enum ConfigError { - Deserialize(String), - Serialize(String), } -impl std::fmt::Display for ConfigError { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - ConfigError::Deserialize(e) => write!(f, "failed to deserialize config: {e}"), - ConfigError::Serialize(e) => write!(f, "failed to serialize config: {e}"), - } - } +#[derive(Debug, Facet)] +pub struct Args { + #[facet(figue::config)] + pub config: Config, } -impl std::error::Error for ConfigError {} - #[cfg(test)] mod tests { use super::*; @@ -274,14 +223,26 @@ command = "npx vitest run" files.include = ["src/**/*.ts"] "#; - fn builder_from(s: &str) -> ConfigBuilder { - ConfigBuilder::new(PathBuf::new()).from_toml(s).unwrap() + fn parse_toml(s: &str) -> Config { + facet_toml::from_str(s).expect("failed to parse toml") + } + + fn parse_with_cli(toml: &str, cli_args: &[&str]) -> Args { + let config = figue::builder::() + .unwrap() + .file(|f| f.format(TomlFormat).content(toml, "config.toml")) + .cli(|cli| cli.args(cli_args.iter().copied())) + .build(); + figue::Driver::new(config) + .run() + .into_result() + .unwrap() + .value } #[test] fn deserialize_ideal_config() { - let config: Config = - facet_toml::from_str(IDEAL_CONFIG).expect("failed to parse ideal config"); + let config = parse_toml(IDEAL_CONFIG); assert_eq!(config.threads, 1); assert_eq!(config.bough_dir, PathBuf::from("./.bough")); @@ -306,8 +267,7 @@ files.include = ["src/**/*.ts"] #[test] fn deserialize_minimal_config() { - let config: Config = - facet_toml::from_str(MINIMAL_CONFIG).expect("failed to parse minimal config"); + let config = parse_toml(MINIMAL_CONFIG); assert_eq!(config.threads, 1); assert_eq!(config.bough_dir, PathBuf::from("./.bough")); @@ -328,76 +288,75 @@ files.include = ["src/**/*.ts"] assert!(ts_mutate.mutants.skip.is_empty()); } - fn build_with_override(base: &str, patch: &str) -> Config { - builder_from(base) - .override_with_toml(patch) - .unwrap() - .build() - .unwrap() + #[test] + fn defaults_are_sane() { + let config = parse_toml(""); + assert_eq!(config.threads, 1); + assert_eq!(config.bough_dir, PathBuf::from("./.bough")); + assert!(config.init.is_none() && config.reset.is_none() && config.test.is_none()); } - // core[verify config.partials] #[test] - fn override_scalar() { - let config = build_with_override("", "threads = 4"); - assert_eq!(config.threads, 4); + fn project_bough_config_parses() { + let toml_str = include_str!("../../../bough.config.toml"); + parse_toml(toml_str); + } + + #[test] + fn figue_defaults_only() { + let config = figue::builder::() + .unwrap() + .cli(|cli| cli.args(std::iter::empty::<&str>())) + .build(); + let result = figue::Driver::new(config).run().into_result(); + assert!(result.is_ok(), "figue defaults failed: {:?}", result.err()); } // core[verify config.partials] #[test] - fn override_bough_dir() { - let config = build_with_override(IDEAL_CONFIG, r#"bough_dir = "/override""#); - assert_eq!(config.bough_dir, PathBuf::from("/override")); + fn cli_override_shallow_scalar() { + let args = parse_with_cli("", &["--config.threads", "4"]); + assert_eq!(args.config.threads, 4); } // core[verify config.partials] #[test] - fn override_vec_replaces() { - let config = build_with_override( - MINIMAL_CONFIG, - r#" - [test] - command = "npm test" - "#, - ); - assert_eq!(config.test.as_ref().unwrap().command, "npm test"); + fn cli_override_shallow_path() { + let args = parse_with_cli(IDEAL_CONFIG, &["--config.bough-dir", "/override"]); + assert_eq!(args.config.bough_dir, PathBuf::from("/override")); } // core[verify config.partials] #[test] - fn override_map_adds() { - let config = build_with_override( - MINIMAL_CONFIG, - r#" - [test.env] - FOO = "bar" - "#, - ); - assert_eq!(config.test.as_ref().unwrap().env["FOO"], "bar"); + fn cli_override_shallow_enum() { + let args = parse_with_cli(IDEAL_CONFIG, &["--config.ordering", "alphabetical"]); + assert_eq!(args.config.ordering, OrderingConfig::Alphabetical); } // core[verify config.partials] #[test] - fn override_deep_merge_phase() { - let config = build_with_override(IDEAL_CONFIG, r#"treat_timeouts_as = "Caught""#); - assert_eq!(config.treat_timeouts_as, Outcome::Caught); - assert!(config.init.is_some()); + fn cli_override_deep_nested_command() { + let args = parse_with_cli(MINIMAL_CONFIG, &["--config.test.command", "npm test"]); + assert_eq!(args.config.test.as_ref().unwrap().command, "npm test"); } + // core[verify config.partials] #[test] - fn defaults_are_sane() { - let config: Config = facet_toml::from_str("").expect("empty config should parse"); - assert_eq!(config.threads, 1); - assert_eq!(config.bough_dir, PathBuf::from("./.bough")); - assert!(config.init.is_none() && config.reset.is_none() && config.test.is_none()); + fn cli_override_deep_timeout() { + let args = parse_with_cli( + IDEAL_CONFIG, + &["--config.test.timeout.absolute", "60"], + ); + assert_eq!(args.config.test.as_ref().unwrap().timeout.absolute, Some(60)); + assert_eq!(args.config.test.as_ref().unwrap().timeout.relative, Some(3)); } - // core[verify config.source-dir] + // core[verify config.partials] #[test] - fn project_bough_config_parses() { - let toml_str = include_str!("../../../bough.config.toml"); - builder_from(toml_str) - .build() - .expect("bough.config.toml should parse without errors or invariant violations"); + fn cli_override_preserves_unrelated_fields() { + let args = parse_with_cli(IDEAL_CONFIG, &["--config.threads", "8"]); + assert_eq!(args.config.threads, 8); + assert!(args.config.init.is_some()); + assert_eq!(args.config.ordering, OrderingConfig::Alphabetical); } } -- knotmirror 0.0.1