diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2024-03-06 12:43:00 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2024-03-11 09:36:35 -0700 |
| commit | 4a5aa1a104a9a85cc765af863f64297f9e7e73f6 (patch) | |
| tree | 4a21208d692a9c3055f389e13e891467d042a4a2 /src/tools | |
| parent | fc746c811867e6dadabb91429813ccf808a84913 (diff) | |
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.
Diffstat (limited to 'src/tools')
| -rw-r--r-- | src/tools/compiletest/src/runtest.rs | 69 |
1 files changed, 20 insertions, 49 deletions
diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 3e0021bf7c6..7be0571b111 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -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( @@ -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( @@ -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 @@ -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` \ @@ -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(); |
