Skip to content

Commit e493b1a

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

File tree

1 file changed

+37
-18
lines changed

1 file changed

+37
-18
lines changed

tests/testsuite/messages.rs

Lines changed: 37 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,12 @@ pub fn raw_rustc_output(project: &Project, path: &str, extra: &[&str]) -> String
4847
result
4948
}
5049

50+
fn redact_rustc_message(msg: &str) -> String {
51+
let assert = assert_e2e().normalize_paths(true);
52+
let redactions = assert.redactions();
53+
redactions.redact(msg)
54+
}
55+
5156
#[cargo_test]
5257
fn deduplicate_messages_basic() {
5358
let p = project()
@@ -61,21 +66,27 @@ fn deduplicate_messages_basic() {
6166
)
6267
.build();
6368
let rustc_message = raw_rustc_output(&p, "src/lib.rs", &[]);
69+
let rustc_message = redact_rustc_message(&rustc_message);
6470
let expected_output = format!(
6571
"{}\
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])
72+
[WARNING] `foo` (lib) generated 1 warning[..]
73+
[WARNING] `foo` (lib test) generated 1 warning (1 duplicate)
74+
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
75+
[EXECUTABLE] unittests src/lib.rs (target/debug/deps/foo-[HASH][EXE])
7076
",
7177
rustc_message
7278
);
7379
p.cargo("test --no-run -j1")
74-
.with_stderr(&format!("[COMPILING] foo [..]\n{}", expected_output))
80+
.with_stderr_data(&format!(
81+
"\
82+
[COMPILING] foo v0.0.1 ([ROOT]/foo)
83+
{}",
84+
expected_output
85+
))
7586
.run();
7687
// Run again, to check for caching behavior.
7788
p.cargo("test --no-run -j1")
78-
.with_stderr(expected_output)
89+
.with_stderr_data(expected_output)
7990
.run();
8091
}
8192

@@ -99,27 +110,34 @@ fn deduplicate_messages_mismatched_warnings() {
99110
)
100111
.build();
101112
let lib_output = raw_rustc_output(&p, "src/lib.rs", &[]);
102-
let mut lib_test_output = raw_rustc_output(&p, "src/lib.rs", &["--test"]);
113+
let lib_output = redact_rustc_message(&lib_output);
114+
let lib_test_output = raw_rustc_output(&p, "src/lib.rs", &["--test"]);
115+
let mut lib_test_output = redact_rustc_message(&lib_test_output);
103116
// Remove the duplicate warning.
104117
let start = lib_test_output.find(&lib_output).expect("same warning");
105118
lib_test_output.replace_range(start..start + lib_output.len(), "");
106119
let expected_output = format!(
107120
"\
108121
{}\
109-
warning: `foo` (lib) generated 1 warning[..]
122+
[WARNING] `foo` (lib) generated 1 warning[..]
110123
{}\
111-
warning: `foo` (lib test) generated 2 warnings (1 duplicate)
112-
[FINISHED] [..]
113-
[EXECUTABLE] unittests src/lib.rs (target/debug/deps/foo-[..][EXE])
124+
[WARNING] `foo` (lib test) generated 2 warnings (1 duplicate)
125+
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
126+
[EXECUTABLE] unittests src/lib.rs (target/debug/deps/foo-[HASH][EXE])
114127
",
115128
lib_output, lib_test_output
116129
);
117130
p.cargo("test --no-run -j1")
118-
.with_stderr(&format!("[COMPILING] foo v0.0.1 [..]\n{}", expected_output))
131+
.with_stderr_data(&format!(
132+
"\
133+
[COMPILING] foo v0.0.1 ([ROOT]/foo)
134+
{}",
135+
expected_output
136+
))
119137
.run();
120138
// Run again, to check for caching behavior.
121139
p.cargo("test --no-run -j1")
122-
.with_stderr(expected_output)
140+
.with_stderr_data(expected_output)
123141
.run();
124142
}
125143

@@ -134,12 +152,13 @@ fn deduplicate_errors() {
134152
)
135153
.build();
136154
let rustc_message = raw_rustc_output(&p, "src/lib.rs", &[]);
155+
let rustc_message = redact_rustc_message(&rustc_message);
137156
p.cargo("test -j1")
138157
.with_status(101)
139-
.with_stderr(&format!(
158+
.with_stderr_data(&format!(
140159
"\
141-
[COMPILING] foo v0.0.1 [..]
142-
{}error: could not compile `foo` (lib) due to 1 previous error
160+
[COMPILING] foo v0.0.1 ([ROOT]/foo)
161+
{}[ERROR] could not compile `foo` (lib) due to 1 previous error
143162
",
144163
rustc_message
145164
))

0 commit comments

Comments
 (0)