Skip to content

Commit 7b05360

Browse files
committed
bootstrap/compiletest: implement "crashes" tests that fail if no ice is reproduced
1 parent 65ca718 commit 7b05360

8 files changed

Lines changed: 36 additions & 6 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,6 +1400,8 @@ impl Step for RunMakeSupport {
14001400

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

1403+
default_test!(Crashes{ path:"tests/crashes", mode:"crashes", suite:"crashes"});
1404+
14031405
default_test!(RunPassValgrind{
14041406
path:"tests/run-pass-valgrind",
14051407
mode:"run-pass-valgrind",

‎src/bootstrap/src/core/builder.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,7 @@ impl<'a> Builder<'a> {
745745
test::ExpandYamlAnchors,
746746
test::Tidy,
747747
test::Ui,
748+
test::Crashes,
748749
test::RunPassValgrind,
749750
test::Coverage,
750751
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
fnupdate_pass_mode(&mutself,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: 13 additions & 3 deletions
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
"",
@@ -82,7 +83,12 @@ pub fn parse_config(args: Vec<String>) -> Config {
8283
.optopt("","run","whether to execute run-* tests","auto | always | never")
8384
.optflag("","ignored","run tests marked as ignored")
8485
.optflag("","with-debug-assertions","whether to run tests with `ignore-debug` header")
85-
.optmulti("","skip","skip tests matching SUBSTRING. Can be passed multiple times","SUBSTRING")
86+
.optmulti(
87+
"",
88+
"skip",
89+
"skip tests matching SUBSTRING. Can be passed multiple times",
90+
"SUBSTRING",
91+
)
8692
.optflag("","exact","filters match exactly")
8793
.optopt(
8894
"",
@@ -145,7 +151,11 @@ pub fn parse_config(args: Vec<String>) -> Config {
145151
.optflag("","profiler-support","is the profiler runtime enabled for this target")
146152
.optflag("h","help","show this message")
147153
.reqopt("","channel","current Rust channel","CHANNEL")
148-
.optflag("","git-hash","run tests which rely on commit version being compiled into the binaries")
154+
.optflag(
155+
"",
156+
"git-hash",
157+
"run tests which rely on commit version being compiled into the binaries",
158+
)
149159
.optopt("","edition","default Rust edition","EDITION")
150160
.reqopt("","git-repository","name of the git repository","ORG/REPO")
151161
.reqopt("","nightly-branch","name of the git branch for nightly","BRANCH");

‎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
usecrate::common::{incremental_dir, output_base_dir, output_base_name, output_testname_unique};
7-
usecrate::common::{Assembly,Incremental,JsDocTest,MirOpt,RunMake,RustdocJson,Ui};
7+
usecrate::common::{Assembly,Crashes,Incremental,JsDocTest,MirOpt,RunMake,RustdocJson,Ui};
88
usecrate::common::{Codegen,CodegenUnits,DebugInfo,Debugger,Rustdoc};
99
usecrate::common::{CompareMode,FailMode,PassMode};
1010
usecrate::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
fnrun_revision(&self){
247-
ifself.props.should_ice && self.config.mode != Incremental{
247+
ifself.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
matchself.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
matchself.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+
fnrun_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
fnrun_rfail_test(&self){
363376
let pm = self.pass_mode();
364377
let should_run = self.run_if_enabled();
@@ -2517,7 +2530,7 @@ impl<'test> TestCx<'test> {
25172530
rustc.arg("-Cdebug-assertions=no");
25182531
}
25192532
RunPassValgrind | Pretty | DebugInfo | Rustdoc | RustdocJson | RunMake
2520-
| CodegenUnits | JsDocTest => {
2533+
| CodegenUnits | JsDocTest| Crashes=> {
25212534
// do not use JSON output
25222535
}
25232536
}

‎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+
pubfnmain(){}

0 commit comments

Comments
 (0)