aboutsummaryrefslogtreecommitdiff
path: root/tests/util
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2019-01-17 14:21:44 +0000
committerRobin Krahl <robin.krahl@ireas.org>2019-01-20 22:15:29 +0100
commitd87859975dc158919ecd5bf11a1111a2da5fcb30 (patch)
tree27eb8ac46b130e08d917a7b91da8b48a14b644b6 /tests/util
parent17f9c30a0ace070cba856e4e89fcccedcab5e8e6 (diff)
downloadnitrokey-rs-d87859975dc158919ecd5bf11a1111a2da5fcb30.tar.gz
nitrokey-rs-d87859975dc158919ecd5bf11a1111a2da5fcb30.tar.bz2
Check specific error codes in the tests
If possible, check specific error codes instead of `is_err()`. This makes the code more readable and catches bugs resulting in the wrong error code. Also, using the assert_*_err and assert_ok macros yields error messages containing the expected and the actual value. To be able to use these macros with the `get_password_safe` method, we also have to implement `Debug` for `PasswordSafe` and `Device`.
Diffstat (limited to 'tests/util')
-rw-r--r--tests/util/mod.rs7
1 files changed, 7 insertions, 0 deletions
diff --git a/tests/util/mod.rs b/tests/util/mod.rs
index b1d3ea3..4a00a66 100644
--- a/tests/util/mod.rs
+++ b/tests/util/mod.rs
@@ -69,6 +69,13 @@ macro_rules! assert_cmd_err {
}
#[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);