Skip to content

Commit b65b353

Browse files
committed
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.
1 parent 2dceda4 commit b65b353

11 files changed

+264
-75
lines changed

src/tools/compiletest/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ edition = "2021"
77
doctest = false
88

99
[dependencies]
10+
anstyle-svg = "0.1.3"
1011
colored = "2"
1112
diff = "0.1.10"
1213
unified-diff = "0.2.1"

src/tools/compiletest/src/common.rs

+2
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,7 @@ pub fn expected_output_path(
703703
}
704704

705705
pub const UI_EXTENSIONS: &[&str] = &[
706+
UI_SVG,
706707
UI_STDERR,
707708
UI_STDOUT,
708709
UI_FIXED,
@@ -714,6 +715,7 @@ pub const UI_EXTENSIONS: &[&str] = &[
714715
UI_COVERAGE,
715716
UI_COVERAGE_MAP,
716717
];
718+
pub const UI_SVG: &str = "svg";
717719
pub const UI_STDERR: &str = "stderr";
718720
pub const UI_STDOUT: &str = "stdout";
719721
pub const UI_FIXED: &str = "fixed";

src/tools/compiletest/src/runtest.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ignore-tidy-filelength
22

3-
use crate::common::{expected_output_path, UI_EXTENSIONS, UI_FIXED, UI_STDERR, UI_STDOUT};
3+
use crate::common::{expected_output_path, UI_EXTENSIONS, UI_FIXED, UI_STDERR, UI_STDOUT, UI_SVG};
44
use crate::common::{incremental_dir, output_base_dir, output_base_name, output_testname_unique};
55
use crate::common::{Assembly, Incremental, JsDocTest, MirOpt, RunMake, RustdocJson, Ui};
66
use crate::common::{Codegen, CodegenUnits, DebugInfo, Debugger, Rustdoc};
@@ -4014,9 +4014,17 @@ impl<'test> TestCx<'test> {
40144014
explicit_format: bool,
40154015
) -> usize {
40164016
let stderr_bits = format!("{}bit.stderr", self.config.get_pointer_width());
4017+
let force_color_svg = self.props.compile_flags.iter().any(|s| s.contains("--color"))
4018+
&& !self.config.target.contains("windows");
40174019
let (stderr_kind, stdout_kind) = match output_kind {
40184020
TestOutput::Compile => (
4019-
{ if self.props.stderr_per_bitwidth { &stderr_bits } else { UI_STDERR } },
4021+
if force_color_svg {
4022+
UI_SVG
4023+
} else if self.props.stderr_per_bitwidth {
4024+
&stderr_bits
4025+
} else {
4026+
UI_STDERR
4027+
},
40204028
UI_STDOUT,
40214029
),
40224030
TestOutput::Run => (UI_RUN_STDERR, UI_RUN_STDOUT),
@@ -4051,7 +4059,9 @@ impl<'test> TestCx<'test> {
40514059
_ => {}
40524060
};
40534061

4054-
let stderr = if explicit_format {
4062+
let stderr = if force_color_svg {
4063+
anstyle_svg::Term::new().render_svg(&proc_res.stderr)
4064+
} else if explicit_format {
40554065
proc_res.stderr.clone()
40564066
} else {
40574067
json::extract_rendered(&proc_res.stderr)

tests/ui/diagnostic-flags/colored-session-opt-error.stderr

-2
This file was deleted.
Loading

tests/ui/error-emitter/highlighting.not-windows.stderr

-22
This file was deleted.
Loading

tests/ui/error-emitter/multiline-multipart-suggestion.not-windows.stderr

-46
This file was deleted.

0 commit comments

Comments
 (0)