@@ -5948,3 +5948,122 @@ fn primary_package_env_var() {
59485948
59495949 foo. cargo ( "test" ) . run ( ) ;
59505950}
5951+
5952+ #[ cargo_test]
5953+ fn check_cfg_features ( ) {
5954+ if !is_nightly ( ) {
5955+ // --check-cfg is a nightly only rustc command line
5956+ return ;
5957+ }
5958+
5959+ let p = project ( )
5960+ . file (
5961+ "Cargo.toml" ,
5962+ r#"
5963+ [project]
5964+ name = "foo"
5965+ version = "0.1.0"
5966+
5967+ [features]
5968+ f_a = []
5969+ f_b = []
5970+ "# ,
5971+ )
5972+ . file ( "src/main.rs" , "fn main() {}" )
5973+ . build ( ) ;
5974+
5975+ p. cargo ( "build -v -Z check-cfg-features" )
5976+ . masquerade_as_nightly_cargo ( )
5977+ . with_stderr (
5978+ "\
5979+ [COMPILING] foo v0.1.0 [..]
5980+ [RUNNING] `rustc [..] --check-cfg 'values(feature, \" f_a\" , \" f_b\" )' [..]
5981+ [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
5982+ " ,
5983+ )
5984+ . run ( ) ;
5985+ }
5986+
5987+ #[ cargo_test]
5988+ fn check_cfg_features_with_deps ( ) {
5989+ if !is_nightly ( ) {
5990+ // --check-cfg is a nightly only rustc command line
5991+ return ;
5992+ }
5993+
5994+ let p = project ( )
5995+ . file (
5996+ "Cargo.toml" ,
5997+ r#"
5998+ [project]
5999+ name = "foo"
6000+ version = "0.1.0"
6001+
6002+ [dependencies]
6003+ bar = { path = "bar/" }
6004+
6005+ [features]
6006+ f_a = []
6007+ f_b = []
6008+ "# ,
6009+ )
6010+ . file ( "src/main.rs" , "fn main() {}" )
6011+ . file ( "bar/Cargo.toml" , & basic_manifest ( "bar" , "0.1.0" ) )
6012+ . file ( "bar/src/lib.rs" , "#[allow(dead_code)] fn bar() {}" )
6013+ . build ( ) ;
6014+
6015+ p. cargo ( "build -v -Z check-cfg-features" )
6016+ . masquerade_as_nightly_cargo ( )
6017+ . with_stderr (
6018+ "\
6019+ [COMPILING] bar v0.1.0 [..]
6020+ [RUNNING] `rustc [..] --check-cfg 'values(feature)' [..]
6021+ [COMPILING] foo v0.1.0 [..]
6022+ [RUNNING] `rustc --crate-name foo [..] --check-cfg 'values(feature, \" f_a\" , \" f_b\" )' [..]
6023+ [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
6024+ " ,
6025+ )
6026+ . run ( ) ;
6027+ }
6028+ #[ cargo_test]
6029+ fn check_cfg_features_with_opt_deps ( ) {
6030+ if !is_nightly ( ) {
6031+ // --check-cfg is a nightly only rustc command line
6032+ return ;
6033+ }
6034+
6035+ let p = project ( )
6036+ . file (
6037+ "Cargo.toml" ,
6038+ r#"
6039+ [project]
6040+ name = "foo"
6041+ version = "0.1.0"
6042+
6043+ [dependencies]
6044+ bar = { path = "bar/", optional = true }
6045+
6046+ [features]
6047+ default = ["bar"]
6048+ f_a = []
6049+ f_b = []
6050+ "# ,
6051+ )
6052+ . file ( "src/main.rs" , "fn main() {}" )
6053+ . file ( "bar/Cargo.toml" , & basic_manifest ( "bar" , "0.1.0" ) )
6054+ . file ( "bar/src/lib.rs" , "#[allow(dead_code)] fn bar() {}" )
6055+ . build ( ) ;
6056+
6057+ p. cargo ( "build -v -Z check-cfg-features" )
6058+ . masquerade_as_nightly_cargo ( )
6059+ . with_stderr (
6060+ "\
6061+ [COMPILING] bar v0.1.0 [..]
6062+ [RUNNING] `rustc [..] --check-cfg 'values(feature)' [..]
6063+ [COMPILING] foo v0.1.0 [..]
6064+ [RUNNING] `rustc --crate-name foo [..] --check-cfg 'values(feature, \" bar\" , \" default\" , \" f_a\" , \" f_b\" )' [..]
6065+ [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
6066+ " ,
6067+ )
6068+ . run ( ) ;
6069+ }
0 commit comments