summaryrefslogtreecommitdiff
path: root/tests/util
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2019-01-17 03:49:13 +0000
committerRobin Krahl <robin.krahl@ireas.org>2019-01-20 21:08:26 +0000
commitc43b63b70ee32f9fa8e980d89eff5383931f5c39 (patch)
tree8db1e07e151579d53957f3657eb3e0cfe8dcc723 /tests/util
parent94390aadc8a3997d379bf5e4c0bc00c2a9669a34 (diff)
downloadnitrokey-rs-c43b63b70ee32f9fa8e980d89eff5383931f5c39.tar.gz
nitrokey-rs-c43b63b70ee32f9fa8e980d89eff5383931f5c39.tar.bz2
Add assert_cmd_err and assert_ok macros to tests
These macros allow easier comparisions using the new error type. This patch fixes all tests and updates nitrokey-test to 0.2.0 so that it integrates with the new error structure. Some tests may still fail until CommunicationError::NotConnected is actually returned.
Diffstat (limited to 'tests/util')
-rw-r--r--tests/util/mod.rs67
1 files changed, 67 insertions, 0 deletions
diff --git a/tests/util/mod.rs b/tests/util/mod.rs
index cbf6b93..f0d0bb5 100644
--- a/tests/util/mod.rs
+++ b/tests/util/mod.rs
@@ -1,2 +1,69 @@
pub static ADMIN_PASSWORD: &str = "12345678";
pub static USER_PASSWORD: &str = "123456";
+
+#[macro_export]
+macro_rules! assert_ok {
+ ($left:expr, $right:expr) => {{
+ match &$right {
+ Ok(right) => match &$left {
+ left => {
+ if !(*left == *right) {
+ panic!(
+ r#"assertion failed: `(left == right)`
+ left: `{:?}`,
+ right: `{:?}`"#,
+ left, right
+ )
+ }
+ }
+ },
+ Err(right_err) => panic!(
+ r#"assertion failed: `(left == right)`
+ left: `Ok({:?})`,
+ right: `Err({:?})`"#,
+ $left, right_err
+ ),
+ }
+ }};
+}
+
+#[macro_export]
+macro_rules! assert_err {
+ ($err:path, $left:expr, $right:expr) => {
+ match &$right {
+ Err($err(ref right_err)) => match &$left {
+ left_err => {
+ if !(*left_err == *right_err) {
+ panic!(
+ r#"assertion failed: `(left == right)`
+ left: `{:?}`,
+ right: `{:?}`"#,
+ left_err, right_err
+ )
+ }
+ }
+ },
+ Err(ref right_err) => panic!(
+ r#"assertion failed: `(left == right)`
+ left: `{:?}`,
+ right: `{:?}`"#,
+ $err($left),
+ right_err
+ ),
+ Ok(right_ok) => panic!(
+ r#"assertion failed: `(left == right)`
+ left: `Err({:?})`,
+ right: `Ok({:?})`"#,
+ $err($left),
+ right_ok
+ ),
+ }
+ };
+}
+
+#[macro_export]
+macro_rules! assert_cmd_err {
+ ($left:expr, $right:expr) => {
+ assert_err!(::nitrokey::Error::CommandError, $left, $right);
+ };
+}