Skip to content

Commit 807381b

Browse files
committed
bootstrap/compiletest: implement "crashes" tests that fail if no ice is reproduced
1 parent 1322e07 commit 807381b

File tree

8 files changed

+26
-4
lines changed

8 files changed

+26
-4
lines changed

src/bootstrap/src/core/build_steps/test.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,6 +1374,9 @@ impl Step for RunMakeSupport {
13741374

13751375
default_test!(Ui { path: "tests/ui", mode: "ui", suite: "ui" });
13761376

1377+
default_test!(Crashes { path: "tests/crashes", mode: "crashes", suite: "crashes" });
1378+
1379+
13771380
default_test!(RunPassValgrind {
13781381
path: "tests/run-pass-valgrind",
13791382
mode: "run-pass-valgrind",

src/bootstrap/src/core/builder.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,7 @@ impl<'a> Builder<'a> {
786786
test::ExpandYamlAnchors,
787787
test::Tidy,
788788
test::Ui,
789+
test::Crashes,
789790
test::RunPassValgrind,
790791
test::Coverage,
791792
test::CoverageMap,

src/tools/compiletest/src/common.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ string_enum! {
6969
Assembly => "assembly",
7070
CoverageMap => "coverage-map",
7171
CoverageRun => "coverage-run",
72+
Crashes => "crashes",
7273
}
7374
}
7475

src/tools/compiletest/src/header.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,7 @@ impl TestProps {
625625
fn update_pass_mode(&mut self, ln: &str, revision: Option<&str>, config: &Config) {
626626
let check_no_run = |s| match (config.mode, s) {
627627
(Mode::Ui, _) => (),
628+
(Mode::Crashes, "should-ice") => (),
628629
(Mode::Codegen, "build-pass") => (),
629630
(Mode::Incremental, _) => {
630631
if revision.is_some() && !self.revisions.iter().all(|r| r.starts_with("cfail")) {

src/tools/compiletest/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ pub fn parse_config(args: Vec<String>) -> Config {
6565
"mode",
6666
"which sort of compile tests to run",
6767
"run-pass-valgrind | pretty | debug-info | codegen | rustdoc \
68-
| rustdoc-json | codegen-units | incremental | run-make | ui | js-doc-test | mir-opt | assembly",
68+
| rustdoc-json | codegen-units | incremental | run-make | ui \
69+
| js-doc-test | mir-opt | assembly | crashes",
6970
)
7071
.reqopt(
7172
"",

src/tools/compiletest/src/runtest.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::common::{
44
expected_output_path, UI_EXTENSIONS, UI_FIXED, UI_STDERR, UI_STDOUT, UI_SVG, UI_WINDOWS_SVG,
55
};
66
use crate::common::{incremental_dir, output_base_dir, output_base_name, output_testname_unique};
7-
use crate::common::{Assembly, Incremental, JsDocTest, MirOpt, RunMake, RustdocJson, Ui};
7+
use crate::common::{Assembly, Crashes, Incremental, JsDocTest, MirOpt, RunMake, RustdocJson, Ui};
88
use crate::common::{Codegen, CodegenUnits, DebugInfo, Debugger, Rustdoc};
99
use crate::common::{CompareMode, FailMode, PassMode};
1010
use crate::common::{Config, TestPaths};
@@ -244,7 +244,7 @@ impl<'test> TestCx<'test> {
244244
/// Code executed for each revision in turn (or, if there are no
245245
/// revisions, exactly once, with revision == None).
246246
fn run_revision(&self) {
247-
if self.props.should_ice && self.config.mode != Incremental {
247+
if self.props.should_ice && self.config.mode != Incremental && self.config.mode != Crashes {
248248
self.fatal("cannot use should-ice in a test that is not cfail");
249249
}
250250
match self.config.mode {
@@ -263,6 +263,7 @@ impl<'test> TestCx<'test> {
263263
JsDocTest => self.run_js_doc_test(),
264264
CoverageMap => self.run_coverage_map_test(),
265265
CoverageRun => self.run_coverage_run_test(),
266+
Crashes => self.run_crash_test(),
266267
}
267268
}
268269

@@ -295,6 +296,7 @@ impl<'test> TestCx<'test> {
295296
match self.config.mode {
296297
JsDocTest => true,
297298
Ui => pm.is_some() || self.props.fail_mode > Some(FailMode::Build),
299+
Crashes => false,
298300
Incremental => {
299301
let revision =
300302
self.revision.expect("incremental tests require a list of revisions");
@@ -359,6 +361,17 @@ impl<'test> TestCx<'test> {
359361
self.check_forbid_output(&output_to_check, &proc_res);
360362
}
361363

364+
fn run_crash_test(&self) {
365+
let pm = self.pass_mode();
366+
let proc_res = self.compile_test(WillExecute::No, self.should_emit_metadata(pm));
367+
368+
// if a test does not crash, consider it an error
369+
match proc_res.status.code() {
370+
Some(101) => (),
371+
_ => self.fatal("expected ICE"),
372+
}
373+
}
374+
362375
fn run_rfail_test(&self) {
363376
let pm = self.pass_mode();
364377
let should_run = self.run_if_enabled();
@@ -2499,7 +2512,7 @@ impl<'test> TestCx<'test> {
24992512
rustc.arg("-Cdebug-assertions=no");
25002513
}
25012514
RunPassValgrind | Pretty | DebugInfo | Rustdoc | RustdocJson | RunMake
2502-
| CodegenUnits | JsDocTest => {
2515+
| CodegenUnits | JsDocTest | Crashes => {
25032516
// do not use JSON output
25042517
}
25052518
}

src/tools/opt-dist/src/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ llvm-config = "{llvm_config}"
9696
"tests/pretty",
9797
"tests/run-pass-valgrind",
9898
"tests/ui",
99+
"tests/crases",
99100
];
100101
for test_path in env.skipped_tests() {
101102
args.extend(["--skip", test_path]);

tests/crashes/no-ice.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub fn main() {}

0 commit comments

Comments
 (0)