Skip to content

Commit e9e706c

Browse files
committed
Merge pull request 159 from BramBonne/error-coverage
2 parents 6632b23 + 02f10bf commit e9e706c

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

tests/test_context.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,10 @@ fn test_unsuccessful_downcast() {
162162
drop(err);
163163
assert!(dropped.all());
164164
}
165+
166+
#[test]
167+
fn test_root_cause() {
168+
let (err, _) = make_chain();
169+
170+
assert_eq!(err.root_cause().to_string(), "no such file or directory");
171+
}

tests/test_convert.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,26 @@ use std::error::Error as StdError;
88

99
#[test]
1010
fn test_convert() {
11+
let has_dropped = Flag::new();
12+
let error = Error::new(DetectDrop::new(&has_dropped));
13+
let box_dyn = Box::<dyn StdError>::from(error);
14+
assert_eq!("oh no!", box_dyn.to_string());
15+
drop(box_dyn);
16+
assert!(has_dropped.get());
17+
}
18+
19+
#[test]
20+
fn test_convert_send() {
21+
let has_dropped = Flag::new();
22+
let error = Error::new(DetectDrop::new(&has_dropped));
23+
let box_dyn = Box::<dyn StdError + Send>::from(error);
24+
assert_eq!("oh no!", box_dyn.to_string());
25+
drop(box_dyn);
26+
assert!(has_dropped.get());
27+
}
28+
29+
#[test]
30+
fn test_convert_send_sync() {
1131
let has_dropped = Flag::new();
1232
let error = Error::new(DetectDrop::new(&has_dropped));
1333
let box_dyn = Box::<dyn StdError + Send + Sync>::from(error);

tests/test_downcast.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,15 @@ fn test_drop() {
8484
assert!(has_dropped.get());
8585
}
8686

87+
#[test]
88+
fn test_as_ref() {
89+
let error = bail_error().unwrap_err();
90+
let ref_dyn: &dyn StdError = error.as_ref();
91+
assert_eq!("oh no!", ref_dyn.to_string());
92+
let ref_dyn_send_sync: &(dyn StdError + Send + Sync) = error.as_ref();
93+
assert_eq!("oh no!", ref_dyn_send_sync.to_string());
94+
}
95+
8796
#[test]
8897
fn test_large_alignment() {
8998
#[repr(align(64))]

0 commit comments

Comments
 (0)