Skip to content

Commit

Permalink
Increase error test coverage.
Browse files Browse the repository at this point in the history
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%
  • Loading branch information
BramBonne committed Jun 22, 2021
1 parent b4f670d commit 02f10bf
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/test_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
20 changes: 20 additions & 0 deletions tests/test_convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<dyn StdError>::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::<dyn StdError + Send>::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::<dyn StdError + Send + Sync>::from(error);
Expand Down
9 changes: 9 additions & 0 deletions tests/test_downcast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<dyn StdError>::as_ref(&error);
assert_eq!("oh no!", ref_dyn.to_string());
let ref_dyn_send_sync = AsRef::<dyn StdError + Send + Sync>::as_ref(&error);
assert_eq!("oh no!", ref_dyn_send_sync.to_string());
}

#[test]
fn test_large_alignment() {
#[repr(align(64))]
Expand Down

0 comments on commit 02f10bf

Please sign in to comment.