cli run tests passing on macos

This commit is contained in:
Luke Boswell 2024-08-16 17:59:53 +10:00
parent c3785a2def
commit 767ec7af84
No known key found for this signature in database
GPG key ID: F6DB3C9DB47377B0
9 changed files with 92 additions and 353 deletions

View file

@ -75,9 +75,12 @@ impl Out {
/// Normalise the output for comparison in tests by replacing with a placeholder
fn normalize_for_tests(input: &String) -> String {
// normalise from windows line endings to unix line endings
let without_clrf = input.replace("\r\n", "\n");
// remove ANSI color codes
let ansi_regex = Regex::new(r"\x1b\[[0-9;]*[mGKH]").expect("Invalid ANSI regex pattern");
let without_ansi = ansi_regex.replace_all(input, "");
let without_ansi = ansi_regex.replace_all(without_clrf.as_str(), "");
// replace timings with a placeholder
let regex = Regex::new(r" in (\d+) ms\.").expect("Invalid regex pattern");
@ -88,8 +91,15 @@ impl Out {
let filepath_regex =
Regex::new(r"\[([^:]+):(\d+)\]").expect("Invalid filepath regex pattern");
let filepath_replacement = "[<ignored for tests>:$2]";
filepath_regex
.replace_all(&without_timings, filepath_replacement)
let without_filepaths = filepath_regex.replace_all(&without_timings, filepath_replacement);
// replace error summary timings
let error_summary_regex =
Regex::new(r"(\d+) error(?:s)? and (\d+) warning(?:s)? found in \d+ ms")
.expect("Invalid error summary regex pattern");
let error_summary_replacement = "$1 error and $2 warning found in <ignored for test> ms";
error_summary_regex
.replace_all(&without_filepaths, error_summary_replacement)
.to_string()
}