Skip to content

Commit

Permalink
fix ui tests for MacOS
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospb19 committed Sep 16, 2023
1 parent b45cc1e commit 0a03fe7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
19 changes: 10 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ insta = "1.31.0"
parse-display = "0.8.2"
proptest = "1.2.0"
rand = { version = "0.8.5", default-features = false, features = ["small_rng", "std"] }
regex = { version = "1.9.5", default-features = false, features = ["unicode-perl"] }
test-strategy = "0.3.1"

[features]
Expand Down
14 changes: 11 additions & 3 deletions tests/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ mod utils;
use std::{io, path::Path, process::Output};

use insta::assert_display_snapshot as ui;
use regex::Regex;

use crate::utils::run_in;

Expand Down Expand Up @@ -37,9 +38,16 @@ fn run_ouch(argv: &str, dir: &Path) -> String {

// remove random tempdir paths from snapshots to make them deterministic
fn redact_paths(text: &str, path: &Path) -> String {
let path = format!("{}/", path.display());

text.replace(&path, "<FOLDER>/")
let path = path.display();
let redacted = "<FOLDER>";

if cfg!(target_os = "macos") {
let pattern = &format!(r"(/private[\w\S]+?/)?{path}");
let pattern = Regex::new(pattern).unwrap();
pattern.replace_all(text, redacted).to_string()
} else {
text.replace(&path.to_string(), redacted)
}
}

fn output_to_string(output: Output) -> String {
Expand Down

0 comments on commit 0a03fe7

Please sign in to comment.