Skip to content

Commit

Permalink
ui tests: fix for MacOS and skip for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospb19 committed Sep 16, 2023
1 parent b45cc1e commit 6963cf2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
18 changes: 9 additions & 9 deletions Cargo.lock

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

23 changes: 21 additions & 2 deletions tests/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ mod utils;

use std::{io, path::Path, process::Output};

#[cfg(not(windows))]
use insta::assert_display_snapshot as ui;

// Don't run these on Windows
#[cfg(windows)]
use self::ignore as ui;
use crate::utils::run_in;

fn testdir() -> io::Result<(tempfile::TempDir, &'static Path)> {
Expand Down Expand Up @@ -37,9 +41,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());
let redacted = "<FOLDER>";

text.replace(&path, "<FOLDER>/")
let path = path.display();
let path = if cfg!(target_os = "macos") {
format!(r"/private{path}")
} else {
path.to_string()
};

text.replace(path.as_str(), redacted)
}

fn output_to_string(output: Output) -> String {
Expand Down Expand Up @@ -101,3 +112,11 @@ fn ui_test_usage_help_flag() {
ui!(output_to_string(ouch!("--help")));
ui!(output_to_string(ouch!("-h")));
}

#[allow(unused)]
#[macro_export]
macro_rules! ignore {
($expr:expr) => {{
$expr
}};
}

0 comments on commit 6963cf2

Please sign in to comment.