Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: migrate messages to snapbox #14242

Merged
merged 1 commit into from
Jul 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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())
}
epage marked this conversation as resolved.
Show resolved Hide resolved

#[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();
}