mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 15:21:12 +00:00
restore one test
This commit is contained in:
parent
49f5ea88fc
commit
29289694b5
2 changed files with 19 additions and 12 deletions
|
@ -342,17 +342,19 @@ mod cli_run {
|
||||||
output
|
output
|
||||||
}
|
}
|
||||||
|
|
||||||
// when you want to run `roc test` to execute `expect`s, perhaps on a library rather than an application.
|
/// Run `roc test` to execute `expect`s, perhaps on a library rather than an application.
|
||||||
fn test_roc_expect(dir_name: &str, roc_filename: &str, flags: &[&str], expected_ending: &str) {
|
fn test_roc_expect(dir_name: &str, roc_filename: &str, flags: &[&str], expected_ending: &str) {
|
||||||
_ = get_output_with_stdin(
|
// TODO - do we want to run with Valgrind?
|
||||||
file_path_from_root(dir_name, roc_filename).as_path(),
|
|
||||||
vec![],
|
let out = Run::new_roc()
|
||||||
flags,
|
.arg(CMD_TEST)
|
||||||
&[],
|
.arg(file_path_from_root(dir_name, roc_filename).as_path())
|
||||||
&[],
|
.add_args(flags)
|
||||||
UseValgrind::Yes,
|
.run();
|
||||||
TestCliCommands::Test,
|
|
||||||
);
|
out.assert_clean_success();
|
||||||
|
|
||||||
|
out.assert_stdout_ends_with(expected_ending);
|
||||||
}
|
}
|
||||||
|
|
||||||
// when you don't need args, stdin or extra_env
|
// when you don't need args, stdin or extra_env
|
||||||
|
|
|
@ -69,15 +69,20 @@ impl Out {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Normalise the output for comparison in tests by stripping ANSI color codes
|
||||||
|
/// and replace test timings with a placeholder.
|
||||||
pub fn stdout_without_test_timings(&self) -> String {
|
pub fn stdout_without_test_timings(&self) -> String {
|
||||||
|
let ansi_regex = Regex::new(r"\x1b\[[0-9;]*[mGKH]").expect("Invalid ANSI regex pattern");
|
||||||
|
let without_ansi = ansi_regex.replace_all(&self.stdout, "");
|
||||||
|
|
||||||
let regex = Regex::new(r" in (\d+) ms\.").expect("Invalid regex pattern");
|
let regex = Regex::new(r" in (\d+) ms\.").expect("Invalid regex pattern");
|
||||||
let replacement = " in <ignored for test> ms.";
|
let replacement = " in <ignored for test> ms.";
|
||||||
regex.replace_all(&self.stdout, replacement).to_string()
|
regex.replace_all(&without_ansi, replacement).to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn assert_stdout_ends_with(&self, expected: &str) {
|
pub fn assert_stdout_ends_with(&self, expected: &str) {
|
||||||
assert!(
|
assert!(
|
||||||
self.stdout_without_test_timings().ends_with(expected),
|
dbg!(self.stdout_without_test_timings()).ends_with(expected),
|
||||||
"Expected stdout to end with:\n{}\n\nActual stdout:\n{}",
|
"Expected stdout to end with:\n{}\n\nActual stdout:\n{}",
|
||||||
expected,
|
expected,
|
||||||
self.stdout
|
self.stdout
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue