test: be consistent on error message styles

This commit is contained in:
Weihang Lo 2020-10-10 06:58:06 +08:00
parent 4a61d8a412
commit 5e3dc46753
No known key found for this signature in database
GPG Key ID: D7DBF189825E82E7
5 changed files with 16 additions and 17 deletions

View File

@ -1347,7 +1347,7 @@ fn traverse_and_share(
/// Build `glob::Pattern` with informative context. /// Build `glob::Pattern` with informative context.
fn build_glob(pat: &str) -> CargoResult<glob::Pattern> { fn build_glob(pat: &str) -> CargoResult<glob::Pattern> {
glob::Pattern::new(pat).with_context(|| format!("Cannot build glob pattern from `{}`", pat)) glob::Pattern::new(pat).with_context(|| format!("cannot build glob pattern from `{}`", pat))
} }
/// Emits "package not found" error. /// Emits "package not found" error.
@ -1361,11 +1361,10 @@ fn emit_package_not_found(
) -> CargoResult<()> { ) -> CargoResult<()> {
if !opt_names.is_empty() { if !opt_names.is_empty() {
anyhow::bail!( anyhow::bail!(
"{}package(s) {} not found in workspace `{}`", "{}package(s) `{}` not found in workspace `{}`",
if opt_out { "excluded " } else { "" }, if opt_out { "excluded " } else { "" },
opt_names opt_names
.iter() .into_iter()
.map(|x| x.as_ref())
.collect::<Vec<_>>() .collect::<Vec<_>>()
.join(", "), .join(", "),
ws.root().display(), ws.root().display(),
@ -1390,7 +1389,7 @@ fn emit_pattern_not_found(
.collect::<Vec<_>>(); .collect::<Vec<_>>();
if !not_matched.is_empty() { if !not_matched.is_empty() {
anyhow::bail!( anyhow::bail!(
"{}package pattern(s) {} not found in workspace `{}`", "{}package pattern(s) `{}` not found in workspace `{}`",
if opt_out { "excluded " } else { "" }, if opt_out { "excluded " } else { "" },
not_matched.join(", "), not_matched.join(", "),
ws.root().display(), ws.root().display(),

View File

@ -3519,7 +3519,7 @@ fn build_all_exclude_not_found() {
.with_stderr_contains("[COMPILING] bar v0.1.0 [..]") .with_stderr_contains("[COMPILING] bar v0.1.0 [..]")
.with_stderr( .with_stderr(
"\ "\
[WARNING] excluded package(s) baz not found in workspace [..] [WARNING] excluded package(s) `baz` not found in workspace [..]
[COMPILING] [..] v0.1.0 ([..]) [COMPILING] [..] v0.1.0 ([..])
[COMPILING] [..] v0.1.0 ([..]) [COMPILING] [..] v0.1.0 ([..])
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
@ -3586,7 +3586,7 @@ fn build_all_exclude_glob_not_found() {
.with_stderr_does_not_contain("[COMPILING] baz v0.1.0 [..]") .with_stderr_does_not_contain("[COMPILING] baz v0.1.0 [..]")
.with_stderr( .with_stderr(
"\ "\
[WARNING] excluded package pattern(s) *z not found in workspace [..] [WARNING] excluded package pattern(s) `*z` not found in workspace [..]
[COMPILING] [..] v0.1.0 ([..]) [COMPILING] [..] v0.1.0 ([..])
[COMPILING] [..] v0.1.0 ([..]) [COMPILING] [..] v0.1.0 ([..])
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
@ -3601,7 +3601,7 @@ fn build_all_exclude_broken_glob() {
p.cargo("build --workspace --exclude '[*z'") p.cargo("build --workspace --exclude '[*z'")
.with_status(101) .with_status(101)
.with_stderr_contains("[ERROR] Cannot build glob pattern from `[*z`") .with_stderr_contains("[ERROR] cannot build glob pattern from `[*z`")
.run(); .run();
} }
@ -3778,7 +3778,7 @@ fn build_virtual_manifest_glob_not_found() {
p.cargo("build -p bar -p '*z'") p.cargo("build -p bar -p '*z'")
.with_stderr( .with_stderr(
"\ "\
[WARNING] package pattern(s) *z not found in workspace [..] [WARNING] package pattern(s) `*z` not found in workspace [..]
[COMPILING] bar v0.1.0 ([..]) [COMPILING] bar v0.1.0 ([..])
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
", ",
@ -3802,7 +3802,7 @@ fn build_virtual_manifest_broken_glob() {
p.cargo("build -p '[*z'") p.cargo("build -p '[*z'")
.with_status(101) .with_status(101)
.with_stderr_contains("[ERROR] Cannot build glob pattern from `[*z`") .with_stderr_contains("[ERROR] cannot build glob pattern from `[*z`")
.run(); .run();
} }

View File

@ -551,7 +551,7 @@ fn exclude_warns_on_non_existing_package() {
.with_stdout("") .with_stdout("")
.with_stderr( .with_stderr(
"\ "\
[WARNING] excluded package(s) bar not found in workspace `[CWD]` [WARNING] excluded package(s) `bar` not found in workspace `[CWD]`
[CHECKING] foo v0.0.1 ([CWD]) [CHECKING] foo v0.0.1 ([CWD])
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
", ",

View File

@ -996,7 +996,7 @@ fn run_multiple_packages() {
.arg("-p") .arg("-p")
.arg("d3") .arg("d3")
.with_status(101) .with_status(101)
.with_stderr_contains("[ERROR] package(s) d3 not found in workspace [..]") .with_stderr_contains("[ERROR] package(s) `d3` not found in workspace [..]")
.run(); .run();
cargo() cargo()

View File

@ -2853,7 +2853,7 @@ fn test_all_exclude_not_found() {
.build(); .build();
p.cargo("test --workspace --exclude baz") p.cargo("test --workspace --exclude baz")
.with_stderr_contains("[WARNING] excluded package(s) baz not found in workspace [..]") .with_stderr_contains("[WARNING] excluded package(s) `baz` not found in workspace [..]")
.with_stdout_contains( .with_stdout_contains(
"running 1 test "running 1 test
test bar ... ok", test bar ... ok",
@ -2911,7 +2911,7 @@ fn test_all_exclude_glob_not_found() {
p.cargo("test --workspace --exclude '*z'") p.cargo("test --workspace --exclude '*z'")
.with_stderr_contains( .with_stderr_contains(
"[WARNING] excluded package pattern(s) *z not found in workspace [..]", "[WARNING] excluded package pattern(s) `*z` not found in workspace [..]",
) )
.with_stdout_contains( .with_stdout_contains(
"running 1 test "running 1 test
@ -2926,7 +2926,7 @@ fn test_all_exclude_broken_glob() {
p.cargo("test --workspace --exclude '[*z'") p.cargo("test --workspace --exclude '[*z'")
.with_status(101) .with_status(101)
.with_stderr_contains("[ERROR] Cannot build glob pattern from `[*z`") .with_stderr_contains("[ERROR] cannot build glob pattern from `[*z`")
.run(); .run();
} }
@ -3033,7 +3033,7 @@ fn test_virtual_manifest_glob_not_found() {
.build(); .build();
p.cargo("test -p bar -p '*z'") p.cargo("test -p bar -p '*z'")
.with_stderr_contains("[WARNING] package pattern(s) *z not found in workspace [..]") .with_stderr_contains("[WARNING] package pattern(s) `*z` not found in workspace [..]")
.with_stdout_contains("running 1 test\ntest bar ... ok") .with_stdout_contains("running 1 test\ntest bar ... ok")
.with_stdout_does_not_contain("running 1 test\ntest baz ... ok") .with_stdout_does_not_contain("running 1 test\ntest baz ... ok")
.run(); .run();
@ -3055,7 +3055,7 @@ fn test_virtual_manifest_broken_glob() {
p.cargo("test -p '[*z'") p.cargo("test -p '[*z'")
.with_status(101) .with_status(101)
.with_stderr_contains("[ERROR] Cannot build glob pattern from `[*z`") .with_stderr_contains("[ERROR] cannot build glob pattern from `[*z`")
.run(); .run();
} }