Skip to content

Commit 3fa088d

Browse files
committed
test: migrate messages to snapbox
1 parent d01a41c commit 3fa088d

File tree

1 file changed

+35
-18
lines changed

1 file changed

+35
-18
lines changed

tests/testsuite/messages.rs

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
//!
33
//! Tests for message caching can be found in `cache_messages`.
44
5-
#![allow(deprecated)]
6-
5+
use cargo_test_support::compare::assert_e2e;
76
use cargo_test_support::prelude::*;
87
use cargo_test_support::{process, project, Project};
98
use cargo_util::ProcessError;
@@ -48,6 +47,14 @@ pub fn raw_rustc_output(project: &Project, path: &str, extra: &[&str]) -> String
4847
result
4948
}
5049

50+
fn redact_rustc_message(msg: &str) -> impl IntoData {
51+
use snapbox::filter::{Filter, FilterPaths};
52+
let assert = assert_e2e();
53+
let redactions = assert.redactions();
54+
let msg = redactions.redact(msg);
55+
FilterPaths.filter(msg.into())
56+
}
57+
5158
#[cargo_test]
5259
fn deduplicate_messages_basic() {
5360
let p = project()
@@ -63,19 +70,24 @@ fn deduplicate_messages_basic() {
6370
let rustc_message = raw_rustc_output(&p, "src/lib.rs", &[]);
6471
let expected_output = format!(
6572
"{}\
66-
warning: `foo` (lib) generated 1 warning[..]
67-
warning: `foo` (lib test) generated 1 warning (1 duplicate)
68-
[FINISHED] [..]
69-
[EXECUTABLE] unittests src/lib.rs (target/debug/deps/foo-[..][EXE])
73+
[WARNING] `foo` (lib) generated 1 warning[..]
74+
[WARNING] `foo` (lib test) generated 1 warning (1 duplicate)
75+
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
76+
[EXECUTABLE] unittests src/lib.rs (target/debug/deps/foo-[HASH][EXE])
7077
",
7178
rustc_message
7279
);
7380
p.cargo("test --no-run -j1")
74-
.with_stderr(&format!("[COMPILING] foo [..]\n{}", expected_output))
81+
.with_stderr_data(redact_rustc_message(&format!(
82+
"\
83+
[COMPILING] foo v0.0.1 ([ROOT]/foo)
84+
{}",
85+
expected_output
86+
)))
7587
.run();
7688
// Run again, to check for caching behavior.
7789
p.cargo("test --no-run -j1")
78-
.with_stderr(expected_output)
90+
.with_stderr_data(redact_rustc_message(&expected_output))
7991
.run();
8092
}
8193

@@ -106,20 +118,25 @@ fn deduplicate_messages_mismatched_warnings() {
106118
let expected_output = format!(
107119
"\
108120
{}\
109-
warning: `foo` (lib) generated 1 warning[..]
121+
[WARNING] `foo` (lib) generated 1 warning[..]
110122
{}\
111-
warning: `foo` (lib test) generated 2 warnings (1 duplicate)
112-
[FINISHED] [..]
113-
[EXECUTABLE] unittests src/lib.rs (target/debug/deps/foo-[..][EXE])
123+
[WARNING] `foo` (lib test) generated 2 warnings (1 duplicate)
124+
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
125+
[EXECUTABLE] unittests src/lib.rs (target/debug/deps/foo-[HASH][EXE])
114126
",
115127
lib_output, lib_test_output
116128
);
117129
p.cargo("test --no-run -j1")
118-
.with_stderr(&format!("[COMPILING] foo v0.0.1 [..]\n{}", expected_output))
130+
.with_stderr_data(redact_rustc_message(&format!(
131+
"\
132+
[COMPILING] foo v0.0.1 ([ROOT]/foo)
133+
{}",
134+
expected_output
135+
)))
119136
.run();
120137
// Run again, to check for caching behavior.
121138
p.cargo("test --no-run -j1")
122-
.with_stderr(expected_output)
139+
.with_stderr_data(redact_rustc_message(&expected_output))
123140
.run();
124141
}
125142

@@ -136,12 +153,12 @@ fn deduplicate_errors() {
136153
let rustc_message = raw_rustc_output(&p, "src/lib.rs", &[]);
137154
p.cargo("test -j1")
138155
.with_status(101)
139-
.with_stderr(&format!(
156+
.with_stderr_data(redact_rustc_message(&format!(
140157
"\
141-
[COMPILING] foo v0.0.1 [..]
142-
{}error: could not compile `foo` (lib) due to 1 previous error
158+
[COMPILING] foo v0.0.1 ([ROOT]/foo)
159+
{}[ERROR] could not compile `foo` (lib) due to 1 previous error
143160
",
144161
rustc_message
145-
))
162+
)))
146163
.run();
147164
}

0 commit comments

Comments
 (0)