From 0cc4371d138d5e98cd22813f10689cb089eef378 Mon Sep 17 00:00:00 2001 From: Daniel Mueller Date: Mon, 24 Aug 2020 18:04:20 -0700 Subject: Introduce builder-inspired way for configuring Nitrocli instance In the future we would like to provide more ways for tests to create a Nitrocli instance. In order to prevent explosion of with_XXX methods for each possible combination of arguments, this change allows for an easier configuration of an existing object with builder-pattern-inspired modifier methods. --- src/tests/config.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/tests/config.rs') diff --git a/src/tests/config.rs b/src/tests/config.rs index 75ec983..babd32c 100644 --- a/src/tests/config.rs +++ b/src/tests/config.rs @@ -34,17 +34,20 @@ $"#, ) .unwrap(); - let out = Nitrocli::with_model(model).handle(&["config", "get"])?; + let out = Nitrocli::new().model(model).handle(&["config", "get"])?; + assert!(re.is_match(&out), out); Ok(()) } #[test_device] fn set_wrong_usage(model: nitrokey::Model) { - let err = Nitrocli::with_model(model) + let err = Nitrocli::new() + .model(model) .handle(&["config", "set", "--numlock", "2", "-N"]) .unwrap_err() .to_string(); + assert!( err.contains("The argument '--numlock ' cannot be used with '--no-numlock'"), err, @@ -53,7 +56,7 @@ fn set_wrong_usage(model: nitrokey::Model) { #[test_device] fn set_get(model: nitrokey::Model) -> anyhow::Result<()> { - let mut ncli = Nitrocli::with_model(model); + let mut ncli = Nitrocli::new().model(model); let _ = ncli.handle(&["config", "set", "-s", "1", "-c", "0", "-N"])?; let re = regex::Regex::new( -- cgit v1.2.3