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 + b74fd0a commit 50dad37
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 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
2 changes: 1 addition & 1 deletion src/rustversion.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2016-05-13
2016-06-21
2 changes: 1 addition & 1 deletion tests/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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[..]
"));
}
2 changes: 1 addition & 1 deletion tests/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())));
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 50dad37

Please sign in to comment.