Skip to content

Commit

Permalink
Introduce an error test case for deserialising a whole struct
Browse files Browse the repository at this point in the history
This tests, in particular, that the error messdage is as expected
including the right key and filename.

Signed-off-by: Ian Jackson <[email protected]>
  • Loading branch information
ijackson committed Oct 23, 2023
1 parent 1887369 commit fdfb4f8
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,28 @@ fn test_error_type() {
);
}

#[test]
fn test_error_deser_whole() {
#[derive(Deserialize, Debug)]
struct Place {
#[allow(dead_code)]
name: usize, // is actually s string
}

#[derive(Deserialize, Debug)]
struct Output {
#[allow(dead_code)]
place: Place,
}

let c = make();
let err = c.try_deserialize::<Output>().unwrap_err().to_string();
assert_eq!(
err,
"invalid type: string \"Torre di Pisa\", expected an integer for key `place.name` in tests/Settings.toml",
);
}

#[test]
fn test_error_type_detached() {
let c = make();
Expand Down

0 comments on commit fdfb4f8

Please sign in to comment.