about summary refs log tree commit diff
path: root/src/tools/compiletest
diff options
context:
space:
mode:
authorEsteban Kuber <esteban@kuber.com.ar>2024-03-02 14:36:52 -0800
committerEsteban Küber <esteban@kuber.com.ar>2024-03-02 22:47:17 +0000
commitb4bdb56f86e136ca63bf71dca3034200c6c25900 (patch)
treee058c8945b21f0464e7a7d95f04332c8ff681432 /src/tools/compiletest
parent5257aee7dd163d21d32fa904578d4fb0f4c91b79 (diff)
downloadrust-b4bdb56f86e136ca63bf71dca3034200c6c25900.tar.gz
rust-b4bdb56f86e136ca63bf71dca3034200c6c25900.zip
On tests that specify --color=always emit SVG file with stderr output
Leverage `anstyle-svg`, as `cargo` does now, to emit `.svg` files
instead of `.stderr` files for tests that explicitly enable color
output. This will make reviewing changes to the graphical output of
tests much more human friendly.
Diffstat (limited to 'src/tools/compiletest')
-rw-r--r--src/tools/compiletest/Cargo.toml1
-rw-r--r--src/tools/compiletest/src/common.rs4
-rw-r--r--src/tools/compiletest/src/runtest.rs23
3 files changed, 25 insertions, 3 deletions
diff --git a/src/tools/compiletest/Cargo.toml b/src/tools/compiletest/Cargo.toml
index 62d0fcc1a60..4539c9b3285 100644
--- a/src/tools/compiletest/Cargo.toml
+++ b/src/tools/compiletest/Cargo.toml
@@ -7,6 +7,7 @@ edition = "2021"
 doctest = false
 
 [dependencies]
+anstyle-svg = "0.1.3"
 colored = "2"
 diff = "0.1.10"
 unified-diff = "0.2.1"
diff --git a/src/tools/compiletest/src/common.rs b/src/tools/compiletest/src/common.rs
index 49f1226e2cc..d1bca60d285 100644
--- a/src/tools/compiletest/src/common.rs
+++ b/src/tools/compiletest/src/common.rs
@@ -704,6 +704,8 @@ pub fn expected_output_path(
 
 pub const UI_EXTENSIONS: &[&str] = &[
     UI_STDERR,
+    UI_SVG,
+    UI_WINDOWS_SVG,
     UI_STDOUT,
     UI_FIXED,
     UI_RUN_STDERR,
@@ -715,6 +717,8 @@ pub const UI_EXTENSIONS: &[&str] = &[
     UI_COVERAGE_MAP,
 ];
 pub const UI_STDERR: &str = "stderr";
+pub const UI_SVG: &str = "svg";
+pub const UI_WINDOWS_SVG: &str = "windows.svg";
 pub const UI_STDOUT: &str = "stdout";
 pub const UI_FIXED: &str = "fixed";
 pub const UI_RUN_STDERR: &str = "run.stderr";
diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs
index a942aa9dc90..ae0db88d873 100644
--- a/src/tools/compiletest/src/runtest.rs
+++ b/src/tools/compiletest/src/runtest.rs
@@ -1,6 +1,8 @@
 // ignore-tidy-filelength
 
-use crate::common::{expected_output_path, UI_EXTENSIONS, UI_FIXED, UI_STDERR, UI_STDOUT};
+use crate::common::{
+    expected_output_path, UI_EXTENSIONS, UI_FIXED, UI_STDERR, UI_STDOUT, UI_SVG, UI_WINDOWS_SVG,
+};
 use crate::common::{incremental_dir, output_base_dir, output_base_name, output_testname_unique};
 use crate::common::{Assembly, Incremental, JsDocTest, MirOpt, RunMake, RustdocJson, Ui};
 use crate::common::{Codegen, CodegenUnits, DebugInfo, Debugger, Rustdoc};
@@ -4014,9 +4016,22 @@ impl<'test> TestCx<'test> {
         explicit_format: bool,
     ) -> usize {
         let stderr_bits = format!("{}bit.stderr", self.config.get_pointer_width());
+        let force_color_svg = self.props.compile_flags.iter().any(|s| s.contains("--color=always"));
         let (stderr_kind, stdout_kind) = match output_kind {
             TestOutput::Compile => (
-                { if self.props.stderr_per_bitwidth { &stderr_bits } else { UI_STDERR } },
+                if force_color_svg {
+                    if self.config.target.contains("windows") {
+                        // We single out Windows here because some of the CLI coloring is
+                        // specifically changed for Windows.
+                        UI_WINDOWS_SVG
+                    } else {
+                        UI_SVG
+                    }
+                } else if self.props.stderr_per_bitwidth {
+                    &stderr_bits
+                } else {
+                    UI_STDERR
+                },
                 UI_STDOUT,
             ),
             TestOutput::Run => (UI_RUN_STDERR, UI_RUN_STDOUT),
@@ -4051,7 +4066,9 @@ impl<'test> TestCx<'test> {
             _ => {}
         };
 
-        let stderr = if explicit_format {
+        let stderr = if force_color_svg {
+            anstyle_svg::Term::new().render_svg(&proc_res.stderr)
+        } else if explicit_format {
             proc_res.stderr.clone()
         } else {
             json::extract_rendered(&proc_res.stderr)