Skip to content

Commit f56d444

Browse files
committed
test: migrate messages to snapbox
1 parent b31577d commit f56d444

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::prelude::*;
86
use cargo_test_support::{process, project, Project};
97
use cargo_util::ProcessError;
@@ -48,6 +46,20 @@ pub fn raw_rustc_output(project: &Project, path: &str, extra: &[&str]) -> String
4846
result
4947
}
5048

49+
fn redact_rustc_message(msg: &str) -> String {
50+
let mut msg = msg
51+
.replace("help:", "[HELP]")
52+
.replace("note:", "[NOTE]")
53+
.replace("warning:", "[WARNING]")
54+
.replace("error:", "[ERROR]");
55+
56+
if cfg!(windows) {
57+
msg = msg.replace("\\", "/");
58+
}
59+
60+
msg
61+
}
62+
5163
#[cargo_test]
5264
fn deduplicate_messages_basic() {
5365
let p = project()
@@ -61,21 +73,27 @@ fn deduplicate_messages_basic() {
6173
)
6274
.build();
6375
let rustc_message = raw_rustc_output(&p, "src/lib.rs", &[]);
76+
let rustc_message = redact_rustc_message(&rustc_message);
6477
let expected_output = format!(
6578
"{}\
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])
79+
[WARNING] `foo` (lib) generated 1 warning[..]
80+
[WARNING] `foo` (lib test) generated 1 warning (1 duplicate)
81+
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
82+
[EXECUTABLE] unittests src/lib.rs (target/debug/deps/foo-[HASH][EXE])
7083
",
7184
rustc_message
7285
);
7386
p.cargo("test --no-run -j1")
74-
.with_stderr(&format!("[COMPILING] foo [..]\n{}", expected_output))
87+
.with_stderr_data(&format!(
88+
"\
89+
[COMPILING] foo v0.0.1 ([ROOT]/foo)
90+
{}",
91+
expected_output
92+
))
7593
.run();
7694
// Run again, to check for caching behavior.
7795
p.cargo("test --no-run -j1")
78-
.with_stderr(expected_output)
96+
.with_stderr_data(expected_output)
7997
.run();
8098
}
8199

@@ -99,27 +117,34 @@ fn deduplicate_messages_mismatched_warnings() {
99117
)
100118
.build();
101119
let lib_output = raw_rustc_output(&p, "src/lib.rs", &[]);
102-
let mut lib_test_output = raw_rustc_output(&p, "src/lib.rs", &["--test"]);
120+
let lib_output = redact_rustc_message(&lib_output);
121+
let lib_test_output = raw_rustc_output(&p, "src/lib.rs", &["--test"]);
122+
let mut lib_test_output = redact_rustc_message(&lib_test_output);
103123
// Remove the duplicate warning.
104124
let start = lib_test_output.find(&lib_output).expect("same warning");
105125
lib_test_output.replace_range(start..start + lib_output.len(), "");
106126
let expected_output = format!(
107127
"\
108128
{}\
109-
warning: `foo` (lib) generated 1 warning[..]
129+
[WARNING] `foo` (lib) generated 1 warning[..]
110130
{}\
111-
warning: `foo` (lib test) generated 2 warnings (1 duplicate)
112-
[FINISHED] [..]
113-
[EXECUTABLE] unittests src/lib.rs (target/debug/deps/foo-[..][EXE])
131+
[WARNING] `foo` (lib test) generated 2 warnings (1 duplicate)
132+
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
133+
[EXECUTABLE] unittests src/lib.rs (target/debug/deps/foo-[HASH][EXE])
114134
",
115135
lib_output, lib_test_output
116136
);
117137
p.cargo("test --no-run -j1")
118-
.with_stderr(&format!("[COMPILING] foo v0.0.1 [..]\n{}", expected_output))
138+
.with_stderr_data(&format!(
139+
"\
140+
[COMPILING] foo v0.0.1 ([ROOT]/foo)
141+
{}",
142+
expected_output
143+
))
119144
.run();
120145
// Run again, to check for caching behavior.
121146
p.cargo("test --no-run -j1")
122-
.with_stderr(expected_output)
147+
.with_stderr_data(expected_output)
123148
.run();
124149
}
125150

@@ -134,12 +159,13 @@ fn deduplicate_errors() {
134159
)
135160
.build();
136161
let rustc_message = raw_rustc_output(&p, "src/lib.rs", &[]);
162+
let rustc_message = redact_rustc_message(&rustc_message);
137163
p.cargo("test -j1")
138164
.with_status(101)
139-
.with_stderr(&format!(
165+
.with_stderr_data(&format!(
140166
"\
141-
[COMPILING] foo v0.0.1 [..]
142-
{}error: could not compile `foo` (lib) due to 1 previous error
167+
[COMPILING] foo v0.0.1 ([ROOT]/foo)
168+
{}[ERROR] could not compile `foo` (lib) due to 1 previous error
143169
",
144170
rustc_message
145171
))

0 commit comments

Comments
 (0)