aboutsummaryrefslogtreecommitdiff
path: root/tests/util
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2019-01-28 19:45:40 +0000
committerRobin Krahl <robin.krahl@ireas.org>2019-01-28 19:48:33 +0000
commitd1262390573b758ac4aa610eff96a1b5dcb9f3d6 (patch)
tree445a3251f134c1794aabf587a7ef1ced01b960ea /tests/util
parent52df93249f27ae803bada0451d7380bc3d596007 (diff)
downloadnitrokey-rs-d1262390573b758ac4aa610eff96a1b5dcb9f3d6.tar.gz
nitrokey-rs-d1262390573b758ac4aa610eff96a1b5dcb9f3d6.tar.bz2
Add assert_any_ok macro to unit tests
Sometimes we cannot use assert_ok! as we can’t compare the Ok value (or do not want to). For these cases, this patch adds the new assert_any_ok macro to use instead of assert!(x.is_ok()). The advantage is that the error information is not discarded but printed in a helpful error message.
Diffstat (limited to 'tests/util')
-rw-r--r--tests/util/mod.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/util/mod.rs b/tests/util/mod.rs
index 2bda9ba..bd207a9 100644
--- a/tests/util/mod.rs
+++ b/tests/util/mod.rs
@@ -22,6 +22,21 @@ macro_rules! unwrap_ok {
}
#[macro_export]
+macro_rules! assert_any_ok {
+ ($val:expr) => {{
+ match &$val {
+ Ok(_) => {}
+ 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 {