File tree 1 file changed +31
-0
lines changed 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -1863,3 +1863,34 @@ fn trim_paths_parsing() {
1863
1863
let trim_paths: TomlTrimPaths = gctx. get ( "profile.dev.trim-paths" ) . unwrap ( ) ;
1864
1864
assert_eq ! ( trim_paths, expected, "failed to parse {val}" ) ;
1865
1865
}
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
+ }
You can’t perform that action at this time.
0 commit comments