Skip to content

Commit

Permalink
Merge pull request 159 from BramBonne/error-coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jul 3, 2021
2 parents 6632b23 + 02f10bf commit e9e706c
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 @@ -162,3 +162,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: &dyn StdError = error.as_ref();
assert_eq!("oh no!", ref_dyn.to_string());
let ref_dyn_send_sync: &(dyn StdError + Send + Sync) = error.as_ref();
assert_eq!("oh no!", ref_dyn_send_sync.to_string());
}

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

0 comments on commit e9e706c

Please sign in to comment.