summaryrefslogtreecommitdiff
path: root/tests/util
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2019-01-20 22:16:36 +0100
committerRobin Krahl <robin.krahl@ireas.org>2019-01-20 22:17:37 +0100
commit8c57d3ace0215adb3cd5edd0f18e8cc513f65ff1 (patch)
tree27eb8ac46b130e08d917a7b91da8b48a14b644b6 /tests/util
parent5da2735cfb8ccfaea1ebdee850ddd9fbd0bfb003 (diff)
parentd87859975dc158919ecd5bf11a1111a2da5fcb30 (diff)
downloadnitrokey-rs-8c57d3ace0215adb3cd5edd0f18e8cc513f65ff1.tar.gz
nitrokey-rs-8c57d3ace0215adb3cd5edd0f18e8cc513f65ff1.tar.bz2
Merge branch 'feature/error-refactoring' into next
RFC: https://lists.sr.ht/~ireas/nitrokey-rs-dev/%3C20190117000856.slgb6jwkwd3qu6ey%40localhost%3E
Diffstat (limited to 'tests/util')
-rw-r--r--tests/util/mod.rs81
1 files changed, 81 insertions, 0 deletions
diff --git a/tests/util/mod.rs b/tests/util/mod.rs
index cbf6b93..4a00a66 100644
--- a/tests/util/mod.rs
+++ b/tests/util/mod.rs
@@ -1,2 +1,83 @@
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);
+ };
+}
+
+#[macro_export]
+macro_rules! assert_cmu_err {
+ ($left:expr, $right:expr) => {
+ assert_err!(::nitrokey::Error::CommunicationError, $left, $right);
+ };
+}
+
+#[macro_export]
+macro_rules! assert_lib_err {
+ ($left:expr, $right:expr) => {
+ assert_err!(::nitrokey::Error::LibraryError, $left, $right);
+ };
+}