diff --git a/src/cargo/ops/cargo_rustc/mod.rs b/src/cargo/ops/cargo_rustc/mod.rs index 6b07d8f413f..ab0b829626a 100644 --- a/src/cargo/ops/cargo_rustc/mod.rs +++ b/src/cargo/ops/cargo_rustc/mod.rs @@ -467,8 +467,10 @@ fn build_base_args(cx: &Context, cmd.arg("--crate-name").arg(&unit.target.crate_name()); - for crate_type in crate_types.iter() { - cmd.arg("--crate-type").arg(crate_type); + if !test { + for crate_type in crate_types.iter() { + cmd.arg("--crate-type").arg(crate_type); + } } let prefer_dynamic = (unit.target.for_host() && @@ -515,6 +517,8 @@ fn build_base_args(cx: &Context, if test && unit.target.harness() { cmd.arg("--test"); + } else if test { + cmd.arg("--cfg").arg("test"); } if let Some(features) = cx.resolve.features(unit.pkg.package_id()) { diff --git a/src/rustversion.txt b/src/rustversion.txt index 1557cfb2fe4..0594aef9b99 100644 --- a/src/rustversion.txt +++ b/src/rustversion.txt @@ -1 +1 @@ -2016-05-13 +2016-06-21 diff --git a/tests/registry.rs b/tests/registry.rs index 83ddb6b7427..7f600fb1786 100644 --- a/tests/registry.rs +++ b/tests/registry.rs @@ -1067,6 +1067,6 @@ fn upstream_warnings_on_extra_verbose() { assert_that(p.cargo("build").arg("-vv"), execs().with_status(0).with_stderr_contains("\ -[..] warning: function is never used[..] +[..]warning: function is never used[..] ")); } diff --git a/tests/rustc.rs b/tests/rustc.rs index e65d713d41f..7281bea66a4 100644 --- a/tests/rustc.rs +++ b/tests/rustc.rs @@ -209,7 +209,7 @@ fn build_with_args_to_one_of_multiple_tests() { [COMPILING] foo v0.0.1 ({url}) [RUNNING] `rustc src{sep}lib.rs --crate-name foo --crate-type lib -g \ --out-dir {dir}{sep}target{sep}debug [..]` -[RUNNING] `rustc tests{sep}bar.rs --crate-name bar --crate-type bin -g \ +[RUNNING] `rustc tests{sep}bar.rs --crate-name bar -g \ -C debug-assertions [..]--test[..]` ", sep = SEP, dir = p.root().display(), url = p.url()))); diff --git a/tests/test.rs b/tests/test.rs index 11a2cc54c9f..78b9a9e7125 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -2161,3 +2161,35 @@ fn test_panic_abort_with_dep() { assert_that(p.cargo_process("test").arg("-v"), execs().with_status(0)); } + +#[test] +fn cfg_test_even_with_no_harness() { + if !is_nightly() { + return + } + let p = project("foo") + .file("Cargo.toml", r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + + [lib] + harness = false + doctest = false + "#) + .file("src/lib.rs", r#" + #[cfg(test)] + fn main() { + println!("hello!"); + } + "#); + assert_that(p.cargo_process("test").arg("-v"), + execs().with_status(0) + .with_stdout("hello!\n") + .with_stderr("\ +[COMPILING] foo v0.0.1 ([..]) +[RUNNING] `rustc [..]` +[RUNNING] `[..]` +")); +}