1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-28 09:42:40 +01:00

use unreachable instead of panic

This commit is contained in:
Nikolay Kim 2018-03-29 15:55:27 -07:00
parent 3e98177fad
commit 145010a2b0
6 changed files with 33 additions and 33 deletions

View File

@ -766,7 +766,7 @@ mod tests {
e @ $error => { e @ $error => {
assert!(format!("{}", e).len() >= 5); assert!(format!("{}", e).len() >= 5);
} , } ,
e => panic!("{:?}", e) e => unreachable!("{:?}", e)
} }
} }
} }
@ -778,7 +778,7 @@ mod tests {
let desc = format!("{}", e.cause().unwrap()); let desc = format!("{}", e.cause().unwrap());
assert_eq!(desc, $from.description().to_owned()); assert_eq!(desc, $from.description().to_owned());
}, },
_ => panic!("{:?}", $from) _ => unreachable!("{:?}", $from)
} }
} }
} }

View File

@ -581,27 +581,27 @@ mod tests {
let req = TestRequest::with_header(header::CONTENT_LENGTH, "xxxx").finish(); let req = TestRequest::with_header(header::CONTENT_LENGTH, "xxxx").finish();
match req.body().poll().err().unwrap() { match req.body().poll().err().unwrap() {
PayloadError::UnknownLength => (), PayloadError::UnknownLength => (),
_ => panic!("error"), _ => unreachable!("error"),
} }
let req = TestRequest::with_header(header::CONTENT_LENGTH, "1000000").finish(); let req = TestRequest::with_header(header::CONTENT_LENGTH, "1000000").finish();
match req.body().poll().err().unwrap() { match req.body().poll().err().unwrap() {
PayloadError::Overflow => (), PayloadError::Overflow => (),
_ => panic!("error"), _ => unreachable!("error"),
} }
let mut req = HttpRequest::default(); let mut req = HttpRequest::default();
req.payload_mut().unread_data(Bytes::from_static(b"test")); req.payload_mut().unread_data(Bytes::from_static(b"test"));
match req.body().poll().ok().unwrap() { match req.body().poll().ok().unwrap() {
Async::Ready(bytes) => assert_eq!(bytes, Bytes::from_static(b"test")), Async::Ready(bytes) => assert_eq!(bytes, Bytes::from_static(b"test")),
_ => panic!("error"), _ => unreachable!("error"),
} }
let mut req = HttpRequest::default(); let mut req = HttpRequest::default();
req.payload_mut().unread_data(Bytes::from_static(b"11111111111111")); req.payload_mut().unread_data(Bytes::from_static(b"11111111111111"));
match req.body().limit(5).poll().err().unwrap() { match req.body().limit(5).poll().err().unwrap() {
PayloadError::Overflow => (), PayloadError::Overflow => (),
_ => panic!("error"), _ => unreachable!("error"),
} }
} }
} }

View File

@ -632,7 +632,7 @@ mod tests {
let headers = HeaderMap::new(); let headers = HeaderMap::new();
match Multipart::boundary(&headers) { match Multipart::boundary(&headers) {
Err(MultipartError::NoContentType) => (), Err(MultipartError::NoContentType) => (),
_ => panic!("should not happen"), _ => unreachable!("should not happen"),
} }
let mut headers = HeaderMap::new(); let mut headers = HeaderMap::new();
@ -641,7 +641,7 @@ mod tests {
match Multipart::boundary(&headers) { match Multipart::boundary(&headers) {
Err(MultipartError::ParseContentType) => (), Err(MultipartError::ParseContentType) => (),
_ => panic!("should not happen"), _ => unreachable!("should not happen"),
} }
let mut headers = HeaderMap::new(); let mut headers = HeaderMap::new();
@ -650,7 +650,7 @@ mod tests {
header::HeaderValue::from_static("multipart/mixed")); header::HeaderValue::from_static("multipart/mixed"));
match Multipart::boundary(&headers) { match Multipart::boundary(&headers) {
Err(MultipartError::Boundary) => (), Err(MultipartError::Boundary) => (),
_ => panic!("should not happen"), _ => unreachable!("should not happen"),
} }
let mut headers = HeaderMap::new(); let mut headers = HeaderMap::new();

View File

@ -932,8 +932,8 @@ mod tests {
macro_rules! not_ready { macro_rules! not_ready {
($e:expr) => (match $e { ($e:expr) => (match $e {
Ok(Async::NotReady) => (), Ok(Async::NotReady) => (),
Err(err) => panic!("Unexpected error: {:?}", err), Err(err) => unreachable!("Unexpected error: {:?}", err),
_ => panic!("Should not be ready"), _ => unreachable!("Should not be ready"),
}) })
} }
@ -943,8 +943,8 @@ mod tests {
Vec::new(), KeepAlive::Os); Vec::new(), KeepAlive::Os);
match Reader::new().parse($e, &mut BytesMut::new(), &settings) { match Reader::new().parse($e, &mut BytesMut::new(), &settings) {
Ok(Async::Ready(req)) => req, Ok(Async::Ready(req)) => req,
Ok(_) => panic!("Eof during parsing http request"), Ok(_) => unreachable!("Eof during parsing http request"),
Err(err) => panic!("Error during parsing http request: {:?}", err), Err(err) => unreachable!("Error during parsing http request: {:?}", err),
} }
}) })
} }
@ -953,8 +953,8 @@ mod tests {
($e:expr) => ( ($e:expr) => (
match $e { match $e {
Ok(Async::Ready(req)) => req, Ok(Async::Ready(req)) => req,
Ok(_) => panic!("Eof during parsing http request"), Ok(_) => unreachable!("Eof during parsing http request"),
Err(err) => panic!("Error during parsing http request: {:?}", err), Err(err) => unreachable!("Error during parsing http request: {:?}", err),
} }
) )
} }
@ -968,10 +968,10 @@ mod tests {
match Reader::new().parse($e, &mut buf, &settings) { match Reader::new().parse($e, &mut buf, &settings) {
Err(err) => match err { Err(err) => match err {
ReaderError::Error(_) => (), ReaderError::Error(_) => (),
_ => panic!("Parse error expected"), _ => unreachable!("Parse error expected"),
}, },
_ => { _ => {
panic!("Error expected") unreachable!("Error expected")
} }
}} }}
) )
@ -991,7 +991,7 @@ mod tests {
assert_eq!(*req.method(), Method::GET); assert_eq!(*req.method(), Method::GET);
assert_eq!(req.path(), "/test"); assert_eq!(req.path(), "/test");
} }
Ok(_) | Err(_) => panic!("Error during parsing http request"), Ok(_) | Err(_) => unreachable!("Error during parsing http request"),
} }
} }
@ -1005,7 +1005,7 @@ mod tests {
let mut reader = Reader::new(); let mut reader = Reader::new();
match reader.parse(&mut buf, &mut readbuf, &settings) { match reader.parse(&mut buf, &mut readbuf, &settings) {
Ok(Async::NotReady) => (), Ok(Async::NotReady) => (),
_ => panic!("Error"), _ => unreachable!("Error"),
} }
buf.feed_data(".1\r\n\r\n"); buf.feed_data(".1\r\n\r\n");
@ -1015,7 +1015,7 @@ mod tests {
assert_eq!(*req.method(), Method::PUT); assert_eq!(*req.method(), Method::PUT);
assert_eq!(req.path(), "/test"); assert_eq!(req.path(), "/test");
} }
Ok(_) | Err(_) => panic!("Error during parsing http request"), Ok(_) | Err(_) => unreachable!("Error during parsing http request"),
} }
} }
@ -1033,7 +1033,7 @@ mod tests {
assert_eq!(*req.method(), Method::POST); assert_eq!(*req.method(), Method::POST);
assert_eq!(req.path(), "/test2"); assert_eq!(req.path(), "/test2");
} }
Ok(_) | Err(_) => panic!("Error during parsing http request"), Ok(_) | Err(_) => unreachable!("Error during parsing http request"),
} }
} }
@ -1052,7 +1052,7 @@ mod tests {
assert_eq!(req.path(), "/test"); assert_eq!(req.path(), "/test");
assert_eq!(req.payload_mut().readall().unwrap().as_ref(), b"body"); assert_eq!(req.payload_mut().readall().unwrap().as_ref(), b"body");
} }
Ok(_) | Err(_) => panic!("Error during parsing http request"), Ok(_) | Err(_) => unreachable!("Error during parsing http request"),
} }
} }
@ -1072,7 +1072,7 @@ mod tests {
assert_eq!(req.path(), "/test"); assert_eq!(req.path(), "/test");
assert_eq!(req.payload_mut().readall().unwrap().as_ref(), b"body"); assert_eq!(req.payload_mut().readall().unwrap().as_ref(), b"body");
} }
Ok(_) | Err(_) => panic!("Error during parsing http request"), Ok(_) | Err(_) => unreachable!("Error during parsing http request"),
} }
} }
@ -1093,7 +1093,7 @@ mod tests {
assert_eq!(*req.method(), Method::GET); assert_eq!(*req.method(), Method::GET);
assert_eq!(req.path(), "/test"); assert_eq!(req.path(), "/test");
} }
Ok(_) | Err(_) => panic!("Error during parsing http request"), Ok(_) | Err(_) => unreachable!("Error during parsing http request"),
} }
} }
@ -1121,7 +1121,7 @@ mod tests {
assert_eq!(req.path(), "/test"); assert_eq!(req.path(), "/test");
assert_eq!(req.headers().get("test").unwrap().as_bytes(), b"value"); assert_eq!(req.headers().get("test").unwrap().as_bytes(), b"value");
} }
Ok(_) | Err(_) => panic!("Error during parsing http request"), Ok(_) | Err(_) => unreachable!("Error during parsing http request"),
} }
} }
@ -1143,7 +1143,7 @@ mod tests {
assert_eq!(val[0], "c1=cookie1"); assert_eq!(val[0], "c1=cookie1");
assert_eq!(val[1], "c2=cookie2"); assert_eq!(val[1], "c2=cookie2");
} }
Ok(_) | Err(_) => panic!("Error during parsing http request"), Ok(_) | Err(_) => unreachable!("Error during parsing http request"),
} }
} }
@ -1256,7 +1256,7 @@ mod tests {
if let Ok(val) = req.chunked() { if let Ok(val) = req.chunked() {
assert!(val); assert!(val);
} else { } else {
panic!("Error"); unreachable!("Error");
} }
// type in chunked // type in chunked
@ -1268,7 +1268,7 @@ mod tests {
if let Ok(val) = req.chunked() { if let Ok(val) = req.chunked() {
assert!(!val); assert!(!val);
} else { } else {
panic!("Error"); unreachable!("Error");
} }
} }
@ -1501,7 +1501,7 @@ mod tests {
let mut reader = Reader::new(); let mut reader = Reader::new();
match reader.parse(&mut buf) { match reader.parse(&mut buf) {
Ok(res) => (), Ok(res) => (),
Err(err) => panic!("{:?}", err), Err(err) => unreachable!("{:?}", err),
} }
}*/ }*/
} }

View File

@ -364,7 +364,7 @@ mod tests {
fn extract(frm: Poll<Option<Frame>, ProtocolError>) -> Frame { fn extract(frm: Poll<Option<Frame>, ProtocolError>) -> Frame {
match frm { match frm {
Ok(Async::Ready(Some(frame))) => frame, Ok(Async::Ready(Some(frame))) => frame,
_ => panic!("error"), _ => unreachable!("error"),
} }
} }
@ -468,7 +468,7 @@ mod tests {
if let Err(ProtocolError::Overflow) = Frame::parse(&mut buf, false, 0) { if let Err(ProtocolError::Overflow) = Frame::parse(&mut buf, false, 0) {
} else { } else {
panic!("error"); unreachable!("error");
} }
} }

View File

@ -210,7 +210,7 @@ mod test {
($from:expr => $opcode:pat) => { ($from:expr => $opcode:pat) => {
match OpCode::from($from) { match OpCode::from($from) {
e @ $opcode => (), e @ $opcode => (),
e => panic!("{:?}", e) e => unreachable!("{:?}", e)
} }
} }
} }
@ -220,7 +220,7 @@ mod test {
let res: u8 = $from.into(); let res: u8 = $from.into();
match res { match res {
e @ $opcode => (), e @ $opcode => (),
e => panic!("{:?}", e) e => unreachable!("{:?}", e)
} }
} }
} }