summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIan Jackson <ijackson@chiark.greenend.org.uk>2022-04-28 17:19:58 +0100
committerIan Jackson <ijackson@chiark.greenend.org.uk>2023-10-23 18:24:40 +0100
commitfdfb4f8e2cb812fa5aebaa498d750705732863cd (patch)
tree2266563a307f531c20bc9ae9ae5b79c24992cab8
parent18873691500efb1f04f97b48d1018a003b2e7f75 (diff)
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 <ijackson@chiark.greenend.org.uk>
-rw-r--r--tests/errors.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/errors.rs b/tests/errors.rs
index 54cb93a..1c3204c 100644
--- a/tests/errors.rs
+++ b/tests/errors.rs
@@ -45,6 +45,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();