mirror of
https://github.com/rust-lang/cargo
synced 2024-09-13 21:11:44 +00:00
test: Add 'missing field' test
This commit is contained in:
parent
84dc5dc11a
commit
48742e009c
|
@ -1863,3 +1863,34 @@ fn trim_paths_parsing() {
|
|||
let trim_paths: TomlTrimPaths = gctx.get("profile.dev.trim-paths").unwrap();
|
||||
assert_eq!(trim_paths, expected, "failed to parse {val}");
|
||||
}
|
||||
|
||||
#[cargo_test]
|
||||
fn missing_fields() {
|
||||
#[derive(Deserialize, Default, Debug)]
|
||||
struct Foo {
|
||||
bar: Bar,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Default, Debug)]
|
||||
struct Bar {
|
||||
bax: bool,
|
||||
baz: bool,
|
||||
}
|
||||
|
||||
let gctx = GlobalContextBuilder::new()
|
||||
.env("CARGO_FOO_BAR_BAZ", "true")
|
||||
.build();
|
||||
assert_error(gctx.get::<Foo>("foo").unwrap_err(), "missing field `bax`");
|
||||
let gctx: GlobalContext = GlobalContextBuilder::new()
|
||||
.env("CARGO_FOO_BAR_BAZ", "true")
|
||||
.env("CARGO_FOO_BAR_BAX", "true")
|
||||
.build();
|
||||
let foo = gctx.get::<Foo>("foo").unwrap();
|
||||
assert_eq!(foo.bar.bax, true);
|
||||
assert_eq!(foo.bar.baz, true);
|
||||
|
||||
let gctx: GlobalContext = GlobalContextBuilder::new()
|
||||
.config_arg("foo.bar.baz=true")
|
||||
.build();
|
||||
assert_error(gctx.get::<Foo>("foo").unwrap_err(), "missing field `bax`");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue