From 59d8e80e6c61bfbfb4c1289d8315acb0fdf9ff4e Mon Sep 17 00:00:00 2001 From: Marius Seritan Date: Tue, 26 May 2015 20:15:06 -0700 Subject: [PATCH 1/2] test(error): increasing test coverage of error module --- src/error.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/error.rs b/src/error.rs index a85eff20..3cf818cc 100644 --- a/src/error.rs +++ b/src/error.rs @@ -135,14 +135,27 @@ mod tests { } } + macro_rules! from_and_cause { + ($from:expr => $error:pat) => { + match Error::from($from) { + e @ $error => { + let desc = e.cause().unwrap().description(); + assert_eq!(desc, $from.description().to_owned()); + assert_eq!(desc, e.description()); + }, + _ => panic!("{:?}", $from) + } + } + } + #[test] fn test_from() { - from!(io::Error::new(io::ErrorKind::Other, "other") => Io(..)); - from!(url::ParseError::EmptyHost => Uri(..)); + from_and_cause!(io::Error::new(io::ErrorKind::Other, "other") => Io(..)); + from_and_cause!(url::ParseError::EmptyHost => Uri(..)); + from_and_cause!(SslError::SslSessionClosed => Ssl(..)); from!(SslError::StreamError(io::Error::new(io::ErrorKind::Other, "ssl")) => Io(..)); - from!(SslError::SslSessionClosed => Ssl(..)); from!(httparse::Error::HeaderName => Header); From b24e1a5e6c479aedf719bd491366079331ccaec2 Mon Sep 17 00:00:00 2001 From: Marius Seritan Date: Tue, 26 May 2015 20:31:24 -0700 Subject: [PATCH 2/2] test(error): increasing test coverage of error module 2 --- src/error.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/error.rs b/src/error.rs index 3cf818cc..59cc273b 100644 --- a/src/error.rs +++ b/src/error.rs @@ -129,7 +129,9 @@ mod tests { macro_rules! from { ($from:expr => $error:pat) => { match Error::from($from) { - $error => (), + e @ $error => { + assert!(e.description().len() > 5); + } , _ => panic!("{:?}", $from) } } @@ -155,7 +157,7 @@ mod tests { from_and_cause!(url::ParseError::EmptyHost => Uri(..)); from_and_cause!(SslError::SslSessionClosed => Ssl(..)); - from!(SslError::StreamError(io::Error::new(io::ErrorKind::Other, "ssl")) => Io(..)); + from!(SslError::StreamError(io::Error::new(io::ErrorKind::Other, "ssl negotiation")) => Io(..)); from!(httparse::Error::HeaderName => Header);