summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/device.rs12
-rw-r--r--tests/pws.rs4
-rw-r--r--tests/util/mod.rs15
3 files changed, 23 insertions, 8 deletions
diff --git a/tests/device.rs b/tests/device.rs
index 67c2713..306b33f 100644
--- a/tests/device.rs
+++ b/tests/device.rs
@@ -55,9 +55,9 @@ fn connect_pro(device: Pro) {
assert_eq!(device.get_model(), nitrokey::Model::Pro);
drop(device);
- assert!(nitrokey::connect().is_ok());
- assert!(nitrokey::connect_model(nitrokey::Model::Pro).is_ok());
- assert!(nitrokey::Pro::connect().is_ok());
+ assert_any_ok!(nitrokey::connect());
+ assert_any_ok!(nitrokey::connect_model(nitrokey::Model::Pro));
+ assert_any_ok!(nitrokey::Pro::connect());
}
#[test_device]
@@ -65,9 +65,9 @@ fn connect_storage(device: Storage) {
assert_eq!(device.get_model(), nitrokey::Model::Storage);
drop(device);
- assert!(nitrokey::connect().is_ok());
- assert!(nitrokey::connect_model(nitrokey::Model::Storage).is_ok());
- assert!(nitrokey::Storage::connect().is_ok());
+ assert_any_ok!(nitrokey::connect());
+ assert_any_ok!(nitrokey::connect_model(nitrokey::Model::Storage));
+ assert_any_ok!(nitrokey::Storage::connect());
}
fn assert_empty_serial_number() {
diff --git a/tests/pws.rs b/tests/pws.rs
index 3ec7e38..32dc8f7 100644
--- a/tests/pws.rs
+++ b/tests/pws.rs
@@ -46,12 +46,12 @@ fn enable(device: DeviceWrapper) {
CommandError::WrongPassword,
device.get_password_safe(&(USER_PASSWORD.to_owned() + "123"))
);
- assert!(device.get_password_safe(USER_PASSWORD).is_ok());
+ assert_any_ok!(device.get_password_safe(USER_PASSWORD));
assert_cmd_err!(
CommandError::WrongPassword,
device.get_password_safe(ADMIN_PASSWORD)
);
- assert!(device.get_password_safe(USER_PASSWORD).is_ok());
+ assert_any_ok!(device.get_password_safe(USER_PASSWORD));
}
#[test_device]
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 {