Skip to content

Commit fdfb4f8

Browse files
committed
Introduce an error test case for deserialising a whole struct
This tests, in particular, that the error messdage is as expected including the right key and filename. Signed-off-by: Ian Jackson <[email protected]>
1 parent 1887369 commit fdfb4f8

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

tests/errors.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,28 @@ fn test_error_type() {
4444
);
4545
}
4646

47+
#[test]
48+
fn test_error_deser_whole() {
49+
#[derive(Deserialize, Debug)]
50+
struct Place {
51+
#[allow(dead_code)]
52+
name: usize, // is actually s string
53+
}
54+
55+
#[derive(Deserialize, Debug)]
56+
struct Output {
57+
#[allow(dead_code)]
58+
place: Place,
59+
}
60+
61+
let c = make();
62+
let err = c.try_deserialize::<Output>().unwrap_err().to_string();
63+
assert_eq!(
64+
err,
65+
"invalid type: string \"Torre di Pisa\", expected an integer for key `place.name` in tests/Settings.toml",
66+
);
67+
}
68+
4769
#[test]
4870
fn test_error_type_detached() {
4971
let c = make();

0 commit comments

Comments
 (0)