From df34b6565fdcc6cadedac9c42e6091bc3c6798c0 Mon Sep 17 00:00:00 2001 From: Daniel Mueller Date: Thu, 9 Jul 2020 20:10:21 -0700 Subject: Refrain from using Error::Error variant in pinentry tests The pinentry tests currently expect the Error::Error variant to be reported for failures. This patch adjusts the tests to merely compare strings and ignore the exact type of error. Doing so will make it easier to switch to using anyhow for error handling. --- src/pinentry.rs | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/pinentry.rs b/src/pinentry.rs index d1387f4..e1dec3e 100644 --- a/src/pinentry.rs +++ b/src/pinentry.rs @@ -348,26 +348,16 @@ mod tests { let response = "ERR ".to_string() + error + "\n"; let expected = error; - let error = parse_pinentry_pin(response); - - if let Error::Error(ref e) = error.err().unwrap() { - assert_eq!(e, &expected); - } else { - panic!("Unexpected result"); - } + let error = parse_pinentry_pin(response).unwrap_err(); + assert_eq!(error.to_string(), expected) } #[test] fn parse_pinentry_pin_unexpected() { let response = "foobar\n"; let expected = format!("Unexpected response: {}", response); - let error = parse_pinentry_pin(response); - - if let Error::Error(ref e) = error.err().unwrap() { - assert_eq!(e, &expected); - } else { - panic!("Unexpected result"); - } + let error = parse_pinentry_pin(response).unwrap_err(); + assert_eq!(error.to_string(), expected) } #[test] @@ -384,12 +374,7 @@ mod tests { fn parse_pinentry_response_unexpected() { let response = "ERR 42"; let expected = format!("Unexpected response: {}", response); - let error = parse_pinentry_response(response); - - if let Error::Error(ref e) = error.err().unwrap() { - assert_eq!(e, &expected); - } else { - panic!("Unexpected result"); - } + let error = parse_pinentry_response(response).unwrap_err(); + assert_eq!(error.to_string(), expected) } } -- cgit v1.2.3