Skip to content

Commit

Permalink
Merge pull request #538 from hyperium/error-cov
Browse files Browse the repository at this point in the history
test(error): increasing test coverage of error module
  • Loading branch information
seanmonstar committed May 19, 2015
2 parents c8086db + d7167e8 commit ca6cf2b
Showing 1 changed file with 49 additions and 1 deletion.
50 changes: 49 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ impl StdError for Error {
fn description(&self) -> &str {
match *self {
Method => "Invalid Method specified",
Uri(_) => "Invalid Request URI specified",
Version => "Invalid HTTP version specified",
Header => "Invalid Header provided",
TooLarge => "Message head is too large",
Status => "Invalid Status provided",
Uri(ref e) => e.description(),
Io(ref e) => e.description(),
Ssl(ref e) => e.description(),
}
Expand Down Expand Up @@ -107,3 +107,51 @@ impl From<httparse::Error> for Error {
}
}
}

#[cfg(test)]
mod tests {
use std::error::Error as StdError;
use std::io;
use httparse;
use openssl::ssl::error::SslError;
use url;
use super::Error;
use super::Error::*;

#[test]
fn test_cause() {
let orig = io::Error::new(io::ErrorKind::Other, "other");
let desc = orig.description().to_owned();
let e = Io(orig);
assert_eq!(e.cause().unwrap().description(), desc);
}

macro_rules! from {
($from:expr => $error:pat) => {
match Error::from($from) {
$error => (),
_ => panic!("{:?}", $from)
}
}
}

#[test]
fn test_from() {

from!(io::Error::new(io::ErrorKind::Other, "other") => Io(..));
from!(url::ParseError::EmptyHost => Uri(..));

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);
from!(httparse::Error::HeaderValue => Header);
from!(httparse::Error::NewLine => Header);
from!(httparse::Error::Status => Status);
from!(httparse::Error::Token => Header);
from!(httparse::Error::TooManyHeaders => TooLarge);
from!(httparse::Error::Version => Version);
}
}

0 comments on commit ca6cf2b

Please sign in to comment.