Skip to content

Commit f58d107

Browse files
committed
testsuite: Require failing commands to check output.
1 parent fef7802 commit f58d107

File tree

14 files changed

+211
-36
lines changed

14 files changed

+211
-36
lines changed

tests/testsuite/alt_registry.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ fn cannot_publish_to_crates_io_with_registry_dependency() {
310310
.arg(registry::registry().to_string())
311311
.masquerade_as_nightly_cargo()
312312
.with_status(101)
313+
.with_stderr_contains("[ERROR] crates cannot be published to crates.io[..]")
313314
.run();
314315
}
315316

tests/testsuite/build.rs

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -542,15 +542,19 @@ fn cargo_compile_with_invalid_code_in_deps() {
542542
.build();
543543
let _bar = project()
544544
.at("bar")
545-
.file("Cargo.toml", &basic_bin_manifest("bar"))
545+
.file("Cargo.toml", &basic_manifest("bar", "0.1.0"))
546546
.file("src/lib.rs", "invalid rust code!")
547547
.build();
548548
let _baz = project()
549549
.at("baz")
550-
.file("Cargo.toml", &basic_bin_manifest("baz"))
550+
.file("Cargo.toml", &basic_manifest("baz", "0.1.0"))
551551
.file("src/lib.rs", "invalid rust code!")
552552
.build();
553-
p.cargo("build").with_status(101).run();
553+
p.cargo("build")
554+
.with_status(101)
555+
.with_stderr_contains("[..]invalid rust code[..]")
556+
.with_stderr_contains("[ERROR] Could not compile [..]")
557+
.run();
554558
}
555559

556560
#[test]
@@ -1266,7 +1270,10 @@ fn compile_offline_while_transitive_dep_not_cached() {
12661270
.build();
12671271

12681272
// simulate download bar, but fail to download baz
1269-
p.cargo("build").with_status(101).run();
1273+
p.cargo("build")
1274+
.with_status(101)
1275+
.with_stderr_contains("[..]failed to verify the checksum of `baz[..]")
1276+
.run();
12701277

12711278
drop(File::create(baz_path).ok().unwrap().write_all(&content));
12721279

@@ -2169,7 +2176,10 @@ fn deletion_causes_failure() {
21692176

21702177
p.cargo("build").run();
21712178
p.change_file("Cargo.toml", &basic_manifest("foo", "0.0.1"));
2172-
p.cargo("build").with_status(101).run();
2179+
p.cargo("build")
2180+
.with_status(101)
2181+
.with_stderr_contains("[..]can't find crate for `bar`")
2182+
.run();
21732183
}
21742184

21752185
#[test]
@@ -2541,11 +2551,14 @@ fn bad_platform_specific_dependency() {
25412551
.file("bar/Cargo.toml", &basic_manifest("bar", "0.5.0"))
25422552
.file(
25432553
"bar/src/lib.rs",
2544-
r#"extern crate baz; pub fn gimme() -> String { format!("") }"#,
2554+
r#"pub fn gimme() -> String { format!("") }"#,
25452555
)
25462556
.build();
25472557

2548-
p.cargo("build").with_status(101).run();
2558+
p.cargo("build")
2559+
.with_status(101)
2560+
.with_stderr_contains("[..]can't find crate for `bar`")
2561+
.run();
25492562
}
25502563

25512564
#[test]
@@ -2858,7 +2871,17 @@ fn dashes_in_crate_name_bad() {
28582871
.file("src/main.rs", "extern crate foo_bar; fn main() {}")
28592872
.build();
28602873

2861-
p.cargo("build -v").with_status(101).run();
2874+
p.cargo("build -v")
2875+
.with_status(101)
2876+
.with_stderr(
2877+
"\
2878+
[ERROR] failed to parse manifest at `[..]/foo/Cargo.toml`
2879+
2880+
Caused by:
2881+
library target names cannot contain hyphens: foo-bar
2882+
",
2883+
)
2884+
.run();
28622885
}
28632886

28642887
#[test]
@@ -4513,7 +4536,17 @@ fn avoid_dev_deps() {
45134536
.file("src/main.rs", "fn main() {}")
45144537
.build();
45154538

4516-
p.cargo("build").with_status(101).run();
4539+
p.cargo("build")
4540+
.with_status(101)
4541+
.with_stderr(
4542+
"\
4543+
[UPDATING] [..]
4544+
[ERROR] no matching package named `baz` found
4545+
location searched: registry `https://github.com/rust-lang/crates.io-index`
4546+
required by package `bar v0.1.0 ([..]/foo)`
4547+
",
4548+
)
4549+
.run();
45174550
p.cargo("build -Zavoid-dev-deps")
45184551
.masquerade_as_nightly_cargo()
45194552
.run();

tests/testsuite/check.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ fn check_fail() {
6161
.file("src/lib.rs", "pub fn baz() {}")
6262
.build();
6363

64-
foo.cargo("check").with_status(101).run();
64+
foo.cargo("check")
65+
.with_status(101)
66+
.with_stderr_contains("[..]this function takes 0 parameters but 1 parameter was supplied")
67+
.run();
6568
}
6669

6770
#[test]
@@ -363,6 +366,9 @@ fn rustc_check_err() {
363366

364367
foo.cargo("rustc --profile check -- --emit=metadata")
365368
.with_status(101)
369+
.with_stderr_contains("[CHECKING] bar [..]")
370+
.with_stderr_contains("[CHECKING] foo [..]")
371+
.with_stderr_contains("[..]cannot find function `qux` in module `bar`")
366372
.run();
367373
}
368374

tests/testsuite/features.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,10 @@ fn dep_feature_in_cmd_line() {
11711171

11721172
// The foo project requires that feature "some-feat" in "bar" is enabled.
11731173
// Building without any features enabled should fail:
1174-
p.cargo("build").with_status(101).run();
1174+
p.cargo("build")
1175+
.with_status(101)
1176+
.with_stderr_contains("[..]unresolved import `bar::test`")
1177+
.run();
11751178

11761179
// We should be able to enable the feature "derived-feat", which enables "some-feat",
11771180
// on the command line. The feature is enabled, thus building should be successful:

tests/testsuite/fix.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ fn do_not_fix_broken_builds() {
2929
p.cargo("fix --allow-no-vcs")
3030
.env("__CARGO_FIX_YOLO", "1")
3131
.with_status(101)
32+
.with_stderr_contains("[ERROR] Could not compile `foo`.")
3233
.run();
3334
assert!(p.read_file("src/lib.rs").contains("let mut x = 3;"));
3435
}
@@ -1247,6 +1248,7 @@ fn fix_to_broken_code() {
12471248
.cwd(p.root().join("bar"))
12481249
.env("RUSTC", p.root().join("foo/target/debug/foo"))
12491250
.with_status(101)
1251+
.with_stderr_contains("[WARNING] failed to automatically apply fixes [..]")
12501252
.run();
12511253

12521254
assert_eq!(

tests/testsuite/freshness.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ fn modifying_and_moving() {
4040
.run();
4141

4242
fs::rename(&p.root().join("src/a.rs"), &p.root().join("src/b.rs")).unwrap();
43-
p.cargo("build").with_status(101).run();
43+
p.cargo("build")
44+
.with_status(101)
45+
.with_stderr_contains("[..]file not found[..]")
46+
.run();
4447
}
4548

4649
#[test]
@@ -513,7 +516,10 @@ fn rebuild_tests_if_lib_changes() {
513516
File::create(&p.root().join("src/lib.rs")).unwrap();
514517

515518
p.cargo("build -v").run();
516-
p.cargo("test -v").with_status(101).run();
519+
p.cargo("test -v")
520+
.with_status(101)
521+
.with_stderr_contains("[..]cannot find function `foo`[..]")
522+
.run();
517523
}
518524

519525
#[test]

tests/testsuite/install.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,10 @@ fn dev_dependencies_no_check() {
10141014
.file("src/main.rs", "fn main() {}")
10151015
.build();
10161016

1017-
p.cargo("build").with_status(101).run();
1017+
p.cargo("build")
1018+
.with_status(101)
1019+
.with_stderr_contains("[..] no matching package named `baz` found")
1020+
.run();
10181021
p.cargo("install").run();
10191022
}
10201023

tests/testsuite/path.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,10 @@ fn cargo_compile_with_root_dev_deps() {
138138
)
139139
.build();
140140

141-
p.cargo("build").with_status(101).run();
141+
p.cargo("build")
142+
.with_status(101)
143+
.with_stderr_contains("[..]can't find crate for `bar`")
144+
.run();
142145
}
143146

144147
#[test]

tests/testsuite/publish.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,10 @@ fn new_crate_rejected() {
597597
p.cargo("publish --index")
598598
.arg(publish::registry().to_string())
599599
.with_status(101)
600+
.with_stderr_contains(
601+
"[ERROR] 3 files in the working directory contain \
602+
changes that were not yet committed into git:",
603+
)
600604
.run();
601605
}
602606

tests/testsuite/rename_deps.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,10 @@ fn rename_affects_fingerprint() {
228228
"#,
229229
);
230230

231-
p.cargo("build -v").with_status(101).run();
231+
p.cargo("build -v")
232+
.with_status(101)
233+
.with_stderr_contains("[..]can't find crate for `foo`")
234+
.run();
232235
}
233236

234237
#[test]

0 commit comments

Comments
 (0)