From bbc42e7845d73362ce94662882e8c20289337612 Mon Sep 17 00:00:00 2001 From: Xavier L'Heureux Date: Sat, 14 Sep 2019 11:29:44 -0400 Subject: Where relevant, replace equality checks in assert! with assert_eq! `assert_eq!` gives more debug info when the test fails by default than `assert!`. This should help make debugging easier. --- src/sys/socket/mod.rs | 4 ++-- src/sys/socket/sockopt.rs | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'src/sys/socket') diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs index beaa69ad..ca4505fa 100644 --- a/src/sys/socket/mod.rs +++ b/src/sys/socket/mod.rs @@ -1245,12 +1245,12 @@ pub unsafe fn sockaddr_storage_to_addr( match c_int::from(addr.ss_family) { libc::AF_INET => { - assert!(len as usize == mem::size_of::()); + assert_eq!(len as usize, mem::size_of::()); let ret = *(addr as *const _ as *const sockaddr_in); Ok(SockAddr::Inet(InetAddr::V4(ret))) } libc::AF_INET6 => { - assert!(len as usize == mem::size_of::()); + assert_eq!(len as usize, mem::size_of::()); Ok(SockAddr::Inet(InetAddr::V6(*(addr as *const _ as *const sockaddr_in6)))) } libc::AF_UNIX => { diff --git a/src/sys/socket/sockopt.rs b/src/sys/socket/sockopt.rs index 1271f645..691f66dd 100644 --- a/src/sys/socket/sockopt.rs +++ b/src/sys/socket/sockopt.rs @@ -411,7 +411,7 @@ unsafe impl Get for GetStruct { } unsafe fn unwrap(self) -> T { - assert!(self.len as usize == mem::size_of::(), "invalid getsockopt implementation"); + assert_eq!(self.len as usize, mem::size_of::(), "invalid getsockopt implementation"); self.val } } @@ -458,7 +458,7 @@ unsafe impl Get for GetBool { } unsafe fn unwrap(self) -> bool { - assert!(self.len as usize == mem::size_of::(), "invalid getsockopt implementation"); + assert_eq!(self.len as usize, mem::size_of::(), "invalid getsockopt implementation"); self.val != 0 } } @@ -505,7 +505,7 @@ unsafe impl Get for GetU8 { } unsafe fn unwrap(self) -> u8 { - assert!(self.len as usize == mem::size_of::(), "invalid getsockopt implementation"); + assert_eq!(self.len as usize, mem::size_of::(), "invalid getsockopt implementation"); self.val as u8 } } @@ -552,7 +552,7 @@ unsafe impl Get for GetUsize { } unsafe fn unwrap(self) -> usize { - assert!(self.len as usize == mem::size_of::(), "invalid getsockopt implementation"); + assert_eq!(self.len as usize, mem::size_of::(), "invalid getsockopt implementation"); self.val as usize } } @@ -644,7 +644,7 @@ mod test { let (a, b) = socketpair(AddressFamily::Unix, SockType::Stream, None, SockFlag::empty()).unwrap(); let a_type = getsockopt(a, super::SockType).unwrap(); - assert!(a_type == SockType::Stream); + assert_eq!(a_type, SockType::Stream); close(a).unwrap(); close(b).unwrap(); } @@ -656,7 +656,7 @@ mod test { let s = socket(AddressFamily::Inet, SockType::Datagram, SockFlag::empty(), None).unwrap(); let s_type = getsockopt(s, super::SockType).unwrap(); - assert!(s_type == SockType::Datagram); + assert_eq!(s_type, SockType::Datagram); close(s).unwrap(); } -- cgit v1.2.3