Skip to content

Commit

Permalink
Auto merge of rust-lang#122779 - estebank:test-svg-non-determinism, r…
Browse files Browse the repository at this point in the history
…=compiler-errors

When comparing SVG tests against their blessed version, ignore the first line

`anstyle_svg` has some weird non-determinism in the width parameter, which makes tests blessed in one environment to fail in another. This is the *only* non-determinism detected so far, so we modify the diff check to ignore the first line of the SVG. In order for a test to fail/be updated by `--bless`, a different part of the file needs to also have changed. If other sources of non-determinism are found, we should back out of the "`--color=always` means `.svg`" change.

r? `@compiler-errors`
  • Loading branch information
bors committed Mar 20, 2024
2 parents 94b72d6 + bf63f7e commit e3df96c
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3982,17 +3982,20 @@ impl<'test> TestCx<'test> {
}
}

fn force_color_svg(&self) -> bool {
self.props.compile_flags.iter().any(|s| s.contains("--color=always"))
}

fn load_compare_outputs(
&self,
proc_res: &ProcRes,
output_kind: TestOutput,
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 force_color_svg {
if self.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.
Expand Down Expand Up @@ -4039,8 +4042,8 @@ impl<'test> TestCx<'test> {
_ => {}
};

let stderr = if force_color_svg {
anstyle_svg::Term::new().min_width_px(730).render_svg(&proc_res.stderr)
let stderr = if self.force_color_svg() {
anstyle_svg::Term::new().render_svg(&proc_res.stderr)
} else if explicit_format {
proc_res.stderr.clone()
} else {
Expand Down Expand Up @@ -4652,7 +4655,13 @@ impl<'test> TestCx<'test> {
}

fn compare_output(&self, kind: &str, actual: &str, expected: &str) -> usize {
if actual == expected {
let are_different = match (self.force_color_svg(), expected.find('\n'), actual.find('\n')) {
// FIXME: We ignore the first line of SVG files
// because the width parameter is non-deterministic.
(true, Some(nl_e), Some(nl_a)) => expected[nl_e..] != actual[nl_a..],
_ => expected != actual,
};
if !are_different {
return 0;
}

Expand Down

0 comments on commit e3df96c

Please sign in to comment.