Skip to content

Commit 138d065

Browse files
committed
test: migrate messages to snapbox
1 parent 0e2ef80 commit 138d065

File tree

1 file changed

+44
-18
lines changed

1 file changed

+44
-18
lines changed

tests/testsuite/messages.rs

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
//!
33
//! Tests for message caching can be found in `cache_messages`.
44
5-
#![allow(deprecated)]
6-
75
use cargo_test_support::{process, project, Project};
86
use cargo_util::ProcessError;
97

@@ -47,6 +45,20 @@ pub fn raw_rustc_output(project: &Project, path: &str, extra: &[&str]) -> String
4745
result
4846
}
4947

48+
fn redact_rustc_message(msg: &str) -> String {
49+
let mut msg = msg
50+
.replace("help:", "[HELP]")
51+
.replace("note:", "[NOTE]")
52+
.replace("warning:", "[WARNING]")
53+
.replace("error:", "[ERROR]");
54+
55+
if cfg!(windows) {
56+
msg = msg.replace("\\", "/");
57+
}
58+
59+
msg
60+
}
61+
5062
#[cargo_test]
5163
fn deduplicate_messages_basic() {
5264
let p = project()
@@ -60,21 +72,27 @@ fn deduplicate_messages_basic() {
6072
)
6173
.build();
6274
let rustc_message = raw_rustc_output(&p, "src/lib.rs", &[]);
75+
let rustc_message = redact_rustc_message(&rustc_message);
6376
let expected_output = format!(
6477
"{}\
65-
warning: `foo` (lib) generated 1 warning[..]
66-
warning: `foo` (lib test) generated 1 warning (1 duplicate)
67-
[FINISHED] [..]
68-
[EXECUTABLE] unittests src/lib.rs (target/debug/deps/foo-[..][EXE])
78+
[WARNING] `foo` (lib) generated 1 warning[..]
79+
[WARNING] `foo` (lib test) generated 1 warning (1 duplicate)
80+
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
81+
[EXECUTABLE] unittests src/lib.rs (target/debug/deps/foo-[HASH][EXE])
6982
",
7083
rustc_message
7184
);
7285
p.cargo("test --no-run -j1")
73-
.with_stderr(&format!("[COMPILING] foo [..]\n{}", expected_output))
86+
.with_stderr_data(&format!(
87+
"\
88+
[COMPILING] foo v0.0.1 ([ROOT]/foo)
89+
{}",
90+
expected_output
91+
))
7492
.run();
7593
// Run again, to check for caching behavior.
7694
p.cargo("test --no-run -j1")
77-
.with_stderr(expected_output)
95+
.with_stderr_data(expected_output)
7896
.run();
7997
}
8098

@@ -98,27 +116,34 @@ fn deduplicate_messages_mismatched_warnings() {
98116
)
99117
.build();
100118
let lib_output = raw_rustc_output(&p, "src/lib.rs", &[]);
101-
let mut lib_test_output = raw_rustc_output(&p, "src/lib.rs", &["--test"]);
119+
let lib_output = redact_rustc_message(&lib_output);
120+
let lib_test_output = raw_rustc_output(&p, "src/lib.rs", &["--test"]);
121+
let mut lib_test_output = redact_rustc_message(&lib_test_output);
102122
// Remove the duplicate warning.
103123
let start = lib_test_output.find(&lib_output).expect("same warning");
104124
lib_test_output.replace_range(start..start + lib_output.len(), "");
105125
let expected_output = format!(
106126
"\
107127
{}\
108-
warning: `foo` (lib) generated 1 warning[..]
128+
[WARNING] `foo` (lib) generated 1 warning[..]
109129
{}\
110-
warning: `foo` (lib test) generated 2 warnings (1 duplicate)
111-
[FINISHED] [..]
112-
[EXECUTABLE] unittests src/lib.rs (target/debug/deps/foo-[..][EXE])
130+
[WARNING] `foo` (lib test) generated 2 warnings (1 duplicate)
131+
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
132+
[EXECUTABLE] unittests src/lib.rs (target/debug/deps/foo-[HASH][EXE])
113133
",
114134
lib_output, lib_test_output
115135
);
116136
p.cargo("test --no-run -j1")
117-
.with_stderr(&format!("[COMPILING] foo v0.0.1 [..]\n{}", expected_output))
137+
.with_stderr_data(&format!(
138+
"\
139+
[COMPILING] foo v0.0.1 ([ROOT]/foo)
140+
{}",
141+
expected_output
142+
))
118143
.run();
119144
// Run again, to check for caching behavior.
120145
p.cargo("test --no-run -j1")
121-
.with_stderr(expected_output)
146+
.with_stderr_data(expected_output)
122147
.run();
123148
}
124149

@@ -133,12 +158,13 @@ fn deduplicate_errors() {
133158
)
134159
.build();
135160
let rustc_message = raw_rustc_output(&p, "src/lib.rs", &[]);
161+
let rustc_message = redact_rustc_message(&rustc_message);
136162
p.cargo("test -j1")
137163
.with_status(101)
138-
.with_stderr(&format!(
164+
.with_stderr_data(&format!(
139165
"\
140-
[COMPILING] foo v0.0.1 [..]
141-
{}error: could not compile `foo` (lib) due to 1 previous error
166+
[COMPILING] foo v0.0.1 ([ROOT]/foo)
167+
{}[ERROR] could not compile `foo` (lib) due to 1 previous error
142168
",
143169
rustc_message
144170
))

0 commit comments

Comments
 (0)