From 02f10bfed3adb8a8ac0aa3ea21946717cbe18593 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bram=20Bonn=C3=A9?= Date: Tue, 22 Jun 2021 16:58:10 +0200 Subject: [PATCH] Increase error test coverage. error.rs coverage: Lines: 84.26% -> 91.88% Functions: 37.1% -> 39.07% Total coverage: Lines: 83.55% -> 87.5% Functions: 45.21% -> 46.42% --- tests/test_context.rs | 7 +++++++ tests/test_convert.rs | 20 ++++++++++++++++++++ tests/test_downcast.rs | 9 +++++++++ 3 files changed, 36 insertions(+) diff --git a/tests/test_context.rs b/tests/test_context.rs index 44c1c70..a9c06b0 100644 --- a/tests/test_context.rs +++ b/tests/test_context.rs @@ -157,3 +157,10 @@ fn test_unsuccessful_downcast() { drop(err); assert!(dropped.all()); } + +#[test] +fn test_root_cause() { + let (err, _) = make_chain(); + + assert_eq!(err.root_cause().to_string(), "no such file or directory"); +} diff --git a/tests/test_convert.rs b/tests/test_convert.rs index aff64e2..6da171d 100644 --- a/tests/test_convert.rs +++ b/tests/test_convert.rs @@ -8,6 +8,26 @@ use std::error::Error as StdError; #[test] fn test_convert() { + let has_dropped = Flag::new(); + let error = Error::new(DetectDrop::new(&has_dropped)); + let box_dyn = Box::::from(error); + assert_eq!("oh no!", box_dyn.to_string()); + drop(box_dyn); + assert!(has_dropped.get()); +} + +#[test] +fn test_convert_send() { + let has_dropped = Flag::new(); + let error = Error::new(DetectDrop::new(&has_dropped)); + let box_dyn = Box::::from(error); + assert_eq!("oh no!", box_dyn.to_string()); + drop(box_dyn); + assert!(has_dropped.get()); +} + +#[test] +fn test_convert_send_sync() { let has_dropped = Flag::new(); let error = Error::new(DetectDrop::new(&has_dropped)); let box_dyn = Box::::from(error); diff --git a/tests/test_downcast.rs b/tests/test_downcast.rs index 6b93710..ce3e742 100644 --- a/tests/test_downcast.rs +++ b/tests/test_downcast.rs @@ -84,6 +84,15 @@ fn test_drop() { assert!(has_dropped.get()); } +#[test] +fn test_as_ref() { + let error = bail_error().unwrap_err(); + let ref_dyn = AsRef::::as_ref(&error); + assert_eq!("oh no!", ref_dyn.to_string()); + let ref_dyn_send_sync = AsRef::::as_ref(&error); + assert_eq!("oh no!", ref_dyn_send_sync.to_string()); +} + #[test] fn test_large_alignment() { #[repr(align(64))]