Skip to content

Commit e3df96c

Browse files
committed
Auto merge of #122779 - estebank:test-svg-non-determinism, r=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`
2 parents 94b72d6 + bf63f7e commit e3df96c

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/tools/compiletest/src/runtest.rs

+14-5
Original file line numberDiff line numberDiff line change
@@ -3982,17 +3982,20 @@ impl<'test> TestCx<'test> {
39823982
}
39833983
}
39843984

3985+
fn force_color_svg(&self) -> bool {
3986+
self.props.compile_flags.iter().any(|s| s.contains("--color=always"))
3987+
}
3988+
39853989
fn load_compare_outputs(
39863990
&self,
39873991
proc_res: &ProcRes,
39883992
output_kind: TestOutput,
39893993
explicit_format: bool,
39903994
) -> usize {
39913995
let stderr_bits = format!("{}bit.stderr", self.config.get_pointer_width());
3992-
let force_color_svg = self.props.compile_flags.iter().any(|s| s.contains("--color=always"));
39933996
let (stderr_kind, stdout_kind) = match output_kind {
39943997
TestOutput::Compile => (
3995-
if force_color_svg {
3998+
if self.force_color_svg() {
39963999
if self.config.target.contains("windows") {
39974000
// We single out Windows here because some of the CLI coloring is
39984001
// specifically changed for Windows.
@@ -4039,8 +4042,8 @@ impl<'test> TestCx<'test> {
40394042
_ => {}
40404043
};
40414044

4042-
let stderr = if force_color_svg {
4043-
anstyle_svg::Term::new().min_width_px(730).render_svg(&proc_res.stderr)
4045+
let stderr = if self.force_color_svg() {
4046+
anstyle_svg::Term::new().render_svg(&proc_res.stderr)
40444047
} else if explicit_format {
40454048
proc_res.stderr.clone()
40464049
} else {
@@ -4652,7 +4655,13 @@ impl<'test> TestCx<'test> {
46524655
}
46534656

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

0 commit comments

Comments
 (0)