Skip to content

Commit 48742e0

Browse files
committed
test: Add 'missing field' test
1 parent 84dc5dc commit 48742e0

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

tests/testsuite/config.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1863,3 +1863,34 @@ fn trim_paths_parsing() {
18631863
let trim_paths: TomlTrimPaths = gctx.get("profile.dev.trim-paths").unwrap();
18641864
assert_eq!(trim_paths, expected, "failed to parse {val}");
18651865
}
1866+
1867+
#[cargo_test]
1868+
fn missing_fields() {
1869+
#[derive(Deserialize, Default, Debug)]
1870+
struct Foo {
1871+
bar: Bar,
1872+
}
1873+
1874+
#[derive(Deserialize, Default, Debug)]
1875+
struct Bar {
1876+
bax: bool,
1877+
baz: bool,
1878+
}
1879+
1880+
let gctx = GlobalContextBuilder::new()
1881+
.env("CARGO_FOO_BAR_BAZ", "true")
1882+
.build();
1883+
assert_error(gctx.get::<Foo>("foo").unwrap_err(), "missing field `bax`");
1884+
let gctx: GlobalContext = GlobalContextBuilder::new()
1885+
.env("CARGO_FOO_BAR_BAZ", "true")
1886+
.env("CARGO_FOO_BAR_BAX", "true")
1887+
.build();
1888+
let foo = gctx.get::<Foo>("foo").unwrap();
1889+
assert_eq!(foo.bar.bax, true);
1890+
assert_eq!(foo.bar.baz, true);
1891+
1892+
let gctx: GlobalContext = GlobalContextBuilder::new()
1893+
.config_arg("foo.bar.baz=true")
1894+
.build();
1895+
assert_error(gctx.get::<Foo>("foo").unwrap_err(), "missing field `bax`");
1896+
}

0 commit comments

Comments
 (0)