Skip to content

Commit

Permalink
Auto merge of #14242 - eth3lbert:snapbox-messages, r=epage
Browse files Browse the repository at this point in the history
test: migrate messages to snapbox

### What does this PR try to resolve?

Part of #14039.

Migrate following to snapbox:

- `tests/testsuite/messages.rs`
  • Loading branch information
bors committed Jul 26, 2024
2 parents 9a0c8b3 + f9026f1 commit b9e432a
Showing 1 changed file with 35 additions and 18 deletions.
53 changes: 35 additions & 18 deletions tests/testsuite/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
//!
//! Tests for message caching can be found in `cache_messages`.
#![allow(deprecated)]

use cargo_test_support::compare::assert_e2e;
use cargo_test_support::prelude::*;
use cargo_test_support::{process, project, Project};
use cargo_util::ProcessError;
Expand Down Expand Up @@ -48,6 +47,14 @@ pub fn raw_rustc_output(project: &Project, path: &str, extra: &[&str]) -> String
result
}

fn redact_rustc_message(msg: &str) -> impl IntoData {
use snapbox::filter::{Filter, FilterPaths};
let assert = assert_e2e();
let redactions = assert.redactions();
let msg = redactions.redact(msg);
FilterPaths.filter(msg.into())
}

#[cargo_test]
fn deduplicate_messages_basic() {
let p = project()
Expand All @@ -63,19 +70,24 @@ fn deduplicate_messages_basic() {
let rustc_message = raw_rustc_output(&p, "src/lib.rs", &[]);
let expected_output = format!(
"{}\
warning: `foo` (lib) generated 1 warning[..]
warning: `foo` (lib test) generated 1 warning (1 duplicate)
[FINISHED] [..]
[EXECUTABLE] unittests src/lib.rs (target/debug/deps/foo-[..][EXE])
[WARNING] `foo` (lib) generated 1 warning[..]
[WARNING] `foo` (lib test) generated 1 warning (1 duplicate)
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[EXECUTABLE] unittests src/lib.rs (target/debug/deps/foo-[HASH][EXE])
",
rustc_message
);
p.cargo("test --no-run -j1")
.with_stderr(&format!("[COMPILING] foo [..]\n{}", expected_output))
.with_stderr_data(redact_rustc_message(&format!(
"\
[COMPILING] foo v0.0.1 ([ROOT]/foo)
{}",
expected_output
)))
.run();
// Run again, to check for caching behavior.
p.cargo("test --no-run -j1")
.with_stderr(expected_output)
.with_stderr_data(redact_rustc_message(&expected_output))
.run();
}

Expand Down Expand Up @@ -106,20 +118,25 @@ fn deduplicate_messages_mismatched_warnings() {
let expected_output = format!(
"\
{}\
warning: `foo` (lib) generated 1 warning[..]
[WARNING] `foo` (lib) generated 1 warning[..]
{}\
warning: `foo` (lib test) generated 2 warnings (1 duplicate)
[FINISHED] [..]
[EXECUTABLE] unittests src/lib.rs (target/debug/deps/foo-[..][EXE])
[WARNING] `foo` (lib test) generated 2 warnings (1 duplicate)
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[EXECUTABLE] unittests src/lib.rs (target/debug/deps/foo-[HASH][EXE])
",
lib_output, lib_test_output
);
p.cargo("test --no-run -j1")
.with_stderr(&format!("[COMPILING] foo v0.0.1 [..]\n{}", expected_output))
.with_stderr_data(redact_rustc_message(&format!(
"\
[COMPILING] foo v0.0.1 ([ROOT]/foo)
{}",
expected_output
)))
.run();
// Run again, to check for caching behavior.
p.cargo("test --no-run -j1")
.with_stderr(expected_output)
.with_stderr_data(redact_rustc_message(&expected_output))
.run();
}

Expand All @@ -136,12 +153,12 @@ fn deduplicate_errors() {
let rustc_message = raw_rustc_output(&p, "src/lib.rs", &[]);
p.cargo("test -j1")
.with_status(101)
.with_stderr(&format!(
.with_stderr_data(redact_rustc_message(&format!(
"\
[COMPILING] foo v0.0.1 [..]
{}error: could not compile `foo` (lib) due to 1 previous error
[COMPILING] foo v0.0.1 ([ROOT]/foo)
{}[ERROR] could not compile `foo` (lib) due to 1 previous error
",
rustc_message
))
)))
.run();
}

0 comments on commit b9e432a

Please sign in to comment.