File tree Expand file tree Collapse file tree 5 files changed +41
-5
lines changed Expand file tree Collapse file tree 5 files changed +41
-5
lines changed Original file line number Diff line number Diff line change @@ -467,8 +467,10 @@ fn build_base_args(cx: &Context,
467467
468468 cmd. arg ( "--crate-name" ) . arg ( & unit. target . crate_name ( ) ) ;
469469
470- for crate_type in crate_types. iter ( ) {
471- cmd. arg ( "--crate-type" ) . arg ( crate_type) ;
470+ if !test {
471+ for crate_type in crate_types. iter ( ) {
472+ cmd. arg ( "--crate-type" ) . arg ( crate_type) ;
473+ }
472474 }
473475
474476 let prefer_dynamic = ( unit. target . for_host ( ) &&
@@ -515,6 +517,8 @@ fn build_base_args(cx: &Context,
515517
516518 if test && unit. target . harness ( ) {
517519 cmd. arg ( "--test" ) ;
520+ } else if test {
521+ cmd. arg ( "--cfg" ) . arg ( "test" ) ;
518522 }
519523
520524 if let Some ( features) = cx. resolve . features ( unit. pkg . package_id ( ) ) {
Original file line number Diff line number Diff line change 1- 2016-05-13
1+ 2016-06-21
Original file line number Diff line number Diff line change @@ -1067,6 +1067,6 @@ fn upstream_warnings_on_extra_verbose() {
10671067
10681068 assert_that ( p. cargo ( "build" ) . arg ( "-vv" ) ,
10691069 execs ( ) . with_status ( 0 ) . with_stderr_contains ( "\
1070- [..] warning: function is never used[..]
1070+ [..]warning: function is never used[..]
10711071" ) ) ;
10721072}
Original file line number Diff line number Diff line change @@ -209,7 +209,7 @@ fn build_with_args_to_one_of_multiple_tests() {
209209 [COMPILING] foo v0.0.1 ({url})
210210[RUNNING] `rustc src{sep}lib.rs --crate-name foo --crate-type lib -g \
211211 --out-dir {dir}{sep}target{sep}debug [..]`
212- [RUNNING] `rustc tests{sep}bar.rs --crate-name bar --crate-type bin - g \
212+ [RUNNING] `rustc tests{sep}bar.rs --crate-name bar -g \
213213 -C debug-assertions [..]--test[..]`
214214" , sep = SEP ,
215215 dir = p. root( ) . display( ) , url = p. url( ) ) ) ) ;
Original file line number Diff line number Diff line change @@ -2161,3 +2161,35 @@ fn test_panic_abort_with_dep() {
21612161 assert_that ( p. cargo_process ( "test" ) . arg ( "-v" ) ,
21622162 execs ( ) . with_status ( 0 ) ) ;
21632163}
2164+
2165+ #[ test]
2166+ fn cfg_test_even_with_no_harness ( ) {
2167+ if !is_nightly ( ) {
2168+ return
2169+ }
2170+ let p = project ( "foo" )
2171+ . file ( "Cargo.toml" , r#"
2172+ [package]
2173+ name = "foo"
2174+ version = "0.0.1"
2175+ authors = []
2176+
2177+ [lib]
2178+ harness = false
2179+ doctest = false
2180+ "# )
2181+ . file ( "src/lib.rs" , r#"
2182+ #[cfg(test)]
2183+ fn main() {
2184+ println!("hello!");
2185+ }
2186+ "# ) ;
2187+ assert_that ( p. cargo_process ( "test" ) . arg ( "-v" ) ,
2188+ execs ( ) . with_status ( 0 )
2189+ . with_stdout ( "hello!\n " )
2190+ . with_stderr ( "\
2191+ [COMPILING] foo v0.0.1 ([..])
2192+ [RUNNING] `rustc [..]`
2193+ [RUNNING] `[..]`
2194+ " ) ) ;
2195+ }
You can’t perform that action at this time.
0 commit comments