Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make cargo check also check unit tests #4039

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix behaviour to not check unit tests by default (with no arguments)
  • Loading branch information
tbourvon committed May 16, 2017
commit 36cd8224d7a85aedb078f9bc8663ae74354544dc
4 changes: 2 additions & 2 deletions src/cargo/ops/cargo_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ fn generate_targets<'a>(pkg: &'a Package,
let test = if release {&profiles.bench} else {&profiles.test};

let is_check_test = match *filter {
CompileFilter::Everything { .. } => true,
CompileFilter::Everything { .. } => false,
CompileFilter::Only { tests, .. } => match tests {
FilterRule::All => true,
FilterRule::Just(_) => false,
Expand Down Expand Up @@ -587,7 +587,7 @@ fn generate_targets<'a>(pkg: &'a Package,
CompileFilter::Only { lib, bins, examples, tests, benches } => {
let mut targets = Vec::new();

if lib {
if lib || is_check_test {
if let Some(t) = pkg.targets().iter().find(|t| t.is_lib()) {
targets.push(BuildProposal {
target: t,
Expand Down
13 changes: 7 additions & 6 deletions tests/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ fn check_unit_test_implicit() {
"#);

assert_that(foo.cargo_process("check"),
execs().with_status(101));
execs().with_status(0));
}

#[test]
Expand All @@ -444,12 +444,12 @@ fn check_unit_test_explicit() {
}
"#);

assert_that(foo.cargo_process("check").arg("--lib").arg("--tests"),
assert_that(foo.cargo_process("check").arg("--tests"),
execs().with_status(101));
}

#[test]
fn check_no_unit_test() {
fn check_unit_test_specific() {
let foo = project("foo")
.file("Cargo.toml", r#"
[package]
Expand All @@ -469,8 +469,9 @@ fn check_no_unit_test() {
test_fn(1);
}
}
"#);
"#)
.file("tests/a.rs", "");

assert_that(foo.cargo_process("check").arg("--lib"),
assert_that(foo.cargo_process("check").arg("--test").arg("a"),
execs().with_status(0));
}
}