aboutsummaryrefslogtreecommitdiff
path: root/tests/util
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2019-01-28 19:40:49 +0000
committerRobin Krahl <robin.krahl@ireas.org>2019-01-28 19:40:49 +0000
commit52df93249f27ae803bada0451d7380bc3d596007 (patch)
treecbaefc826acc68514d2c16e93666ec639f7e1c5b /tests/util
parent5d7bb087707915a78149da7492cccd772db2657e (diff)
downloadnitrokey-rs-52df93249f27ae803bada0451d7380bc3d596007.tar.gz
nitrokey-rs-52df93249f27ae803bada0451d7380bc3d596007.tar.bz2
Add unwrap_ok macro to replace unwrap in unit tests
The unwrap error message is not very useful. This patch adds the unwrap_ok macro that is basically the same as unwrap but prints a more readable error message.
Diffstat (limited to 'tests/util')
-rw-r--r--tests/util/mod.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/util/mod.rs b/tests/util/mod.rs
index 49ec13e..2bda9ba 100644
--- a/tests/util/mod.rs
+++ b/tests/util/mod.rs
@@ -1,10 +1,27 @@
// Copyright (C) 2018-2019 Robin Krahl <robin.krahl@ireas.org>
// SPDX-License-Identifier: MIT
+#[allow(dead_code)]
pub static ADMIN_PASSWORD: &str = "12345678";
+#[allow(dead_code)]
pub static USER_PASSWORD: &str = "123456";
#[macro_export]
+macro_rules! unwrap_ok {
+ ($val:expr) => {{
+ match $val {
+ Ok(val) => val,
+ Err(err) => panic!(
+ r#"assertion failed: `(left == right)`
+ left: `Ok(_)`,
+ right: `Err({:?})`"#,
+ err
+ ),
+ }
+ }};
+}
+
+#[macro_export]
macro_rules! assert_ok {
($left:expr, $right:expr) => {{
match &$right {