Skip to content

Commit 4387811

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 4387811

13 files changed

+303
-75
lines changed

Cargo.lock

+38
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,15 @@ version = "1.0.6"
149149
source = "registry+https://github.com/rust-lang/crates.io-index"
150150
checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc"
151151

152+
[[package]]
153+
name = "anstyle-lossy"
154+
version = "1.1.0"
155+
source = "registry+https://github.com/rust-lang/crates.io-index"
156+
checksum = "a9a0444767dbd4aea9355cb47a370eb184dbfe918875e127eff52cb9d1638181"
157+
dependencies = [
158+
"anstyle",
159+
]
160+
152161
[[package]]
153162
name = "anstyle-parse"
154163
version = "0.2.3"
@@ -167,6 +176,19 @@ dependencies = [
167176
"windows-sys 0.52.0",
168177
]
169178

179+
[[package]]
180+
name = "anstyle-svg"
181+
version = "0.1.3"
182+
source = "registry+https://github.com/rust-lang/crates.io-index"
183+
checksum = "8b6ddad447b448d6d5db36b31cbd3ff27c7af071619501998eeceab01968287a"
184+
dependencies = [
185+
"anstream",
186+
"anstyle",
187+
"anstyle-lossy",
188+
"html-escape",
189+
"unicode-width",
190+
]
191+
170192
[[package]]
171193
name = "anstyle-wincon"
172194
version = "3.0.2"
@@ -724,6 +746,7 @@ dependencies = [
724746
name = "compiletest"
725747
version = "0.0.0"
726748
dependencies = [
749+
"anstyle-svg",
727750
"anyhow",
728751
"build_helper",
729752
"colored",
@@ -1672,6 +1695,15 @@ dependencies = [
16721695
"walkdir",
16731696
]
16741697

1698+
[[package]]
1699+
name = "html-escape"
1700+
version = "0.2.13"
1701+
source = "registry+https://github.com/rust-lang/crates.io-index"
1702+
checksum = "6d1ad449764d627e22bfd7cd5e8868264fc9236e07c752972b4080cd351cb476"
1703+
dependencies = [
1704+
"utf8-width",
1705+
]
1706+
16751707
[[package]]
16761708
name = "html5ever"
16771709
version = "0.26.0"
@@ -6018,6 +6050,12 @@ version = "0.7.6"
60186050
source = "registry+https://github.com/rust-lang/crates.io-index"
60196051
checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9"
60206052

6053+
[[package]]
6054+
name = "utf8-width"
6055+
version = "0.1.7"
6056+
source = "registry+https://github.com/rust-lang/crates.io-index"
6057+
checksum = "86bd8d4e895da8537e5315b8254664e6b769c4ff3db18321b297a1e7004392e3"
6058+
60216059
[[package]]
60226060
name = "utf8parse"
60236061
version = "0.2.1"

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)

src/tools/tidy/src/ui_tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const ROOT_ENTRY_LIMIT: usize = 872;
2323
const EXPECTED_TEST_FILE_EXTENSIONS: &[&str] = &[
2424
"rs", // test source files
2525
"stderr", // expected stderr file, corresponds to a rs file
26+
"svg", // expected svg file, corresponds to a rs file, equivalent to stderr
2627
"stdout", // expected stdout file, corresponds to a rs file
2728
"fixed", // expected source file after applying fixes
2829
"md", // test directory descriptions

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)