Skip to content

Commit

Permalink
test: add test to show the error is without path info
Browse files Browse the repository at this point in the history
  • Loading branch information
allevo committed Jan 9, 2025
1 parent a3ff970 commit e9475fe
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/testsuite/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,39 @@ fn test_error_root_not_table() {
},
}
}

#[test]
#[cfg(feature = "json5")]
fn test_json_error_with_path() {
#[derive(Debug, Deserialize)]
struct InnerSettings {
#[allow(dead_code)]
value: u32,
#[allow(dead_code)]
value2: u32,
}

#[derive(Debug, Deserialize)]
struct Settings {
#[allow(dead_code)]
inner: InnerSettings,
}

let c = Config::builder()
.add_source(File::from_str(
r#"
{
"inner": { "value": 42 }
}
"#,
FileFormat::Json,
))
.build()
.unwrap();

let without_path = c.clone().try_deserialize::<Settings>();
assert_data_eq!(
without_path.unwrap_err().to_string(),
str!["missing field `value2`"]
);
}

0 comments on commit e9475fe

Please sign in to comment.