From efb6fbffdb96c6acd197b8a7c4fe0ed9855a151e Mon Sep 17 00:00:00 2001 From: Daniel Mueller Date: Wed, 8 Jul 2020 09:16:56 -0700 Subject: Remove unwrap_str_err method from UnwrapError test trait With upcoming changes we intend to move towards a model where we do not distinguish the individual error variants the program deals with in a global enum. In preparation of such a change, this patch marks a first step in removing the UnwrapError test trait, which relies on the existence of exactly such typed errors. In particular, we remove the unwrap_str_err method from it, basically falling back to just working with strings. --- src/tests/config.rs | 6 ++++-- src/tests/encrypted.rs | 9 ++++++--- src/tests/mod.rs | 16 ---------------- src/tests/status.rs | 5 +++-- 4 files changed, 13 insertions(+), 23 deletions(-) diff --git a/src/tests/config.rs b/src/tests/config.rs index fa311d5..3542ecf 100644 --- a/src/tests/config.rs +++ b/src/tests/config.rs @@ -55,8 +55,10 @@ $"#, #[test_device] fn set_wrong_usage(model: nitrokey::Model) { - let res = Nitrocli::with_model(model).handle(&["config", "set", "--numlock", "2", "-N"]); - let err = res.unwrap_str_err(); + let err = Nitrocli::with_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, diff --git a/src/tests/encrypted.rs b/src/tests/encrypted.rs index aed2662..a47c3c9 100644 --- a/src/tests/encrypted.rs +++ b/src/tests/encrypted.rs @@ -1,7 +1,7 @@ // encrypted.rs // ************************************************************************* -// * Copyright (C) 2019 Daniel Mueller (deso@posteo.net) * +// * Copyright (C) 2019-2020 Daniel Mueller (deso@posteo.net) * // * * // * This program is free software: you can redistribute it and/or modify * // * it under the terms of the GNU General Public License as published by * @@ -61,9 +61,12 @@ $"#, #[test_device(pro)] fn encrypted_open_on_pro(model: nitrokey::Model) { - let res = Nitrocli::with_model(model).handle(&["encrypted", "open"]); + let err = Nitrocli::with_model(model) + .handle(&["encrypted", "open"]) + .unwrap_err() + .to_string(); assert_eq!( - res.unwrap_str_err(), + err, "This command is only available on the Nitrokey Storage", ); } diff --git a/src/tests/mod.rs b/src/tests/mod.rs index abf63e3..fd2f9e0 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -37,8 +37,6 @@ mod unencrypted; /// A trait simplifying checking for expected errors. pub trait UnwrapError { - /// Unwrap an Error::Error variant. - fn unwrap_str_err(self) -> String; /// Unwrap a Error::CommandError variant. fn unwrap_cmd_err(self) -> (Option<&'static str>, nitrokey::CommandError); /// Unwrap a Error::LibraryError variant. @@ -49,20 +47,6 @@ impl UnwrapError for crate::Result where T: fmt::Debug, { - fn unwrap_str_err(self) -> String { - match self.unwrap_err() { - crate::Error::ClapError(err) => { - if err.use_stderr() { - err.message - } else { - String::new() - } - } - crate::Error::Error(err) => err, - err => panic!("Unexpected error variant found: {:?}", err), - } - } - fn unwrap_cmd_err(self) -> (Option<&'static str>, nitrokey::CommandError) { match self.unwrap_err() { crate::Error::NitrokeyError(ctx, err) => match err { diff --git a/src/tests/status.rs b/src/tests/status.rs index c9f4976..e80fadc 100644 --- a/src/tests/status.rs +++ b/src/tests/status.rs @@ -1,7 +1,7 @@ // status.rs // ************************************************************************* -// * Copyright (C) 2019 Daniel Mueller (deso@posteo.net) * +// * Copyright (C) 2019-2020 Daniel Mueller (deso@posteo.net) * // * * // * This program is free software: you can redistribute it and/or modify * // * it under the terms of the GNU General Public License as published by * @@ -33,7 +33,8 @@ fn not_found_raw() { #[test_device] fn not_found() { let res = Nitrocli::new().handle(&["status"]); - assert_eq!(res.unwrap_str_err(), "Nitrokey device not found"); + let err = res.unwrap_err().to_string(); + assert_eq!(err, "Nitrokey device not found"); } #[test_device(pro)] -- cgit v1.2.3