From 051f9ec694ec8c173b551d674cd17b8b989a9ee8 Mon Sep 17 00:00:00 2001 From: Tyler Mandry Date: Sat, 24 Apr 2021 01:20:48 +0000 Subject: [PATCH] Add --run flag to compiletest This controls whether run-* tests actually get run. --- src/tools/compiletest/src/common.rs | 3 +++ src/tools/compiletest/src/main.rs | 7 +++++++ src/tools/compiletest/src/runtest.rs | 21 ++++++++++++++++----- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/tools/compiletest/src/common.rs b/src/tools/compiletest/src/common.rs index b7693a3cb143..9a2166675d8a 100644 --- a/src/tools/compiletest/src/common.rs +++ b/src/tools/compiletest/src/common.rs @@ -249,6 +249,9 @@ pub struct Config { /// Force the pass mode of a check/build/run-pass test to this mode. pub force_pass_mode: Option, + /// Explicitly enable or disable running. + pub run: Option, + /// Write out a parseable log of tests that were run pub logfile: Option, diff --git a/src/tools/compiletest/src/main.rs b/src/tools/compiletest/src/main.rs index 480916018619..5bf1b55e45b4 100644 --- a/src/tools/compiletest/src/main.rs +++ b/src/tools/compiletest/src/main.rs @@ -87,6 +87,7 @@ pub fn parse_config(args: Vec) -> Config { "force {check,build,run}-pass tests to this mode.", "check | build | run", ) + .optopt("", "run", "whether to execute run-* tests", "auto | always | never") .optflag("", "ignored", "run tests marked as ignored") .optflag("", "exact", "filters match exactly") .optopt( @@ -234,6 +235,12 @@ pub fn parse_config(args: Vec) -> Config { mode.parse::() .unwrap_or_else(|_| panic!("unknown `--pass` option `{}` given", mode)) }), + run: matches.opt_str("run").and_then(|mode| match mode.as_str() { + "auto" => None, + "always" => Some(true), + "never" => Some(false), + _ => panic!("unknown `--run` option `{}` given", mode), + }), logfile: matches.opt_str("logfile").map(|s| PathBuf::from(&s)), runtool: matches.opt_str("runtool"), host_rustcflags: matches.opt_str("host-rustcflags"), diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index ecbaccf744dc..c758b977573a 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -317,6 +317,7 @@ enum TestOutput { enum WillExecute { Yes, No, + Disabled, } /// Should `--emit metadata` be used? @@ -357,13 +358,22 @@ impl<'test> TestCx<'test> { } fn should_run(&self, pm: Option) -> WillExecute { - match self.config.mode { + let test_should_run = match self.config.mode { Ui if pm == Some(PassMode::Run) || self.props.fail_mode == Some(FailMode::Run) => { - WillExecute::Yes + true } - MirOpt if pm == Some(PassMode::Run) => WillExecute::Yes, - Ui | MirOpt => WillExecute::No, + MirOpt if pm == Some(PassMode::Run) => true, + Ui | MirOpt => false, mode => panic!("unimplemented for mode {:?}", mode), + }; + 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, } } @@ -1531,7 +1541,8 @@ 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 => TargetLocation::ThisDirectory(self.output_base_dir()), + WillExecute::No | WillExecute::Disabled => + TargetLocation::ThisDirectory(self.output_base_dir()), }; let allow_unused = match self.config.mode {