Skip to content

Commit ea36ed0

Browse files
committed
refactor(test): Share redactions between ui and e2e
1 parent 94119af commit ea36ed0

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ use crate::diff;
4040
use crate::paths;
4141
use anyhow::{bail, Context, Result};
4242
use serde_json::Value;
43-
use std::env;
4443
use std::fmt;
4544
use std::path::Path;
4645
use std::str;
@@ -84,7 +83,7 @@ pub fn assert_ui() -> snapbox::Assert {
8483
let root_url = url::Url::from_file_path(&root).unwrap().to_string();
8584

8685
let mut subs = snapbox::Redactions::new();
87-
subs.extend([("[EXE]", std::env::consts::EXE_SUFFIX)])
86+
subs.extend(MIN_LITERAL_REDACTIONS.into_iter().cloned())
8887
.unwrap();
8988
subs.insert("[ROOT]", root).unwrap();
9089
subs.insert("[ROOTURL]", root_url).unwrap();
@@ -98,6 +97,8 @@ pub fn assert_ui() -> snapbox::Assert {
9897
.redact_with(subs)
9998
}
10099

100+
static MIN_LITERAL_REDACTIONS: &[(&str, &str)] = &[("[EXE]", std::env::consts::EXE_SUFFIX)];
101+
101102
/// Normalizes the output so that it can be compared against the expected value.
102103
fn normalize_actual(actual: &str, cwd: Option<&Path>) -> String {
103104
// It's easier to read tabs in outputs if they don't show up as literal
@@ -226,7 +227,6 @@ fn substitute_macros(input: &str) -> String {
226227
("[SUMMARY]", " Summary"),
227228
("[FIXED]", " Fixed"),
228229
("[FIXING]", " Fixing"),
229-
("[EXE]", env::consts::EXE_SUFFIX),
230230
("[IGNORED]", " Ignored"),
231231
("[INSTALLED]", " Installed"),
232232
("[REPLACED]", " Replaced"),
@@ -244,6 +244,9 @@ fn substitute_macros(input: &str) -> String {
244244
("[GENERATED]", " Generated"),
245245
];
246246
let mut result = input.to_owned();
247+
for &(pat, subst) in MIN_LITERAL_REDACTIONS {
248+
result = result.replace(pat, subst)
249+
}
247250
for &(pat, subst) in &macros {
248251
result = result.replace(pat, subst)
249252
}

0 commit comments

Comments
 (0)