Skip to content

Commit 6dd4ff0

Browse files
committed
Auto merge of #3524 - sdroege:test-build-doc-test-check-status, r=alexcrichton
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)
2 parents 7060ca1 + 446486b commit 6dd4ff0

File tree

2 files changed

+53
-48
lines changed

2 files changed

+53
-48
lines changed

tests/build.rs

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ fn cargo_compile_simple() {
2222
.file("Cargo.toml", &basic_bin_manifest("foo"))
2323
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]));
2424

25-
assert_that(p.cargo_process("build"), execs());
25+
assert_that(p.cargo_process("build"), execs().with_status(0));
2626
assert_that(&p.bin("foo"), existing_file());
2727

2828
assert_that(process(&p.bin("foo")),
29-
execs().with_stdout("i am foo\n"));
29+
execs().with_status(0).with_stdout("i am foo\n"));
3030
}
3131

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

310310
assert_that(p.cargo_process("build"),
311-
execs().with_stderr_contains("\
311+
execs().with_status(0).with_stderr_contains("\
312312
[..]function is never used: `dead`[..]
313313
"));
314314
}
@@ -354,15 +354,15 @@ fn cargo_compile_with_warnings_in_a_dep_package() {
354354
"#);
355355

356356
assert_that(p.cargo_process("build"),
357-
execs().with_stderr_contains("\
357+
execs().with_status(0).with_stderr_contains("\
358358
[..]function is never used: `dead`[..]
359359
"));
360360

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

363363
assert_that(
364364
process(&p.bin("foo")),
365-
execs().with_stdout("test passed\n"));
365+
execs().with_status(0).with_stdout("test passed\n"));
366366
}
367367

368368
#[test]
@@ -423,7 +423,7 @@ fn cargo_compile_with_nested_deps_inferred() {
423423

424424
assert_that(
425425
process(&p.bin("foo")),
426-
execs().with_stdout("test passed\n"));
426+
execs().with_status(0).with_stdout("test passed\n"));
427427
}
428428

429429
#[test]
@@ -484,7 +484,7 @@ fn cargo_compile_with_nested_deps_correct_bin() {
484484

485485
assert_that(
486486
process(&p.bin("foo")),
487-
execs().with_stdout("test passed\n"));
487+
execs().with_status(0).with_stdout("test passed\n"));
488488
}
489489

490490
#[test]
@@ -554,7 +554,7 @@ fn cargo_compile_with_nested_deps_shorthand() {
554554

555555
assert_that(
556556
process(&p.bin("foo")),
557-
execs().with_stdout("test passed\n"));
557+
execs().with_status(0).with_stdout("test passed\n"));
558558
}
559559

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

625625
assert_that(process(&p.bin("foo")),
626-
execs().with_stdout("test passed\n"));
626+
execs().with_status(0).with_stdout("test passed\n"));
627627
}
628628

629629
// Check that Cargo gives a sensible error if a dependency can't be found
@@ -878,6 +878,8 @@ fn crate_env_vars() {
878878
assert_eq!("foo", PKG_NAME);
879879
assert_eq!("http://example.com", HOMEPAGE);
880880
assert_eq!("This is foo", DESCRIPTION);
881+
let s = format!("{}.{}.{}-{}", VERSION_MAJOR,
882+
VERSION_MINOR, VERSION_PATCH, VERSION_PRE);
881883
assert_eq!(s, VERSION);
882884
}
883885
"#)
@@ -897,8 +899,8 @@ fn crate_env_vars() {
897899

898900
println!("bin");
899901
assert_that(process(&p.bin("foo")),
900-
execs().with_stdout(&format!("0-5-1 @ alpha.1 in {}\n",
901-
p.root().display())));
902+
execs().with_status(0).with_stdout(&format!("0-5-1 @ alpha.1 in {}\n",
903+
p.root().display())));
902904

903905
println!("test");
904906
assert_that(p.cargo("test").arg("-v"),
@@ -937,7 +939,7 @@ fn crate_authors_env_vars() {
937939

938940
println!("bin");
939941
assert_that(process(&p.bin("foo")),
940-
execs().with_stdout("[email protected]:[email protected]"));
942+
execs().with_status(0).with_stdout("[email protected]:[email protected]"));
941943

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

1093-
assert_that(p.cargo_process("build"), execs());
1095+
assert_that(p.cargo_process("build"), execs().with_status(0));
10941096
assert_that(&p.bin("foo"), existing_file());
10951097

10961098
assert_that(process(&p.bin("foo")),
1097-
execs().with_stdout("i am foo\n"));
1099+
execs().with_status(0).with_stdout("i am foo\n"));
10981100
}
10991101

11001102
#[test]
@@ -1302,9 +1304,9 @@ fn explicit_examples() {
13021304

13031305
assert_that(p.cargo_process("test").arg("-v"), execs().with_status(0));
13041306
assert_that(process(&p.bin("examples/hello")),
1305-
execs().with_stdout("Hello, World!\n"));
1307+
execs().with_status(0).with_stdout("Hello, World!\n"));
13061308
assert_that(process(&p.bin("examples/goodbye")),
1307-
execs().with_stdout("Goodbye, World!\n"));
1309+
execs().with_status(0).with_stdout("Goodbye, World!\n"));
13081310
}
13091311

13101312
#[test]
@@ -1336,9 +1338,9 @@ fn implicit_examples() {
13361338

13371339
assert_that(p.cargo_process("test"), execs().with_status(0));
13381340
assert_that(process(&p.bin("examples/hello")),
1339-
execs().with_stdout("Hello, World!\n"));
1341+
execs().with_status(0).with_stdout("Hello, World!\n"));
13401342
assert_that(process(&p.bin("examples/goodbye")),
1341-
execs().with_stdout("Goodbye, World!\n"));
1343+
execs().with_status(0).with_stdout("Goodbye, World!\n"));
13421344
}
13431345

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

13581360
assert_that(p.cargo_process("build"), execs().with_status(0));
13591361
assert_that(process(&p.bin("foo")),
1360-
execs().with_stdout("slow\n"));
1362+
execs().with_status(0).with_stdout("slow\n"));
13611363
}
13621364

13631365
#[test]
@@ -1377,7 +1379,7 @@ fn release_build_ndebug() {
13771379
assert_that(p.cargo_process("build").arg("--release"),
13781380
execs().with_status(0));
13791381
assert_that(process(&p.release_bin("foo")),
1380-
execs().with_stdout("fast\n"));
1382+
execs().with_status(0).with_stdout("fast\n"));
13811383
}
13821384

13831385
#[test]
@@ -1855,7 +1857,7 @@ fn cargo_platform_specific_dependency_wrong_platform() {
18551857

18561858
assert_that(&p.bin("foo"), existing_file());
18571859
assert_that(process(&p.bin("foo")),
1858-
execs());
1860+
execs().with_status(0));
18591861

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

22502252
assert_that(p.cargo_process("build").arg("-p").arg("d1").arg("-p").arg("d2")
22512253
.arg("-p").arg("foo"),
2252-
execs());
2254+
execs().with_status(0));
22532255

22542256
assert_that(&p.bin("foo"), existing_file());
22552257
assert_that(process(&p.bin("foo")),
2256-
execs().with_stdout("i am foo\n"));
2258+
execs().with_status(0).with_stdout("i am foo\n"));
22572259

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

22632265
assert_that(d1_path, existing_file());
2264-
assert_that(process(d1_path), execs().with_stdout("d1"));
2266+
assert_that(process(d1_path), execs().with_status(0).with_stdout("d1"));
22652267

22662268
assert_that(d2_path, existing_file());
22672269
assert_that(process(d2_path),
2268-
execs().with_stdout("d2"));
2270+
execs().with_status(0).with_stdout("d2"));
22692271
}
22702272

22712273
#[test]
@@ -2395,7 +2397,7 @@ fn compiler_json_error_format() {
23952397

23962398
assert_that(p.cargo_process("build").arg("-v")
23972399
.arg("--message-format").arg("json"),
2398-
execs().with_json(r#"
2400+
execs().with_status(0).with_json(r#"
23992401
{
24002402
"reason":"compiler-message",
24012403
"package_id":"bar 0.5.0 ([..])",
@@ -2481,7 +2483,7 @@ fn message_format_json_forward_stderr() {
24812483

24822484
assert_that(p.cargo_process("rustc").arg("--bin").arg("foo")
24832485
.arg("--message-format").arg("JSON").arg("--").arg("-Zno-trans"),
2484-
execs()
2486+
execs().with_status(0)
24852487
.with_stderr_contains("[WARNING] the option `Z` is unstable [..]")
24862488
.with_json(r#"
24872489
{
@@ -2584,7 +2586,8 @@ fn build_all_workspace() {
25842586

25852587
assert_that(p.cargo_process("build")
25862588
.arg("--all"),
2587-
execs().with_stderr("[..] Compiling bar v0.1.0 ([..])\n\
2589+
execs().with_status(0)
2590+
.with_stderr("[..] Compiling bar v0.1.0 ([..])\n\
25882591
[..] Compiling foo v0.1.0 ([..])\n\
25892592
[..] Finished debug [unoptimized + debuginfo] target(s) in [..]\n"));
25902593
}
@@ -2617,7 +2620,8 @@ fn build_all_virtual_manifest() {
26172620
// The order in which foo and bar are built is not guaranteed
26182621
assert_that(p.cargo_process("build")
26192622
.arg("--all"),
2620-
execs().with_stderr_contains("[..] Compiling bar v0.1.0 ([..])")
2623+
execs().with_status(0)
2624+
.with_stderr_contains("[..] Compiling bar v0.1.0 ([..])")
26212625
.with_stderr_contains("[..] Compiling foo v0.1.0 ([..])")
26222626
.with_stderr("[..] Compiling [..] v0.1.0 ([..])\n\
26232627
[..] Compiling [..] v0.1.0 ([..])\n\
@@ -2648,7 +2652,8 @@ fn build_all_member_dependency_same_name() {
26482652

26492653
assert_that(p.cargo_process("build")
26502654
.arg("--all"),
2651-
execs().with_stderr("[..] Updating registry `[..]`\n\
2655+
execs().with_status(0)
2656+
.with_stderr("[..] Updating registry `[..]`\n\
26522657
[..] Downloading a v0.1.0 ([..])\n\
26532658
[..] Compiling a v0.1.0\n\
26542659
[..] Compiling a v0.1.0 ([..])\n\

tests/test.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ fn cargo_test_simple() {
3131
assert_eq!(hello(), "hello")
3232
}"#);
3333

34-
assert_that(p.cargo_process("build"), execs());
34+
assert_that(p.cargo_process("build"), execs().with_status(0));
3535
assert_that(&p.bin("foo"), existing_file());
3636

3737
assert_that(process(&p.bin("foo")),
38-
execs().with_stdout("hello\n"));
38+
execs().with_status(0).with_stdout("hello\n"));
3939

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

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

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

192-
assert_that(p.cargo_process("build"), execs());
192+
assert_that(p.cargo_process("build"), execs().with_status(0));
193193
assert_that(&p.bin("foo"), existing_file());
194194

195195
assert_that(process(&p.bin("foo")),
196-
execs().with_stdout("hello\n"));
196+
execs().with_status(0).with_stdout("hello\n"));
197197

198198
assert_that(p.cargo("test"),
199199
execs().with_stderr(format!("\
@@ -256,7 +256,7 @@ fn test_with_lib_dep() {
256256
");
257257

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

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

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

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

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

17801780
assert_that(p.cargo_process("test"),
1781-
execs().with_stderr("\
1781+
execs().with_status(0).with_stderr("\
17821782
[COMPILING] foo v0.0.1 ([..])
17831783
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
17841784
[DOCTEST] foo")
@@ -1814,7 +1814,7 @@ fn dylib_doctest2() {
18141814
"#);
18151815

18161816
assert_that(p.cargo_process("test"),
1817-
execs().with_stdout(""));
1817+
execs().with_status(0).with_stdout(""));
18181818
}
18191819

18201820
#[test]
@@ -1847,7 +1847,7 @@ fn cyclic_dev_dep_doc_test() {
18471847
extern crate foo;
18481848
"#);
18491849
assert_that(p.cargo_process("test"),
1850-
execs().with_stderr("\
1850+
execs().with_status(0).with_stderr("\
18511851
[COMPILING] foo v0.0.1 ([..])
18521852
[COMPILING] bar v0.0.1 ([..])
18531853
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
@@ -2430,7 +2430,7 @@ fn test_all_workspace() {
24302430

24312431
assert_that(p.cargo_process("test")
24322432
.arg("--all"),
2433-
execs().with_stdout_contains("\
2433+
execs().with_status(0).with_stdout_contains("\
24342434
running 1 test
24352435
test foo_test ... ok
24362436
@@ -2475,7 +2475,7 @@ fn test_all_virtual_manifest() {
24752475

24762476
assert_that(p.cargo_process("test")
24772477
.arg("--all"),
2478-
execs().with_stdout_contains("\
2478+
execs().with_status(0).with_stdout_contains("\
24792479
running 1 test
24802480
test b ... ok
24812481
@@ -2516,7 +2516,7 @@ fn test_all_member_dependency_same_name() {
25162516

25172517
assert_that(p.cargo_process("test")
25182518
.arg("--all"),
2519-
execs().with_stdout_contains("\
2519+
execs().with_status(0).with_stdout_contains("\
25202520
running 1 test
25212521
test a ... ok
25222522

0 commit comments

Comments
 (0)