From 0b2e908691a2d5d35ebd877a2c3339b230b81eb0 Mon Sep 17 00:00:00 2001 From: Tyler Mandry Date: Thu, 29 Apr 2021 00:13:56 +0000 Subject: [PATCH] Add support for --run for non-ui tests --- src/bootstrap/flags.rs | 7 +--- src/tools/compiletest/src/runtest.rs | 58 ++++++++++++++++++++-------- 2 files changed, 43 insertions(+), 22 deletions(-) diff --git a/src/bootstrap/flags.rs b/src/bootstrap/flags.rs index 13d11cded303a..dd1e48a14684f 100644 --- a/src/bootstrap/flags.rs +++ b/src/bootstrap/flags.rs @@ -294,12 +294,7 @@ To learn more about a subcommand, run `./x.py -h`", "force {check,build,run}-pass tests to this mode.", "check | build | run", ); - opts.optopt( - "", - "run", - "whether to execute run-* tests", - "auto | always | never", - ); + opts.optopt("", "run", "whether to execute run-* tests", "auto | always | never"); opts.optflag( "", "rustfix-coverage", diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index c758b977573ae..a044c4425b4e6 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -359,22 +359,20 @@ impl<'test> TestCx<'test> { fn should_run(&self, pm: Option) -> WillExecute { let test_should_run = match self.config.mode { - Ui if pm == Some(PassMode::Run) || self.props.fail_mode == Some(FailMode::Run) => { - true - } + Ui if pm == Some(PassMode::Run) || self.props.fail_mode == Some(FailMode::Run) => true, MirOpt if pm == Some(PassMode::Run) => true, Ui | MirOpt => false, mode => panic!("unimplemented for mode {:?}", mode), }; + if test_should_run { self.run_if_enabled() } else { WillExecute::No } + } + + fn run_if_enabled(&self) -> WillExecute { let enabled = self.config.run.unwrap_or_else(|| { // Auto-detect whether to run based on the platform. !self.config.target.ends_with("-fuchsia") }); - match (test_should_run, enabled) { - (false, _) => WillExecute::No, - (true, true) => WillExecute::Yes, - (true, false) => WillExecute::Disabled, - } + if enabled { WillExecute::Yes } else { WillExecute::Disabled } } fn should_run_successfully(&self, pm: Option) -> bool { @@ -449,12 +447,17 @@ impl<'test> TestCx<'test> { fn run_rfail_test(&self) { let pm = self.pass_mode(); - let proc_res = self.compile_test(WillExecute::Yes, self.should_emit_metadata(pm)); + let should_run = self.run_if_enabled(); + let proc_res = self.compile_test(should_run, self.should_emit_metadata(pm)); if !proc_res.status.success() { self.fatal_proc_rec("compilation failed!", &proc_res); } + if let WillExecute::Disabled = should_run { + return; + } + let proc_res = self.exec_compiled_test(); // The value our Makefile configures valgrind to return on failure @@ -493,12 +496,17 @@ impl<'test> TestCx<'test> { fn run_rpass_test(&self) { let emit_metadata = self.should_emit_metadata(self.pass_mode()); - let proc_res = self.compile_test(WillExecute::Yes, emit_metadata); + let should_run = self.run_if_enabled(); + let proc_res = self.compile_test(should_run, emit_metadata); if !proc_res.status.success() { self.fatal_proc_rec("compilation failed!", &proc_res); } + if let WillExecute::Disabled = should_run { + return; + } + // FIXME(#41968): Move this check to tidy? let expected_errors = errors::load_errors(&self.testpaths.file, self.revision); assert!( @@ -520,12 +528,17 @@ impl<'test> TestCx<'test> { return self.run_rpass_test(); } - let mut proc_res = self.compile_test(WillExecute::Yes, EmitMetadata::No); + let should_run = self.run_if_enabled(); + let mut proc_res = self.compile_test(should_run, EmitMetadata::No); if !proc_res.status.success() { self.fatal_proc_rec("compilation failed!", &proc_res); } + if let WillExecute::Disabled = should_run { + return; + } + let mut new_config = self.config.clone(); new_config.runtool = new_config.valgrind_path.clone(); let new_cx = TestCx { config: &new_config, ..*self }; @@ -742,10 +755,14 @@ impl<'test> TestCx<'test> { fn run_debuginfo_cdb_test_no_opt(&self) { // compile test file (it should have 'compile-flags:-g' in the header) - let compile_result = self.compile_test(WillExecute::Yes, EmitMetadata::No); + let should_run = self.run_if_enabled(); + let compile_result = self.compile_test(should_run, EmitMetadata::No); if !compile_result.status.success() { self.fatal_proc_rec("compilation failed!", &compile_result); } + if let WillExecute::Disabled = should_run { + return; + } let exe_file = self.make_exe_name(); @@ -836,10 +853,14 @@ impl<'test> TestCx<'test> { let mut cmds = commands.join("\n"); // compile test file (it should have 'compile-flags:-g' in the header) - let compiler_run_result = self.compile_test(WillExecute::Yes, EmitMetadata::No); + let should_run = self.run_if_enabled(); + let compiler_run_result = self.compile_test(should_run, EmitMetadata::No); if !compiler_run_result.status.success() { self.fatal_proc_rec("compilation failed!", &compiler_run_result); } + if let WillExecute::Disabled = should_run { + return; + } let exe_file = self.make_exe_name(); @@ -1054,10 +1075,14 @@ impl<'test> TestCx<'test> { fn run_debuginfo_lldb_test_no_opt(&self) { // compile test file (it should have 'compile-flags:-g' in the header) - let compile_result = self.compile_test(WillExecute::Yes, EmitMetadata::No); + let should_run = self.run_if_enabled(); + let compile_result = self.compile_test(should_run, EmitMetadata::No); if !compile_result.status.success() { self.fatal_proc_rec("compilation failed!", &compile_result); } + if let WillExecute::Disabled = should_run { + return; + } let exe_file = self.make_exe_name(); @@ -1541,8 +1566,9 @@ impl<'test> TestCx<'test> { // Only use `make_exe_name` when the test ends up being executed. let output_file = match will_execute { WillExecute::Yes => TargetLocation::ThisFile(self.make_exe_name()), - WillExecute::No | WillExecute::Disabled => - TargetLocation::ThisDirectory(self.output_base_dir()), + WillExecute::No | WillExecute::Disabled => { + TargetLocation::ThisDirectory(self.output_base_dir()) + } }; let allow_unused = match self.config.mode {