Skip to content

Commit

Permalink
Auto merge of #3524 - sdroege:test-build-doc-test-check-status, r=ale…
Browse files Browse the repository at this point in the history
…xcrichton

Check the exit code of all processes started in the build/test tests

By not checking the exit codes, a failure in the build::crate_env_vars()
test was ignored.

As suggested by @alexcrichton in #3515 (comment)
  • Loading branch information
bors committed Jan 10, 2017
2 parents 7060ca1 + 446486b commit 6dd4ff0
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 48 deletions.
65 changes: 35 additions & 30 deletions tests/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ fn cargo_compile_simple() {
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]));

assert_that(p.cargo_process("build"), execs());
assert_that(p.cargo_process("build"), execs().with_status(0));
assert_that(&p.bin("foo"), existing_file());

assert_that(process(&p.bin("foo")),
execs().with_stdout("i am foo\n"));
execs().with_status(0).with_stdout("i am foo\n"));
}

#[test]
Expand Down Expand Up @@ -308,7 +308,7 @@ fn cargo_compile_with_warnings_in_the_root_package() {
.file("src/foo.rs", "fn main() {} fn dead() {}");

assert_that(p.cargo_process("build"),
execs().with_stderr_contains("\
execs().with_status(0).with_stderr_contains("\
[..]function is never used: `dead`[..]
"));
}
Expand Down Expand Up @@ -354,15 +354,15 @@ fn cargo_compile_with_warnings_in_a_dep_package() {
"#);

assert_that(p.cargo_process("build"),
execs().with_stderr_contains("\
execs().with_status(0).with_stderr_contains("\
[..]function is never used: `dead`[..]
"));

assert_that(&p.bin("foo"), existing_file());

assert_that(
process(&p.bin("foo")),
execs().with_stdout("test passed\n"));
execs().with_status(0).with_stdout("test passed\n"));
}

#[test]
Expand Down Expand Up @@ -423,7 +423,7 @@ fn cargo_compile_with_nested_deps_inferred() {

assert_that(
process(&p.bin("foo")),
execs().with_stdout("test passed\n"));
execs().with_status(0).with_stdout("test passed\n"));
}

#[test]
Expand Down Expand Up @@ -484,7 +484,7 @@ fn cargo_compile_with_nested_deps_correct_bin() {

assert_that(
process(&p.bin("foo")),
execs().with_stdout("test passed\n"));
execs().with_status(0).with_stdout("test passed\n"));
}

#[test]
Expand Down Expand Up @@ -554,7 +554,7 @@ fn cargo_compile_with_nested_deps_shorthand() {

assert_that(
process(&p.bin("foo")),
execs().with_stdout("test passed\n"));
execs().with_status(0).with_stdout("test passed\n"));
}

#[test]
Expand Down Expand Up @@ -623,7 +623,7 @@ fn cargo_compile_with_nested_deps_longhand() {
assert_that(&p.bin("libbaz.rlib"), is_not(existing_file()));

assert_that(process(&p.bin("foo")),
execs().with_stdout("test passed\n"));
execs().with_status(0).with_stdout("test passed\n"));
}

// Check that Cargo gives a sensible error if a dependency can't be found
Expand Down Expand Up @@ -878,6 +878,8 @@ fn crate_env_vars() {
assert_eq!("foo", PKG_NAME);
assert_eq!("http://example.com", HOMEPAGE);
assert_eq!("This is foo", DESCRIPTION);
let s = format!("{}.{}.{}-{}", VERSION_MAJOR,
VERSION_MINOR, VERSION_PATCH, VERSION_PRE);
assert_eq!(s, VERSION);
}
"#)
Expand All @@ -897,8 +899,8 @@ fn crate_env_vars() {

println!("bin");
assert_that(process(&p.bin("foo")),
execs().with_stdout(&format!("0-5-1 @ alpha.1 in {}\n",
p.root().display())));
execs().with_status(0).with_stdout(&format!("0-5-1 @ alpha.1 in {}\n",
p.root().display())));

println!("test");
assert_that(p.cargo("test").arg("-v"),
Expand Down Expand Up @@ -937,7 +939,7 @@ fn crate_authors_env_vars() {

println!("bin");
assert_that(process(&p.bin("foo")),
execs().with_stdout("[email protected]:[email protected]"));
execs().with_status(0).with_stdout("[email protected]:[email protected]"));

println!("test");
assert_that(p.cargo("test").arg("-v"),
Expand Down Expand Up @@ -1090,11 +1092,11 @@ fn ignore_broken_symlinks() {
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
.symlink("Notafile", "bar");

assert_that(p.cargo_process("build"), execs());
assert_that(p.cargo_process("build"), execs().with_status(0));
assert_that(&p.bin("foo"), existing_file());

assert_that(process(&p.bin("foo")),
execs().with_stdout("i am foo\n"));
execs().with_status(0).with_stdout("i am foo\n"));
}

#[test]
Expand Down Expand Up @@ -1302,9 +1304,9 @@ fn explicit_examples() {

assert_that(p.cargo_process("test").arg("-v"), execs().with_status(0));
assert_that(process(&p.bin("examples/hello")),
execs().with_stdout("Hello, World!\n"));
execs().with_status(0).with_stdout("Hello, World!\n"));
assert_that(process(&p.bin("examples/goodbye")),
execs().with_stdout("Goodbye, World!\n"));
execs().with_status(0).with_stdout("Goodbye, World!\n"));
}

#[test]
Expand Down Expand Up @@ -1336,9 +1338,9 @@ fn implicit_examples() {

assert_that(p.cargo_process("test"), execs().with_status(0));
assert_that(process(&p.bin("examples/hello")),
execs().with_stdout("Hello, World!\n"));
execs().with_status(0).with_stdout("Hello, World!\n"));
assert_that(process(&p.bin("examples/goodbye")),
execs().with_stdout("Goodbye, World!\n"));
execs().with_status(0).with_stdout("Goodbye, World!\n"));
}

#[test]
Expand All @@ -1357,7 +1359,7 @@ fn standard_build_no_ndebug() {

assert_that(p.cargo_process("build"), execs().with_status(0));
assert_that(process(&p.bin("foo")),
execs().with_stdout("slow\n"));
execs().with_status(0).with_stdout("slow\n"));
}

#[test]
Expand All @@ -1377,7 +1379,7 @@ fn release_build_ndebug() {
assert_that(p.cargo_process("build").arg("--release"),
execs().with_status(0));
assert_that(process(&p.release_bin("foo")),
execs().with_stdout("fast\n"));
execs().with_status(0).with_stdout("fast\n"));
}

#[test]
Expand Down Expand Up @@ -1855,7 +1857,7 @@ fn cargo_platform_specific_dependency_wrong_platform() {

assert_that(&p.bin("foo"), existing_file());
assert_that(process(&p.bin("foo")),
execs());
execs().with_status(0));

let loc = p.root().join("Cargo.lock");
let mut lockfile = String::new();
Expand Down Expand Up @@ -2249,23 +2251,23 @@ fn build_multiple_packages() {

assert_that(p.cargo_process("build").arg("-p").arg("d1").arg("-p").arg("d2")
.arg("-p").arg("foo"),
execs());
execs().with_status(0));

assert_that(&p.bin("foo"), existing_file());
assert_that(process(&p.bin("foo")),
execs().with_stdout("i am foo\n"));
execs().with_status(0).with_stdout("i am foo\n"));

let d1_path = &p.build_dir().join("debug")
.join(format!("d1{}", env::consts::EXE_SUFFIX));
let d2_path = &p.build_dir().join("debug")
.join(format!("d2{}", env::consts::EXE_SUFFIX));

assert_that(d1_path, existing_file());
assert_that(process(d1_path), execs().with_stdout("d1"));
assert_that(process(d1_path), execs().with_status(0).with_stdout("d1"));

assert_that(d2_path, existing_file());
assert_that(process(d2_path),
execs().with_stdout("d2"));
execs().with_status(0).with_stdout("d2"));
}

#[test]
Expand Down Expand Up @@ -2395,7 +2397,7 @@ fn compiler_json_error_format() {

assert_that(p.cargo_process("build").arg("-v")
.arg("--message-format").arg("json"),
execs().with_json(r#"
execs().with_status(0).with_json(r#"
{
"reason":"compiler-message",
"package_id":"bar 0.5.0 ([..])",
Expand Down Expand Up @@ -2481,7 +2483,7 @@ fn message_format_json_forward_stderr() {

assert_that(p.cargo_process("rustc").arg("--bin").arg("foo")
.arg("--message-format").arg("JSON").arg("--").arg("-Zno-trans"),
execs()
execs().with_status(0)
.with_stderr_contains("[WARNING] the option `Z` is unstable [..]")
.with_json(r#"
{
Expand Down Expand Up @@ -2584,7 +2586,8 @@ fn build_all_workspace() {

assert_that(p.cargo_process("build")
.arg("--all"),
execs().with_stderr("[..] Compiling bar v0.1.0 ([..])\n\
execs().with_status(0)
.with_stderr("[..] Compiling bar v0.1.0 ([..])\n\
[..] Compiling foo v0.1.0 ([..])\n\
[..] Finished debug [unoptimized + debuginfo] target(s) in [..]\n"));
}
Expand Down Expand Up @@ -2617,7 +2620,8 @@ fn build_all_virtual_manifest() {
// The order in which foo and bar are built is not guaranteed
assert_that(p.cargo_process("build")
.arg("--all"),
execs().with_stderr_contains("[..] Compiling bar v0.1.0 ([..])")
execs().with_status(0)
.with_stderr_contains("[..] Compiling bar v0.1.0 ([..])")
.with_stderr_contains("[..] Compiling foo v0.1.0 ([..])")
.with_stderr("[..] Compiling [..] v0.1.0 ([..])\n\
[..] Compiling [..] v0.1.0 ([..])\n\
Expand Down Expand Up @@ -2648,7 +2652,8 @@ fn build_all_member_dependency_same_name() {

assert_that(p.cargo_process("build")
.arg("--all"),
execs().with_stderr("[..] Updating registry `[..]`\n\
execs().with_status(0)
.with_stderr("[..] Updating registry `[..]`\n\
[..] Downloading a v0.1.0 ([..])\n\
[..] Compiling a v0.1.0\n\
[..] Compiling a v0.1.0 ([..])\n\
Expand Down
36 changes: 18 additions & 18 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ fn cargo_test_simple() {
assert_eq!(hello(), "hello")
}"#);

assert_that(p.cargo_process("build"), execs());
assert_that(p.cargo_process("build"), execs().with_status(0));
assert_that(&p.bin("foo"), existing_file());

assert_that(process(&p.bin("foo")),
execs().with_stdout("hello\n"));
execs().with_status(0).with_stdout("hello\n"));

assert_that(p.cargo("test"),
execs().with_stderr(format!("\
execs().with_status(0).with_stderr(format!("\
[COMPILING] foo v0.5.0 ({})
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
[RUNNING] target[/]debug[/]deps[/]foo-[..][EXE]", p.url()))
Expand Down Expand Up @@ -85,7 +85,7 @@ fn cargo_test_release() {
.file("bar/src/lib.rs", "pub fn bar() {}");

assert_that(p.cargo_process("test").arg("-v").arg("--release"),
execs().with_stderr(format!("\
execs().with_status(0).with_stderr(format!("\
[COMPILING] bar v0.0.1 ({dir}/bar)
[RUNNING] [..] -C opt-level=3 [..]
[COMPILING] foo v0.1.0 ({dir})
Expand Down Expand Up @@ -127,7 +127,7 @@ fn cargo_test_verbose() {
"#);

assert_that(p.cargo_process("test").arg("-v").arg("hello"),
execs().with_stderr(format!("\
execs().with_status(0).with_stderr(format!("\
[COMPILING] foo v0.5.0 ({url})
[RUNNING] `rustc [..] src[/]foo.rs [..]`
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
Expand Down Expand Up @@ -189,11 +189,11 @@ fn cargo_test_failing_test() {
assert_eq!(hello(), "nope")
}"#);

assert_that(p.cargo_process("build"), execs());
assert_that(p.cargo_process("build"), execs().with_status(0));
assert_that(&p.bin("foo"), existing_file());

assert_that(process(&p.bin("foo")),
execs().with_stdout("hello\n"));
execs().with_status(0).with_stdout("hello\n"));

assert_that(p.cargo("test"),
execs().with_stderr(format!("\
Expand Down Expand Up @@ -256,7 +256,7 @@ fn test_with_lib_dep() {
");

assert_that(p.cargo_process("test"),
execs().with_stderr(format!("\
execs().with_status(0).with_stderr(format!("\
[COMPILING] foo v0.0.1 ({})
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
[RUNNING] target[/]debug[/]deps[/]baz-[..][EXE]
Expand Down Expand Up @@ -372,7 +372,7 @@ fn external_test_explicit() {
"#);

assert_that(p.cargo_process("test"),
execs().with_stderr(format!("\
execs().with_status(0).with_stderr(format!("\
[COMPILING] foo v0.0.1 ({})
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
[RUNNING] target[/]debug[/]deps[/]foo-[..][EXE]
Expand Down Expand Up @@ -421,7 +421,7 @@ fn external_test_implicit() {
"#);

assert_that(p.cargo_process("test"),
execs().with_stderr(format!("\
execs().with_status(0).with_stderr(format!("\
[COMPILING] foo v0.0.1 ({})
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
[RUNNING] target[/]debug[/]deps[/]external-[..][EXE]
Expand Down Expand Up @@ -565,7 +565,7 @@ fn lib_bin_same_name() {
");

assert_that(p.cargo_process("test"),
execs().with_stderr(format!("\
execs().with_status(0).with_stderr(format!("\
[COMPILING] foo v0.0.1 ({})
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
[RUNNING] target[/]debug[/]deps[/]foo-[..][EXE]
Expand Down Expand Up @@ -1744,7 +1744,7 @@ fn filter_no_doc_tests() {
.file("tests/foo.rs", "");

assert_that(p.cargo_process("test").arg("--test=foo"),
execs().with_stderr("\
execs().with_status(0).with_stderr("\
[COMPILING] foo v0.0.1 ([..])
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
[RUNNING] target[/]debug[/]deps[/]foo[..][EXE]")
Expand Down Expand Up @@ -1778,7 +1778,7 @@ fn dylib_doctest() {
"#);

assert_that(p.cargo_process("test"),
execs().with_stderr("\
execs().with_status(0).with_stderr("\
[COMPILING] foo v0.0.1 ([..])
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
[DOCTEST] foo")
Expand Down Expand Up @@ -1814,7 +1814,7 @@ fn dylib_doctest2() {
"#);

assert_that(p.cargo_process("test"),
execs().with_stdout(""));
execs().with_status(0).with_stdout(""));
}

#[test]
Expand Down Expand Up @@ -1847,7 +1847,7 @@ fn cyclic_dev_dep_doc_test() {
extern crate foo;
"#);
assert_that(p.cargo_process("test"),
execs().with_stderr("\
execs().with_status(0).with_stderr("\
[COMPILING] foo v0.0.1 ([..])
[COMPILING] bar v0.0.1 ([..])
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
Expand Down Expand Up @@ -2430,7 +2430,7 @@ fn test_all_workspace() {

assert_that(p.cargo_process("test")
.arg("--all"),
execs().with_stdout_contains("\
execs().with_status(0).with_stdout_contains("\
running 1 test
test foo_test ... ok
Expand Down Expand Up @@ -2475,7 +2475,7 @@ fn test_all_virtual_manifest() {

assert_that(p.cargo_process("test")
.arg("--all"),
execs().with_stdout_contains("\
execs().with_status(0).with_stdout_contains("\
running 1 test
test b ... ok
Expand Down Expand Up @@ -2516,7 +2516,7 @@ fn test_all_member_dependency_same_name() {

assert_that(p.cargo_process("test")
.arg("--all"),
execs().with_stdout_contains("\
execs().with_status(0).with_stdout_contains("\
running 1 test
test a ... ok
Expand Down

0 comments on commit 6dd4ff0

Please sign in to comment.