Skip to content

Commit b4bdb56

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 5257aee commit b4bdb56

18 files changed

+485
-150
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"
@@ -6019,6 +6051,12 @@ version = "0.7.6"
60196051
source = "registry+https://github.com/rust-lang/crates.io-index"
60206052
checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9"
60216053

6054+
[[package]]
6055+
name = "utf8-width"
6056+
version = "0.1.7"
6057+
source = "registry+https://github.com/rust-lang/crates.io-index"
6058+
checksum = "86bd8d4e895da8537e5315b8254664e6b769c4ff3db18321b297a1e7004392e3"
6059+
60226060
[[package]]
60236061
name = "utf8parse"
60246062
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

+4
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,8 @@ pub fn expected_output_path(
704704

705705
pub const UI_EXTENSIONS: &[&str] = &[
706706
UI_STDERR,
707+
UI_SVG,
708+
UI_WINDOWS_SVG,
707709
UI_STDOUT,
708710
UI_FIXED,
709711
UI_RUN_STDERR,
@@ -715,6 +717,8 @@ pub const UI_EXTENSIONS: &[&str] = &[
715717
UI_COVERAGE_MAP,
716718
];
717719
pub const UI_STDERR: &str = "stderr";
720+
pub const UI_SVG: &str = "svg";
721+
pub const UI_WINDOWS_SVG: &str = "windows.svg";
718722
pub const UI_STDOUT: &str = "stdout";
719723
pub const UI_FIXED: &str = "fixed";
720724
pub const UI_RUN_STDERR: &str = "run.stderr";

src/tools/compiletest/src/runtest.rs

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

3-
use crate::common::{expected_output_path, UI_EXTENSIONS, UI_FIXED, UI_STDERR, UI_STDOUT};
3+
use crate::common::{
4+
expected_output_path, UI_EXTENSIONS, UI_FIXED, UI_STDERR, UI_STDOUT, UI_SVG, UI_WINDOWS_SVG,
5+
};
46
use crate::common::{incremental_dir, output_base_dir, output_base_name, output_testname_unique};
57
use crate::common::{Assembly, Incremental, JsDocTest, MirOpt, RunMake, RustdocJson, Ui};
68
use crate::common::{Codegen, CodegenUnits, DebugInfo, Debugger, Rustdoc};
@@ -4014,9 +4016,22 @@ impl<'test> TestCx<'test> {
40144016
explicit_format: bool,
40154017
) -> usize {
40164018
let stderr_bits = format!("{}bit.stderr", self.config.get_pointer_width());
4019+
let force_color_svg = self.props.compile_flags.iter().any(|s| s.contains("--color=always"));
40174020
let (stderr_kind, stdout_kind) = match output_kind {
40184021
TestOutput::Compile => (
4019-
{ if self.props.stderr_per_bitwidth { &stderr_bits } else { UI_STDERR } },
4022+
if force_color_svg {
4023+
if self.config.target.contains("windows") {
4024+
// We single out Windows here because some of the CLI coloring is
4025+
// specifically changed for Windows.
4026+
UI_WINDOWS_SVG
4027+
} else {
4028+
UI_SVG
4029+
}
4030+
} else if self.props.stderr_per_bitwidth {
4031+
&stderr_bits
4032+
} else {
4033+
UI_STDERR
4034+
},
40204035
UI_STDOUT,
40214036
),
40224037
TestOutput::Run => (UI_RUN_STDERR, UI_RUN_STDOUT),
@@ -4051,7 +4066,9 @@ impl<'test> TestCx<'test> {
40514066
_ => {}
40524067
};
40534068

4054-
let stderr = if explicit_format {
4069+
let stderr = if force_color_svg {
4070+
anstyle_svg::Term::new().render_svg(&proc_res.stderr)
4071+
} else if explicit_format {
40554072
proc_res.stderr.clone()
40564073
} else {
40574074
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
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
//@ check-pass
22
//@ ignore-windows
3-
//@ compile-flags: -Cremark=foo --error-format=human --color always
3+
//@ compile-flags: -Cremark=foo --error-format=human --color=always
4+
// Temporary until next release:
5+
//@ ignore-stage2
46
fn main() {}

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.

tests/ui/error-emitter/highlighting.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
//@ compile-flags: --error-format=human --color=always
44
//@ error-pattern:for<'a> 
55
//@ edition:2018
6-
7-
//@ revisions: windows not-windows
8-
//@ [windows]only-windows
9-
//@ [not-windows]ignore-windows
6+
// Temporary until next release:
7+
//@ ignore-stage2
108

119
use core::pin::Pin;
1210
use core::future::Future;
+72
Loading

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

-22
This file was deleted.
Loading

0 commit comments

Comments
 (0)