Skip to content

Commit

Permalink
On tests that specify --color=always emit SVG file with stderr output
Browse files Browse the repository at this point in the history
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
estebank committed Mar 1, 2024
1 parent 2dceda4 commit b65b353
Show file tree
Hide file tree
Showing 11 changed files with 264 additions and 75 deletions.
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
16 changes: 13 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,17 @@ 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"))
&& !self.config.target.contains("windows");
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 {
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 +4059,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
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 b65b353

Please sign in to comment.