Skip to content

Commit a03fe2c

Browse files
committed
compiletest: Refactor and document compare_output
1 parent 19e75f4 commit a03fe2c

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

src/tools/compiletest/src/runtest.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2323,15 +2323,15 @@ impl<'test> TestCx<'test> {
23232323
&normalized_stdout,
23242324
&proc_res.stdout,
23252325
&expected_stdout,
2326-
);
2326+
) as usize;
23272327
}
23282328
if !self.props.dont_check_compiler_stderr {
23292329
errors += self.compare_output(
23302330
stderr_kind,
23312331
&normalized_stderr,
23322332
&stderr,
23332333
&expected_stderr,
2334-
);
2334+
) as usize;
23352335
}
23362336
}
23372337
TestOutput::Run => {
@@ -2340,9 +2340,10 @@ impl<'test> TestCx<'test> {
23402340
&normalized_stdout,
23412341
&proc_res.stdout,
23422342
&expected_stdout,
2343-
);
2343+
) as usize;
23442344
errors +=
2345-
self.compare_output(stderr_kind, &normalized_stderr, &stderr, &expected_stderr);
2345+
self.compare_output(stderr_kind, &normalized_stderr, &stderr, &expected_stderr)
2346+
as usize;
23462347
}
23472348
}
23482349
errors
@@ -2570,21 +2571,22 @@ impl<'test> TestCx<'test> {
25702571
}
25712572
}
25722573

2574+
// Returns `true` if output differed and was not blessed
25732575
fn compare_output(
25742576
&self,
25752577
stream: &str,
25762578
actual: &str,
25772579
actual_unnormalized: &str,
25782580
expected: &str,
2579-
) -> usize {
2581+
) -> bool {
25802582
let are_different = match (self.force_color_svg(), expected.find('\n'), actual.find('\n')) {
25812583
// FIXME: We ignore the first line of SVG files
25822584
// because the width parameter is non-deterministic.
25832585
(true, Some(nl_e), Some(nl_a)) => expected[nl_e..] != actual[nl_a..],
25842586
_ => expected != actual,
25852587
};
25862588
if !are_different {
2587-
return 0;
2589+
return false;
25882590
}
25892591

25902592
// Wrapper tools set by `runner` might provide extra output on failure,
@@ -2600,7 +2602,7 @@ impl<'test> TestCx<'test> {
26002602
used.retain(|line| actual_lines.contains(line));
26012603
// check if `expected` contains a subset of the lines of `actual`
26022604
if used.len() == expected_lines.len() && (expected.is_empty() == actual.is_empty()) {
2603-
return 0;
2605+
return false;
26042606
}
26052607
if expected_lines.is_empty() {
26062608
// if we have no lines to check, force a full overwite
@@ -2659,7 +2661,7 @@ impl<'test> TestCx<'test> {
26592661

26602662
println!("\nThe actual {0} differed from the expected {0}.", stream);
26612663

2662-
if self.config.bless { 0 } else { 1 }
2664+
if self.config.bless { false } else { true }
26632665
}
26642666

26652667
/// Returns whether to show the full stderr/stdout.

src/tools/compiletest/src/runtest/coverage.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ impl<'test> TestCx<'test> {
4646
&expected_coverage_dump,
4747
);
4848

49-
if coverage_dump_errors > 0 {
49+
if coverage_dump_errors {
5050
self.fatal_proc_rec(
51-
&format!("{coverage_dump_errors} errors occurred comparing coverage output."),
51+
&format!("an error occurred comparing coverage output."),
5252
&proc_res,
5353
);
5454
}
@@ -146,9 +146,9 @@ impl<'test> TestCx<'test> {
146146
&expected_coverage,
147147
);
148148

149-
if coverage_errors > 0 {
149+
if coverage_errors {
150150
self.fatal_proc_rec(
151-
&format!("{} errors occurred comparing coverage output.", coverage_errors),
151+
&format!("an error occurred comparing coverage output."),
152152
&proc_res,
153153
);
154154
}

src/tools/compiletest/src/runtest/ui.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ impl TestCx<'_> {
100100
)
101101
});
102102

103-
errors += self.compare_output("fixed", &fixed_code, &fixed_code, &expected_fixed);
103+
errors +=
104+
self.compare_output("fixed", &fixed_code, &fixed_code, &expected_fixed) as usize;
104105
} else if !expected_fixed.is_empty() {
105106
panic!(
106107
"the `//@ run-rustfix` directive wasn't found but a `*.fixed` \

0 commit comments

Comments
 (0)