Skip to content

Commit a10b3ca

Browse files
committed
refactor(test): Split out 'pure' redactions for testing
1 parent c8113d3 commit a10b3ca

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

crates/cargo-test-support/src/compare.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,11 @@ macro_rules! regex {
8888
/// - Carriage returns are removed, which can help when running on Windows.
8989
pub fn assert_ui() -> snapbox::Assert {
9090
let mut subs = snapbox::Redactions::new();
91-
add_common_redactions(&mut subs);
91+
subs.extend(MIN_LITERAL_REDACTIONS.into_iter().cloned())
92+
.unwrap();
93+
add_test_support_redactions(&mut subs);
94+
add_regex_redactions(&mut subs);
95+
9296
snapbox::Assert::new()
9397
.action_env(snapbox::assert::DEFAULT_ACTION_ENV)
9498
.redact_with(subs)
@@ -127,25 +131,33 @@ pub fn assert_ui() -> snapbox::Assert {
127131
/// - Carriage returns are removed, which can help when running on Windows.
128132
pub fn assert_e2e() -> snapbox::Assert {
129133
let mut subs = snapbox::Redactions::new();
130-
add_common_redactions(&mut subs);
134+
subs.extend(MIN_LITERAL_REDACTIONS.into_iter().cloned())
135+
.unwrap();
131136
subs.extend(E2E_LITERAL_REDACTIONS.into_iter().cloned())
132137
.unwrap();
138+
add_test_support_redactions(&mut subs);
139+
add_regex_redactions(&mut subs);
133140

134141
snapbox::Assert::new()
135142
.action_env(snapbox::assert::DEFAULT_ACTION_ENV)
136143
.redact_with(subs)
137144
}
138145

139-
fn add_common_redactions(subs: &mut snapbox::Redactions) {
146+
fn add_test_support_redactions(subs: &mut snapbox::Redactions) {
140147
let root = paths::root();
141148
// Use `from_file_path` instead of `from_dir_path` so the trailing slash is
142149
// put in the users output, rather than hidden in the variable
143150
let root_url = url::Url::from_file_path(&root).unwrap().to_string();
144151

145-
subs.extend(MIN_LITERAL_REDACTIONS.into_iter().cloned())
146-
.unwrap();
147152
subs.insert("[ROOT]", root).unwrap();
148153
subs.insert("[ROOTURL]", root_url).unwrap();
154+
subs.insert("[HOST_TARGET]", rustc_host()).unwrap();
155+
if let Some(alt_target) = try_alternate() {
156+
subs.insert("[ALT_TARGET]", alt_target).unwrap();
157+
}
158+
}
159+
160+
fn add_regex_redactions(subs: &mut snapbox::Redactions) {
149161
// For e2e tests
150162
subs.insert(
151163
"[ELAPSED]",
@@ -186,10 +198,6 @@ fn add_common_redactions(subs: &mut snapbox::Redactions) {
186198
.unwrap();
187199
subs.insert("[HASH]", regex!(r"/[a-z0-9\-_]+-(?<redacted>[0-9a-f]{16})"))
188200
.unwrap();
189-
subs.insert("[HOST_TARGET]", rustc_host()).unwrap();
190-
if let Some(alt_target) = try_alternate() {
191-
subs.insert("[ALT_TARGET]", alt_target).unwrap();
192-
}
193201
subs.insert(
194202
"[AVG_ELAPSED]",
195203
regex!(r"(?<redacted>[0-9]+(\.[0-9]+)?) ns/iter"),

0 commit comments

Comments
 (0)