diff options
author | Leo Kettmeir <crowlkats@toaxl.com> | 2024-02-12 14:35:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-12 14:35:23 +0100 |
commit | bd1358efab8ba7339a8e70034315fa7da840292e (patch) | |
tree | f29f366cbff49cdf0bfab697dcde4fb94ff7a09d /test_util/src | |
parent | 80d5ffbe7c4109229571bf94182cf3f40397795e (diff) |
fix(console): support NO_COLOR and colors option in all scenarios (#21910)
Noticed in #21607
Diffstat (limited to 'test_util/src')
-rw-r--r-- | test_util/src/builders.rs | 26 | ||||
-rw-r--r-- | test_util/src/lib.rs | 4 |
2 files changed, 24 insertions, 6 deletions
diff --git a/test_util/src/builders.rs b/test_util/src/builders.rs index f0002b52f..862838dcb 100644 --- a/test_util/src/builders.rs +++ b/test_util/src/builders.rs @@ -316,6 +316,7 @@ pub struct TestCommandBuilder { args_text: String, args_vec: Vec<String>, split_output: bool, + skip_strip_ansi: bool, } impl TestCommandBuilder { @@ -327,6 +328,7 @@ impl TestCommandBuilder { stderr: None, stdin_text: None, split_output: false, + skip_strip_ansi: false, cwd: None, envs: Default::default(), envs_remove: Default::default(), @@ -410,6 +412,11 @@ impl TestCommandBuilder { self } + pub fn skip_strip_ansi(mut self) -> Self { + self.skip_strip_ansi = true; + self + } + pub fn stdin<T: Into<Stdio>>(mut self, cfg: T) -> Self { self.stdin = Some(StdioContainer::new(cfg.into())); self @@ -533,8 +540,14 @@ impl TestCommandBuilder { output } - fn sanitize_output(text: String, args: &[OsString]) -> String { - let mut text = strip_ansi_codes(&text).to_string(); + fn sanitize_output( + mut text: String, + args: &[OsString], + skip_strip_ansi: bool, + ) -> String { + if !skip_strip_ansi { + text = strip_ansi_codes(&text).to_string(); + } // deno test's output capturing flushes with a zero-width space in order to // synchronize the output pipes. Occasionally this zero width space // might end up in the output so strip it from the output comparison here. @@ -581,14 +594,15 @@ impl TestCommandBuilder { // and dropping it closes them. drop(command); - let combined = combined_reader - .map(|pipe| sanitize_output(read_pipe_to_string(pipe), &args)); + let combined = combined_reader.map(|pipe| { + sanitize_output(read_pipe_to_string(pipe), &args, self.skip_strip_ansi) + }); let status = process.wait().unwrap(); let std_out_err = std_out_err_handle.map(|(stdout, stderr)| { ( - sanitize_output(stdout.join().unwrap(), &args), - sanitize_output(stderr.join().unwrap(), &args), + sanitize_output(stdout.join().unwrap(), &args, self.skip_strip_ansi), + sanitize_output(stderr.join().unwrap(), &args, self.skip_strip_ansi), ) }); let exit_code = status.code(); diff --git a/test_util/src/lib.rs b/test_util/src/lib.rs index eda386a82..7bb99a573 100644 --- a/test_util/src/lib.rs +++ b/test_util/src/lib.rs @@ -490,6 +490,7 @@ pub struct CheckOutputIntegrationTest<'a> { pub http_server: bool, pub envs: Vec<(String, String)>, pub env_clear: bool, + pub skip_strip_ansi: bool, pub temp_cwd: bool, /// Copies the files at the specified directory in the "testdata" directory /// to the temp folder and runs the test from there. This is useful when @@ -531,6 +532,9 @@ impl<'a> CheckOutputIntegrationTest<'a> { if self.env_clear { command_builder = command_builder.env_clear(); } + if self.skip_strip_ansi { + command_builder = command_builder.skip_strip_ansi(); + } if let Some(cwd) = &self.cwd { command_builder = command_builder.current_dir(cwd); } |