Skip to content

Commit 0e3bc62

Browse files
committed
Allow checking of both compile & run output for run-pass tests
1 parent b9ba8f9 commit 0e3bc62

File tree

2 files changed

+34
-18
lines changed

2 files changed

+34
-18
lines changed

src/tools/compiletest/src/common.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -333,10 +333,12 @@ pub fn expected_output_path(
333333
testpaths.file.with_extension(extension)
334334
}
335335

336-
pub const UI_EXTENSIONS: &[&str] = &[UI_STDERR, UI_STDOUT, UI_FIXED];
336+
pub const UI_EXTENSIONS: &[&str] = &[UI_STDERR, UI_STDOUT, UI_FIXED, UI_RUN_STDERR, UI_RUN_STDOUT];
337337
pub const UI_STDERR: &str = "stderr";
338338
pub const UI_STDOUT: &str = "stdout";
339339
pub const UI_FIXED: &str = "fixed";
340+
pub const UI_RUN_STDERR: &str = "run.stderr";
341+
pub const UI_RUN_STDOUT: &str = "run.stdout";
340342

341343
/// Absolute path to the directory where all output for all tests in the given
342344
/// `relative_dir` group should reside. Example:

src/tools/compiletest/src/runtest.rs

+31-17
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use crate::common::{CompareMode, PassMode};
44
use crate::common::{expected_output_path, UI_EXTENSIONS, UI_FIXED, UI_STDERR, UI_STDOUT};
5+
use crate::common::{UI_RUN_STDERR, UI_RUN_STDOUT};
56
use crate::common::{output_base_dir, output_base_name, output_testname_unique};
67
use crate::common::{Codegen, CodegenUnits, Rustdoc};
78
use crate::common::{DebugInfoCdb, DebugInfoGdbLldb, DebugInfoGdb, DebugInfoLldb};
@@ -288,6 +289,11 @@ enum ReadFrom {
288289
Stdin(String),
289290
}
290291

292+
enum TestOutput {
293+
Compile,
294+
Run,
295+
}
296+
291297
impl<'test> TestCx<'test> {
292298
/// Code executed for each revision in turn (or, if there are no
293299
/// revisions, exactly once, with revision == None).
@@ -2934,9 +2940,16 @@ impl<'test> TestCx<'test> {
29342940
}
29352941
}
29362942

2937-
fn load_compare_outputs(&self, proc_res: &ProcRes, explicit_format: bool) -> usize {
2938-
let expected_stderr = self.load_expected_output(UI_STDERR);
2939-
let expected_stdout = self.load_expected_output(UI_STDOUT);
2943+
fn load_compare_outputs(&self, proc_res: &ProcRes,
2944+
output_kind: TestOutput, explicit_format: bool) -> usize {
2945+
2946+
let (stderr_kind, stdout_kind) = match output_kind {
2947+
TestOutput::Compile => (UI_STDERR, UI_STDOUT),
2948+
TestOutput::Run => (UI_RUN_STDERR, UI_RUN_STDOUT)
2949+
};
2950+
2951+
let expected_stderr = self.load_expected_output(stderr_kind);
2952+
let expected_stdout = self.load_expected_output(stdout_kind);
29402953

29412954
let normalized_stdout =
29422955
self.normalize_output(&proc_res.stdout, &self.props.normalize_stdout);
@@ -2949,11 +2962,19 @@ impl<'test> TestCx<'test> {
29492962

29502963
let normalized_stderr = self.normalize_output(&stderr, &self.props.normalize_stderr);
29512964
let mut errors = 0;
2952-
if !self.props.dont_check_compiler_stdout {
2953-
errors += self.compare_output("stdout", &normalized_stdout, &expected_stdout);
2954-
}
2955-
if !self.props.dont_check_compiler_stderr {
2956-
errors += self.compare_output("stderr", &normalized_stderr, &expected_stderr);
2965+
match output_kind {
2966+
TestOutput::Compile => {
2967+
if !self.props.dont_check_compiler_stdout {
2968+
errors += self.compare_output("stdout", &normalized_stdout, &expected_stdout);
2969+
}
2970+
if !self.props.dont_check_compiler_stderr {
2971+
errors += self.compare_output("stderr", &normalized_stderr, &expected_stderr);
2972+
}
2973+
}
2974+
TestOutput::Run => {
2975+
errors += self.compare_output(stdout_kind, &normalized_stdout, &expected_stdout);
2976+
errors += self.compare_output(stderr_kind, &normalized_stderr, &expected_stderr);
2977+
}
29572978
}
29582979
errors
29592980
}
@@ -2975,14 +2996,7 @@ impl<'test> TestCx<'test> {
29752996
let modes_to_prune = vec![CompareMode::Nll];
29762997
self.prune_duplicate_outputs(&modes_to_prune);
29772998

2978-
// if the user specified to check the results of the
2979-
// run-pass test, delay loading and comparing output
2980-
// until execution of the binary
2981-
let mut errors = if !self.props.check_run_results {
2982-
self.load_compare_outputs(&proc_res, explicit)
2983-
} else {
2984-
0
2985-
};
2999+
let mut errors = self.load_compare_outputs(&proc_res, TestOutput::Compile, explicit);
29863000

29873001
if self.config.compare_mode.is_some() {
29883002
// don't test rustfix with nll right now
@@ -3062,7 +3076,7 @@ impl<'test> TestCx<'test> {
30623076
if self.should_run_successfully() {
30633077
let proc_res = self.exec_compiled_test();
30643078
let run_output_errors = if self.props.check_run_results {
3065-
self.load_compare_outputs(&proc_res, explicit)
3079+
self.load_compare_outputs(&proc_res, TestOutput::Run, explicit)
30663080
} else {
30673081
0
30683082
};

0 commit comments

Comments
 (0)