diff options
Diffstat (limited to 'nitrocli/src/tests/mod.rs')
-rw-r--r-- | nitrocli/src/tests/mod.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/nitrocli/src/tests/mod.rs b/nitrocli/src/tests/mod.rs index 474b43c..cb0d09e 100644 --- a/nitrocli/src/tests/mod.rs +++ b/nitrocli/src/tests/mod.rs @@ -17,6 +17,8 @@ // * along with this program. If not, see <http://www.gnu.org/licenses/>. * // ************************************************************************* +use std::fmt; + use nitrokey_test::test as test_device; // TODO: This is a hack to make the nitrokey-test crate work across @@ -63,6 +65,24 @@ impl IntoArg for nitrokey::DeviceWrapper { } } +/// A trait simplifying checking for expected errors. +pub trait UnwrapError { + /// Unwrap an Error::Error variant. + fn unwrap_str_err(self) -> String; +} + +impl<T> UnwrapError for crate::Result<T> +where + T: fmt::Debug, +{ + fn unwrap_str_err(self) -> String { + match self.unwrap_err() { + crate::Error::Error(err) => err, + err => panic!("Unexpected error variant found: {:?}", err), + } + } +} + mod nitrocli { use super::*; |