From f5ddbc0533546b593dc04bc4b85de4158d1fea06 Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Mon, 13 Feb 2023 09:30:00 -0700 Subject: [PATCH] refactor: change unwrap()s to expects() and deny in clippy Signed-off-by: Stephen Waits --- src/height_vector.rs | 5 +++-- src/lib.rs | 1 + src/network_coordinate.rs | 14 +++++++++----- src/vector.rs | 5 ++++- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/height_vector.rs b/src/height_vector.rs index 3a05e4c..d4ece38 100644 --- a/src/height_vector.rs +++ b/src/height_vector.rs @@ -368,14 +368,15 @@ mod tests { fn test_serde() { // start with JSON, deserialize it let s = "{\"position\":[1.0,2.0,3.0],\"height\":4.0}"; - let a: HeightVector<3> = serde_json::from_str(s).unwrap(); + let a: HeightVector<3> = + serde_json::from_str(s).expect("deserialization failed during test"); // make sure it's the right length and works like we expect a normal NC assert_approx_eq!(a.len(), 7.741_657, 0.001); // serialize it into a new JSON string and make sure it matches the original let t = serde_json::to_string(&a); - assert_eq!(t.as_ref().unwrap(), s); + assert_eq!(t.as_ref().expect("serialization failed during test"), s); } #[test] diff --git a/src/lib.rs b/src/lib.rs index 14e1c9f..fe2f3f7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -102,6 +102,7 @@ #![deny(clippy::cargo)] #![deny(clippy::pedantic)] #![deny(clippy::nursery)] +#![deny(clippy::unwrap_used)] #![allow(clippy::type_repetition_in_bounds)] #![allow(clippy::module_name_repetitions)] diff --git a/src/network_coordinate.rs b/src/network_coordinate.rs index a3363c5..241d9ec 100644 --- a/src/network_coordinate.rs +++ b/src/network_coordinate.rs @@ -360,7 +360,8 @@ mod tests { fn test_serde() { // start with JSON, deserialize it let s = "{\"position\":[1.5,0.5,2.0],\"height\":0.1,\"error\":1.0}"; - let a: NetworkCoordinate<3> = serde_json::from_str(s).unwrap(); + let a: NetworkCoordinate<3> = + serde_json::from_str(s).expect("deserialization failed during test"); // make sure it's the right length and works like we expect a normal NC assert_approx_eq!(a.heightvec.len(), 2.649_509, 0.001); @@ -369,16 +370,18 @@ mod tests { // serialize it into a new JSON string and make sure it matches the original let t = serde_json::to_string(&a); - assert_eq!(t.as_ref().unwrap(), s); + assert_eq!(t.as_ref().expect("serialization failed during test"), s); } #[test] fn test_estimated_rtt() { // start with JSON, deserialize it let s = "{\"position\":[1.5,0.5,2.0],\"height\":25.0,\"error\":1.0}"; - let a: NetworkCoordinate<3> = serde_json::from_str(s).unwrap(); + let a: NetworkCoordinate<3> = + serde_json::from_str(s).expect("deserialization failed during test"); let s = "{\"position\":[-1.5,-0.5,-2.0],\"height\":50.0,\"error\":1.0}"; - let b: NetworkCoordinate<3> = serde_json::from_str(s).unwrap(); + let b: NetworkCoordinate<3> = + serde_json::from_str(s).expect("deserialization failed during test"); let estimate = a.estimated_rtt(&b); assert_approx_eq!(estimate.as_secs_f32(), 0.080_099); @@ -387,7 +390,8 @@ mod tests { #[test] fn test_error_getter() { let s = "{\"position\":[1.5,0.5,2.0],\"height\":25.0,\"error\":1.0}"; - let a: NetworkCoordinate<3> = serde_json::from_str(s).unwrap(); + let a: NetworkCoordinate<3> = + serde_json::from_str(s).expect("deserialization failed during test"); assert_approx_eq!(a.error(), 1.0); } } diff --git a/src/vector.rs b/src/vector.rs index b022165..be9b9a6 100644 --- a/src/vector.rs +++ b/src/vector.rs @@ -285,7 +285,10 @@ mod tests { fn test_serde() { let a = Vector::::from([1.0, 2.0, 3.0]); let s = serde_json::to_string(&a); - assert_eq!(s.as_ref().unwrap(), "{\"position\":[1.0,2.0,3.0]}"); + assert_eq!( + s.as_ref().expect("serialization failed in test"), + "{\"position\":[1.0,2.0,3.0]}" + ); assert!(s.is_ok()); } }