Skip to content

Commit

Permalink
compiletest: Automatically compare output by subset with runners
Browse files Browse the repository at this point in the history
This commit updates compiletest to automatically compare test output
with subsets if a `--runner` argument is configured. Runners might
inject extra information on failures, for example a WebAssembly runtime
printing a wasm stack trace, which won't be in the output of a native
runtime. The output with a `--runner` argument, however, should still
have all the native output present.
  • Loading branch information
alexcrichton committed Mar 11, 2024
1 parent fc746c8 commit 4a5aa1a
Showing 1 changed file with 20 additions and 49 deletions.
69 changes: 20 additions & 49 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,12 +493,8 @@ impl<'test> TestCx<'test> {
let expected_coverage_dump = self.load_expected_output(kind);
let actual_coverage_dump = self.normalize_output(&proc_res.stdout, &[]);

let coverage_dump_errors = self.compare_output(
kind,
&actual_coverage_dump,
&expected_coverage_dump,
self.props.compare_output_lines_by_subset,
);
let coverage_dump_errors =
self.compare_output(kind, &actual_coverage_dump, &expected_coverage_dump);

if coverage_dump_errors > 0 {
self.fatal_proc_rec(
Expand Down Expand Up @@ -591,12 +587,8 @@ impl<'test> TestCx<'test> {
self.fatal_proc_rec(&err, &proc_res);
});

let coverage_errors = self.compare_output(
kind,
&normalized_actual_coverage,
&expected_coverage,
self.props.compare_output_lines_by_subset,
);
let coverage_errors =
self.compare_output(kind, &normalized_actual_coverage, &expected_coverage);

if coverage_errors > 0 {
self.fatal_proc_rec(
Expand Down Expand Up @@ -4051,35 +4043,17 @@ impl<'test> TestCx<'test> {
match output_kind {
TestOutput::Compile => {
if !self.props.dont_check_compiler_stdout {
errors += self.compare_output(
stdout_kind,
&normalized_stdout,
&expected_stdout,
self.props.compare_output_lines_by_subset,
);
errors +=
self.compare_output(stdout_kind, &normalized_stdout, &expected_stdout);
}
if !self.props.dont_check_compiler_stderr {
errors += self.compare_output(
stderr_kind,
&normalized_stderr,
&expected_stderr,
self.props.compare_output_lines_by_subset,
);
errors +=
self.compare_output(stderr_kind, &normalized_stderr, &expected_stderr);
}
}
TestOutput::Run => {
errors += self.compare_output(
stdout_kind,
&normalized_stdout,
&expected_stdout,
self.props.compare_output_lines_by_subset,
);
errors += self.compare_output(
stderr_kind,
&normalized_stderr,
&expected_stderr,
self.props.compare_output_lines_by_subset,
);
errors += self.compare_output(stdout_kind, &normalized_stdout, &expected_stdout);
errors += self.compare_output(stderr_kind, &normalized_stderr, &expected_stderr);
}
}
errors
Expand Down Expand Up @@ -4173,12 +4147,7 @@ impl<'test> TestCx<'test> {
)
});

errors += self.compare_output(
"fixed",
&fixed_code,
&expected_fixed,
self.props.compare_output_lines_by_subset,
);
errors += self.compare_output("fixed", &fixed_code, &expected_fixed);
} else if !expected_fixed.is_empty() {
panic!(
"the `//@ run-rustfix` directive wasn't found but a `*.fixed` \
Expand Down Expand Up @@ -4673,17 +4642,19 @@ impl<'test> TestCx<'test> {
}
}

fn compare_output(
&self,
kind: &str,
actual: &str,
expected: &str,
compare_output_by_lines: bool,
) -> usize {
fn compare_output(&self, kind: &str, actual: &str, expected: &str) -> usize {
if actual == expected {
return 0;
}

// If `compare-output-lines-by-subset` is not explicitly enabled then
// auto-enable it when a `runner` is in use since wrapper tools might
// provide extra output on failure, for example a WebAssembly runtime
// might print the stack trace of an `unreachable` instruction by
// default.
let compare_output_by_lines =
self.props.compare_output_lines_by_subset || self.config.runner.is_some();

let tmp;
let (expected, actual): (&str, &str) = if compare_output_by_lines {
let actual_lines: HashSet<_> = actual.lines().collect();
Expand Down

0 comments on commit 4a5aa1a

Please sign in to comment.