Skip to content

Commit 4a5aa1a

Browse files
committed
compiletest: Automatically compare output by subset with runners
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.
1 parent fc746c8 commit 4a5aa1a

File tree

1 file changed

+20
-49
lines changed

1 file changed

+20
-49
lines changed

src/tools/compiletest/src/runtest.rs

+20-49
Original file line numberDiff line numberDiff line change
@@ -493,12 +493,8 @@ impl<'test> TestCx<'test> {
493493
let expected_coverage_dump = self.load_expected_output(kind);
494494
let actual_coverage_dump = self.normalize_output(&proc_res.stdout, &[]);
495495

496-
let coverage_dump_errors = self.compare_output(
497-
kind,
498-
&actual_coverage_dump,
499-
&expected_coverage_dump,
500-
self.props.compare_output_lines_by_subset,
501-
);
496+
let coverage_dump_errors =
497+
self.compare_output(kind, &actual_coverage_dump, &expected_coverage_dump);
502498

503499
if coverage_dump_errors > 0 {
504500
self.fatal_proc_rec(
@@ -591,12 +587,8 @@ impl<'test> TestCx<'test> {
591587
self.fatal_proc_rec(&err, &proc_res);
592588
});
593589

594-
let coverage_errors = self.compare_output(
595-
kind,
596-
&normalized_actual_coverage,
597-
&expected_coverage,
598-
self.props.compare_output_lines_by_subset,
599-
);
590+
let coverage_errors =
591+
self.compare_output(kind, &normalized_actual_coverage, &expected_coverage);
600592

601593
if coverage_errors > 0 {
602594
self.fatal_proc_rec(
@@ -4051,35 +4043,17 @@ impl<'test> TestCx<'test> {
40514043
match output_kind {
40524044
TestOutput::Compile => {
40534045
if !self.props.dont_check_compiler_stdout {
4054-
errors += self.compare_output(
4055-
stdout_kind,
4056-
&normalized_stdout,
4057-
&expected_stdout,
4058-
self.props.compare_output_lines_by_subset,
4059-
);
4046+
errors +=
4047+
self.compare_output(stdout_kind, &normalized_stdout, &expected_stdout);
40604048
}
40614049
if !self.props.dont_check_compiler_stderr {
4062-
errors += self.compare_output(
4063-
stderr_kind,
4064-
&normalized_stderr,
4065-
&expected_stderr,
4066-
self.props.compare_output_lines_by_subset,
4067-
);
4050+
errors +=
4051+
self.compare_output(stderr_kind, &normalized_stderr, &expected_stderr);
40684052
}
40694053
}
40704054
TestOutput::Run => {
4071-
errors += self.compare_output(
4072-
stdout_kind,
4073-
&normalized_stdout,
4074-
&expected_stdout,
4075-
self.props.compare_output_lines_by_subset,
4076-
);
4077-
errors += self.compare_output(
4078-
stderr_kind,
4079-
&normalized_stderr,
4080-
&expected_stderr,
4081-
self.props.compare_output_lines_by_subset,
4082-
);
4055+
errors += self.compare_output(stdout_kind, &normalized_stdout, &expected_stdout);
4056+
errors += self.compare_output(stderr_kind, &normalized_stderr, &expected_stderr);
40834057
}
40844058
}
40854059
errors
@@ -4173,12 +4147,7 @@ impl<'test> TestCx<'test> {
41734147
)
41744148
});
41754149

4176-
errors += self.compare_output(
4177-
"fixed",
4178-
&fixed_code,
4179-
&expected_fixed,
4180-
self.props.compare_output_lines_by_subset,
4181-
);
4150+
errors += self.compare_output("fixed", &fixed_code, &expected_fixed);
41824151
} else if !expected_fixed.is_empty() {
41834152
panic!(
41844153
"the `//@ run-rustfix` directive wasn't found but a `*.fixed` \
@@ -4673,17 +4642,19 @@ impl<'test> TestCx<'test> {
46734642
}
46744643
}
46754644

4676-
fn compare_output(
4677-
&self,
4678-
kind: &str,
4679-
actual: &str,
4680-
expected: &str,
4681-
compare_output_by_lines: bool,
4682-
) -> usize {
4645+
fn compare_output(&self, kind: &str, actual: &str, expected: &str) -> usize {
46834646
if actual == expected {
46844647
return 0;
46854648
}
46864649

4650+
// If `compare-output-lines-by-subset` is not explicitly enabled then
4651+
// auto-enable it when a `runner` is in use since wrapper tools might
4652+
// provide extra output on failure, for example a WebAssembly runtime
4653+
// might print the stack trace of an `unreachable` instruction by
4654+
// default.
4655+
let compare_output_by_lines =
4656+
self.props.compare_output_lines_by_subset || self.config.runner.is_some();
4657+
46874658
let tmp;
46884659
let (expected, actual): (&str, &str) = if compare_output_by_lines {
46894660
let actual_lines: HashSet<_> = actual.lines().collect();

0 commit comments

Comments
 (0)