move roc_cli tests to use insta snapshots

This commit is contained in:
Luke Boswell 2024-10-09 09:45:07 +11:00
parent e3afeaa7ff
commit 81668e66bf
No known key found for this signature in database
GPG key ID: F6DB3C9DB47377B0
43 changed files with 464 additions and 394 deletions

View file

@ -6,7 +6,6 @@ extern crate tempfile;
use regex::Regex;
use roc_command_utils::{cargo, pretty_command_string, root_dir};
use roc_reporting::report::ANSI_STYLE_CODES;
use serde::Deserialize;
use serde_xml_rs::from_str;
use std::env;
@ -115,30 +114,6 @@ impl Out {
normalized_output.trim().to_string()
}
/// Assert that the stdout ends with the expected string
/// This normalises the output for comparison in tests such as replacing timings
/// with a placeholder, or stripping ANSI colors
pub fn assert_stdout_and_stderr_ends_with(&self, expected: &str) {
let normalised_output = format!(
"{}{}",
Out::normalize_for_tests(&self.stdout),
Out::normalize_for_tests(&self.stderr)
);
assert!(
normalised_output.ends_with(expected),
"\n{}EXPECTED stdout and stderr after normalizing:\n----------------\n{}{}\n{}ACTUAL stdout and stderr after normalizing:\n----------------\n{}{}{}\n----------------\n{}",
ANSI_STYLE_CODES.cyan,
ANSI_STYLE_CODES.reset,
expected,
ANSI_STYLE_CODES.cyan,
ANSI_STYLE_CODES.reset,
normalised_output,
ANSI_STYLE_CODES.cyan,
ANSI_STYLE_CODES.reset,
);
}
pub fn normalize_stdout_and_stderr(&self) -> String {
format!(
"{}{}",