Skip to content

Commit

Permalink
Auto merge of #2795 - alexcrichton:test-and-harness, r=brson
Browse files Browse the repository at this point in the history
Fix `harness = false` on `[lib]` sections

Now that this is fixed upstream, we can actually add a test for this!

Closes #2305
  • Loading branch information
bors authored Jun 21, 2016
2 parents 4ba8264 + c88c7af commit 80f2775
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/cargo/ops/cargo_rustc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() &&
Expand Down Expand Up @@ -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()) {
Expand Down
32 changes: 32 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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] `[..]`
"));
}

0 comments on commit 80f2775

Please sign in to comment.