Skip to content

Commit

Permalink
Rollup merge of rust-lang#131642 - jieyouxu:build-fail-check-fail, r=…
Browse files Browse the repository at this point in the history
…Kobzol

Special case error message for a `build-fail` test that failed check build

A `build-fail` test requires that a check build (roughly `--emit=metadata`, no codegen) succeeds but fails later. Previously, if its check build failed, the user will see the error message

```
error: test compilation failed although it shouldn't!
```

which is confusing. Because the test is `build-fail`, we want the test compilation to fail! This error message doesn't account for the difference between a check build and a complete build, so let's special case the error message for a `build-fail` test whose check build failed to instead say

```
error: `build-fail` test is required to pass check build, but check build failed
```

Fixes rust-lang#130894.
  • Loading branch information
matthiaskrgr authored Oct 13, 2024
2 parents 84dd8cd + 40ca4d8 commit 0fa7101
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
25 changes: 22 additions & 3 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,10 +318,29 @@ impl<'test> TestCx<'test> {
}
}

fn check_if_test_should_compile(&self, proc_res: &ProcRes, pm: Option<PassMode>) {
if self.should_compile_successfully(pm) {
fn check_if_test_should_compile(
&self,
fail_mode: Option<FailMode>,
pass_mode: Option<PassMode>,
proc_res: &ProcRes,
) {
if self.should_compile_successfully(pass_mode) {
if !proc_res.status.success() {
self.fatal_proc_rec("test compilation failed although it shouldn't!", proc_res);
match (fail_mode, pass_mode) {
(Some(FailMode::Build), Some(PassMode::Check)) => {
// A `build-fail` test needs to `check-pass`.
self.fatal_proc_rec(
"`build-fail` test is required to pass check build, but check build failed",
proc_res,
);
}
_ => {
self.fatal_proc_rec(
"test compilation failed although it shouldn't!",
proc_res,
);
}
}
}
} else {
if proc_res.status.success() {
Expand Down
4 changes: 2 additions & 2 deletions src/tools/compiletest/src/runtest/incremental.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{TestCx, WillExecute};
use super::{FailMode, TestCx, WillExecute};
use crate::errors;

impl TestCx<'_> {
Expand Down Expand Up @@ -96,7 +96,7 @@ impl TestCx<'_> {
fn run_cfail_test(&self) {
let pm = self.pass_mode();
let proc_res = self.compile_test(WillExecute::No, self.should_emit_metadata(pm));
self.check_if_test_should_compile(&proc_res, pm);
self.check_if_test_should_compile(Some(FailMode::Build), pm, &proc_res);
self.check_no_compiler_crash(&proc_res, self.props.should_ice);

let output_to_check = self.get_output(&proc_res);
Expand Down
4 changes: 2 additions & 2 deletions src/tools/compiletest/src/runtest/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ impl TestCx<'_> {
let pm = Some(PassMode::Check);
let proc_res =
self.compile_test_general(WillExecute::No, Emit::Metadata, pm, Vec::new());
self.check_if_test_should_compile(&proc_res, pm);
self.check_if_test_should_compile(self.props.fail_mode, pm, &proc_res);
}

let pm = self.pass_mode();
let should_run = self.should_run(pm);
let emit_metadata = self.should_emit_metadata(pm);
let proc_res = self.compile_test(should_run, emit_metadata);
self.check_if_test_should_compile(&proc_res, pm);
self.check_if_test_should_compile(self.props.fail_mode, pm, &proc_res);
if matches!(proc_res.truncated, Truncated::Yes)
&& !self.props.dont_check_compiler_stdout
&& !self.props.dont_check_compiler_stderr
Expand Down

0 comments on commit 0fa7101

Please sign in to comment.