Skip to content

Commit 75a155b

Browse files
committed
compiletest: ignore SVG y offset in by-lines comparison
SVG diagnostic snapshots (`--color=always`) render one terminal row per line. Under the parallel front-end, independent diagnostics can be emitted in a different order, which only permutes the rows and re-renders each at a different vertical `y` offset; the content of every row is unchanged. The parallel front-end already compares ui output as a sorted line multiset, but the `y` attribute is part of each line, so a pure reordering was still reported as a difference. Strip the `y` coordinate (and the `<svg>` header line, whose width and height are already ignored by the exact comparison) before the multiset comparison. The normalization is only used for the equality check; the original strings are kept for the diff and for blessing, and single-threaded runs keep the exact comparison including `y`. With this, the multiline-removal-suggestion test passes under the parallel front-end, so drop its ignore directive.
1 parent d595fce commit 75a155b

2 files changed

Lines changed: 31 additions & 6 deletions

File tree

src/tools/compiletest/src/runtest.rs

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2714,11 +2714,37 @@ impl<'test> TestCx<'test> {
27142714
(&tmp.0, &tmp.1)
27152715
}
27162716
} else if compare_output_by_lines {
2717-
let mut actual_lines: Vec<&str> = actual.lines().collect();
2718-
let mut expected_lines: Vec<&str> = expected.lines().collect();
2719-
actual_lines.sort_unstable();
2720-
expected_lines.sort_unstable();
2721-
if actual_lines == expected_lines {
2717+
// SVG output (`--color=always`) renders one terminal row per line,
2718+
// laid out top to bottom. Under the parallel front-end, independent
2719+
// diagnostics can be emitted in a different order, which permutes the
2720+
// rows and re-renders each at a different vertical `y` offset without
2721+
// changing its content. Strip the `y` coordinate (and the first line,
2722+
// the `<svg>` header whose width/height are already ignored by the
2723+
// exact comparison above) before the line-multiset comparison so that
2724+
// such a reordering is not reported as a difference. The normalization
2725+
// is comparison-only: on mismatch the original strings are kept for
2726+
// the diff and for blessing. Single-threaded runs take the
2727+
// exact-comparison path above and still check `y`.
2728+
let matches = if self.force_color_svg() {
2729+
let strip_y = static_regex!(r#"y="\d+px""#);
2730+
let normalize = |svg: &str| {
2731+
let mut lines: Vec<String> = svg
2732+
.lines()
2733+
.skip(1)
2734+
.map(|line| strip_y.replace_all(line, r#"y="0px""#).into_owned())
2735+
.collect();
2736+
lines.sort_unstable();
2737+
lines
2738+
};
2739+
normalize(expected) == normalize(actual)
2740+
} else {
2741+
let mut actual_lines: Vec<&str> = actual.lines().collect();
2742+
let mut expected_lines: Vec<&str> = expected.lines().collect();
2743+
actual_lines.sort_unstable();
2744+
expected_lines.sort_unstable();
2745+
actual_lines == expected_lines
2746+
};
2747+
if matches {
27222748
return CompareOutcome::Same;
27232749
} else {
27242750
(expected, actual)

tests/ui/error-emitter/multiline-removal-suggestion.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,3 @@ fn bay() -> Vec<(bool, HashSet<u8>)> {
5656
.collect()
5757
}
5858
fn main() {}
59-
//@ ignore-parallel-frontend invalid svg(multiple threads trying to write to the same file)

0 commit comments

Comments
 (0)