Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On tests that specify --color=always emit SVG file with stderr output #121877

Merged
merged 1 commit into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 4 additions & 0 deletions src/tools/compiletest/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,8 @@ pub fn expected_output_path(

pub const UI_EXTENSIONS: &[&str] = &[
UI_STDERR,
UI_SVG,
UI_WINDOWS_SVG,
UI_STDOUT,
UI_FIXED,
UI_RUN_STDERR,
Expand All @@ -715,6 +717,8 @@ pub const UI_EXTENSIONS: &[&str] = &[
UI_COVERAGE_MAP,
];
pub const UI_STDERR: &str = "stderr";
pub const UI_SVG: &str = "svg";
pub const UI_WINDOWS_SVG: &str = "windows.svg";
pub const UI_STDOUT: &str = "stdout";
pub const UI_FIXED: &str = "fixed";
pub const UI_RUN_STDERR: &str = "run.stderr";
Expand Down
23 changes: 20 additions & 3 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// 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, UI_WINDOWS_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 +4016,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=always"));
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.
UI_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 +4066,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
4 changes: 3 additions & 1 deletion tests/ui/diagnostic-flags/colored-session-opt-error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//@ check-pass
//@ ignore-windows
//@ compile-flags: -Cremark=foo --error-format=human --color always
//@ compile-flags: -Cremark=foo --error-format=human --color=always
// Temporary until next release:
//@ ignore-stage2
fn main() {}
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.

6 changes: 2 additions & 4 deletions tests/ui/error-emitter/highlighting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
//@ compile-flags: --error-format=human --color=always
//@ error-pattern:for<'a> 
//@ edition:2018

//@ revisions: windows not-windows
//@ [windows]only-windows
//@ [not-windows]ignore-windows
// Temporary until next release:
//@ ignore-stage2

use core::pin::Pin;
use core::future::Future;
Expand Down
72 changes: 72 additions & 0 deletions tests/ui/error-emitter/highlighting.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.windows.stderr

This file was deleted.

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