Skip to content

Commit

Permalink
Auto merge of rust-lang#121877 - estebank:fancy-svg, r=<try>
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Mar 2, 2024
2 parents 5257aee + d8961f0 commit 63ee2ef
Show file tree
Hide file tree
Showing 13 changed files with 308 additions and 75 deletions.
38 changes: 38 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,15 @@ version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc"

[[package]]
name = "anstyle-lossy"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a9a0444767dbd4aea9355cb47a370eb184dbfe918875e127eff52cb9d1638181"
dependencies = [
"anstyle",
]

[[package]]
name = "anstyle-parse"
version = "0.2.3"
Expand All @@ -167,6 +176,19 @@ dependencies = [
"windows-sys 0.52.0",
]

[[package]]
name = "anstyle-svg"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b6ddad447b448d6d5db36b31cbd3ff27c7af071619501998eeceab01968287a"
dependencies = [
"anstream",
"anstyle",
"anstyle-lossy",
"html-escape",
"unicode-width",
]

[[package]]
name = "anstyle-wincon"
version = "3.0.2"
Expand Down Expand Up @@ -724,6 +746,7 @@ dependencies = [
name = "compiletest"
version = "0.0.0"
dependencies = [
"anstyle-svg",
"anyhow",
"build_helper",
"colored",
Expand Down Expand Up @@ -1672,6 +1695,15 @@ dependencies = [
"walkdir",
]

[[package]]
name = "html-escape"
version = "0.2.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d1ad449764d627e22bfd7cd5e8868264fc9236e07c752972b4080cd351cb476"
dependencies = [
"utf8-width",
]

[[package]]
name = "html5ever"
version = "0.26.0"
Expand Down Expand Up @@ -6019,6 +6051,12 @@ version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9"

[[package]]
name = "utf8-width"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86bd8d4e895da8537e5315b8254664e6b769c4ff3db18321b297a1e7004392e3"

[[package]]
name = "utf8parse"
version = "0.2.1"
Expand Down
1 change: 1 addition & 0 deletions src/tools/compiletest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions src/tools/compiletest/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,7 @@ pub fn expected_output_path(
}

pub const UI_EXTENSIONS: &[&str] = &[
UI_SVG,
UI_STDERR,
UI_STDOUT,
UI_FIXED,
Expand All @@ -714,6 +715,7 @@ pub const UI_EXTENSIONS: &[&str] = &[
UI_COVERAGE,
UI_COVERAGE_MAP,
];
pub const UI_SVG: &str = "svg";
pub const UI_STDERR: &str = "stderr";
pub const UI_STDOUT: &str = "stdout";
pub const UI_FIXED: &str = "fixed";
Expand Down
21 changes: 18 additions & 3 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// 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};
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};
Expand Down Expand Up @@ -4014,9 +4014,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"));
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.
"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),
Expand Down Expand Up @@ -4051,7 +4064,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)
Expand Down
1 change: 1 addition & 0 deletions src/tools/tidy/src/ui_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const ROOT_ENTRY_LIMIT: usize = 872;
const EXPECTED_TEST_FILE_EXTENSIONS: &[&str] = &[
"rs", // test source files
"stderr", // expected stderr file, corresponds to a rs file
"svg", // expected svg file, corresponds to a rs file, equivalent to stderr
"stdout", // expected stdout file, corresponds to a rs file
"fixed", // expected source file after applying fixes
"md", // test directory descriptions
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/diagnostic-flags/colored-session-opt-error.stderr

This file was deleted.

29 changes: 29 additions & 0 deletions tests/ui/diagnostic-flags/colored-session-opt-error.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 0 additions & 22 deletions tests/ui/error-emitter/highlighting.not-windows.stderr

This file was deleted.

72 changes: 72 additions & 0 deletions tests/ui/error-emitter/highlighting.not-windows.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

This file was deleted.

Loading

0 comments on commit 63ee2ef

Please sign in to comment.