test(error): increasing test coverage of error module

This commit is contained in:
Marius Seritan
2015-05-26 20:15:06 -07:00
parent 9dc85279ac
commit 59d8e80e6c

View File

@@ -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] #[test]
fn test_from() { fn test_from() {
from!(io::Error::new(io::ErrorKind::Other, "other") => Io(..)); from_and_cause!(io::Error::new(io::ErrorKind::Other, "other") => Io(..));
from!(url::ParseError::EmptyHost => Uri(..)); 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")) => Io(..));
from!(SslError::SslSessionClosed => Ssl(..));
from!(httparse::Error::HeaderName => Header); from!(httparse::Error::HeaderName => Header);