Skip to content

Commit 0b2e908

Browse files
committed
Add support for --run for non-ui tests
1 parent 0978381 commit 0b2e908

File tree

2 files changed

+43
-22
lines changed

2 files changed

+43
-22
lines changed

src/bootstrap/flags.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -294,12 +294,7 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`",
294294
"force {check,build,run}-pass tests to this mode.",
295295
"check | build | run",
296296
);
297-
opts.optopt(
298-
"",
299-
"run",
300-
"whether to execute run-* tests",
301-
"auto | always | never",
302-
);
297+
opts.optopt("", "run", "whether to execute run-* tests", "auto | always | never");
303298
opts.optflag(
304299
"",
305300
"rustfix-coverage",

src/tools/compiletest/src/runtest.rs

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -359,22 +359,20 @@ impl<'test> TestCx<'test> {
359359

360360
fn should_run(&self, pm: Option<PassMode>) -> WillExecute {
361361
let test_should_run = match self.config.mode {
362-
Ui if pm == Some(PassMode::Run) || self.props.fail_mode == Some(FailMode::Run) => {
363-
true
364-
}
362+
Ui if pm == Some(PassMode::Run) || self.props.fail_mode == Some(FailMode::Run) => true,
365363
MirOpt if pm == Some(PassMode::Run) => true,
366364
Ui | MirOpt => false,
367365
mode => panic!("unimplemented for mode {:?}", mode),
368366
};
367+
if test_should_run { self.run_if_enabled() } else { WillExecute::No }
368+
}
369+
370+
fn run_if_enabled(&self) -> WillExecute {
369371
let enabled = self.config.run.unwrap_or_else(|| {
370372
// Auto-detect whether to run based on the platform.
371373
!self.config.target.ends_with("-fuchsia")
372374
});
373-
match (test_should_run, enabled) {
374-
(false, _) => WillExecute::No,
375-
(true, true) => WillExecute::Yes,
376-
(true, false) => WillExecute::Disabled,
377-
}
375+
if enabled { WillExecute::Yes } else { WillExecute::Disabled }
378376
}
379377

380378
fn should_run_successfully(&self, pm: Option<PassMode>) -> bool {
@@ -449,12 +447,17 @@ impl<'test> TestCx<'test> {
449447

450448
fn run_rfail_test(&self) {
451449
let pm = self.pass_mode();
452-
let proc_res = self.compile_test(WillExecute::Yes, self.should_emit_metadata(pm));
450+
let should_run = self.run_if_enabled();
451+
let proc_res = self.compile_test(should_run, self.should_emit_metadata(pm));
453452

454453
if !proc_res.status.success() {
455454
self.fatal_proc_rec("compilation failed!", &proc_res);
456455
}
457456

457+
if let WillExecute::Disabled = should_run {
458+
return;
459+
}
460+
458461
let proc_res = self.exec_compiled_test();
459462

460463
// The value our Makefile configures valgrind to return on failure
@@ -493,12 +496,17 @@ impl<'test> TestCx<'test> {
493496

494497
fn run_rpass_test(&self) {
495498
let emit_metadata = self.should_emit_metadata(self.pass_mode());
496-
let proc_res = self.compile_test(WillExecute::Yes, emit_metadata);
499+
let should_run = self.run_if_enabled();
500+
let proc_res = self.compile_test(should_run, emit_metadata);
497501

498502
if !proc_res.status.success() {
499503
self.fatal_proc_rec("compilation failed!", &proc_res);
500504
}
501505

506+
if let WillExecute::Disabled = should_run {
507+
return;
508+
}
509+
502510
// FIXME(#41968): Move this check to tidy?
503511
let expected_errors = errors::load_errors(&self.testpaths.file, self.revision);
504512
assert!(
@@ -520,12 +528,17 @@ impl<'test> TestCx<'test> {
520528
return self.run_rpass_test();
521529
}
522530

523-
let mut proc_res = self.compile_test(WillExecute::Yes, EmitMetadata::No);
531+
let should_run = self.run_if_enabled();
532+
let mut proc_res = self.compile_test(should_run, EmitMetadata::No);
524533

525534
if !proc_res.status.success() {
526535
self.fatal_proc_rec("compilation failed!", &proc_res);
527536
}
528537

538+
if let WillExecute::Disabled = should_run {
539+
return;
540+
}
541+
529542
let mut new_config = self.config.clone();
530543
new_config.runtool = new_config.valgrind_path.clone();
531544
let new_cx = TestCx { config: &new_config, ..*self };
@@ -742,10 +755,14 @@ impl<'test> TestCx<'test> {
742755

743756
fn run_debuginfo_cdb_test_no_opt(&self) {
744757
// compile test file (it should have 'compile-flags:-g' in the header)
745-
let compile_result = self.compile_test(WillExecute::Yes, EmitMetadata::No);
758+
let should_run = self.run_if_enabled();
759+
let compile_result = self.compile_test(should_run, EmitMetadata::No);
746760
if !compile_result.status.success() {
747761
self.fatal_proc_rec("compilation failed!", &compile_result);
748762
}
763+
if let WillExecute::Disabled = should_run {
764+
return;
765+
}
749766

750767
let exe_file = self.make_exe_name();
751768

@@ -836,10 +853,14 @@ impl<'test> TestCx<'test> {
836853
let mut cmds = commands.join("\n");
837854

838855
// compile test file (it should have 'compile-flags:-g' in the header)
839-
let compiler_run_result = self.compile_test(WillExecute::Yes, EmitMetadata::No);
856+
let should_run = self.run_if_enabled();
857+
let compiler_run_result = self.compile_test(should_run, EmitMetadata::No);
840858
if !compiler_run_result.status.success() {
841859
self.fatal_proc_rec("compilation failed!", &compiler_run_result);
842860
}
861+
if let WillExecute::Disabled = should_run {
862+
return;
863+
}
843864

844865
let exe_file = self.make_exe_name();
845866

@@ -1054,10 +1075,14 @@ impl<'test> TestCx<'test> {
10541075

10551076
fn run_debuginfo_lldb_test_no_opt(&self) {
10561077
// compile test file (it should have 'compile-flags:-g' in the header)
1057-
let compile_result = self.compile_test(WillExecute::Yes, EmitMetadata::No);
1078+
let should_run = self.run_if_enabled();
1079+
let compile_result = self.compile_test(should_run, EmitMetadata::No);
10581080
if !compile_result.status.success() {
10591081
self.fatal_proc_rec("compilation failed!", &compile_result);
10601082
}
1083+
if let WillExecute::Disabled = should_run {
1084+
return;
1085+
}
10611086

10621087
let exe_file = self.make_exe_name();
10631088

@@ -1541,8 +1566,9 @@ impl<'test> TestCx<'test> {
15411566
// Only use `make_exe_name` when the test ends up being executed.
15421567
let output_file = match will_execute {
15431568
WillExecute::Yes => TargetLocation::ThisFile(self.make_exe_name()),
1544-
WillExecute::No | WillExecute::Disabled =>
1545-
TargetLocation::ThisDirectory(self.output_base_dir()),
1569+
WillExecute::No | WillExecute::Disabled => {
1570+
TargetLocation::ThisDirectory(self.output_base_dir())
1571+
}
15461572
};
15471573

15481574
let allow_unused = match self.config.mode {

0 commit comments

Comments
 (0)