Skip to content

Commit 02f10bf

Browse files
committed
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%
1 parent b4f670d commit 02f10bf

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
@@ -157,3 +157,10 @@ fn test_unsuccessful_downcast() {
157157
drop(err);
158158
assert!(dropped.all());
159159
}
160+
161+
#[test]
162+
fn test_root_cause() {
163+
let (err, _) = make_chain();
164+
165+
assert_eq!(err.root_cause().to_string(), "no such file or directory");
166+
}

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 = AsRef::<dyn StdError>::as_ref(&error);
91+
assert_eq!("oh no!", ref_dyn.to_string());
92+
let ref_dyn_send_sync = AsRef::<dyn StdError + Send + Sync>::as_ref(&error);
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)