Add --run flag to compiletest

This controls whether run-* tests actually get run.
This commit is contained in:
Tyler Mandry 2021-04-24 01:20:48 +00:00
parent bb491ed239
commit 051f9ec694
3 changed files with 26 additions and 5 deletions

View file

@ -249,6 +249,9 @@ pub struct Config {
/// Force the pass mode of a check/build/run-pass test to this mode. /// Force the pass mode of a check/build/run-pass test to this mode.
pub force_pass_mode: Option<PassMode>, pub force_pass_mode: Option<PassMode>,
/// Explicitly enable or disable running.
pub run: Option<bool>,
/// Write out a parseable log of tests that were run /// Write out a parseable log of tests that were run
pub logfile: Option<PathBuf>, pub logfile: Option<PathBuf>,

View file

@ -87,6 +87,7 @@ pub fn parse_config(args: Vec<String>) -> Config {
"force {check,build,run}-pass tests to this mode.", "force {check,build,run}-pass tests to this mode.",
"check | build | run", "check | build | run",
) )
.optopt("", "run", "whether to execute run-* tests", "auto | always | never")
.optflag("", "ignored", "run tests marked as ignored") .optflag("", "ignored", "run tests marked as ignored")
.optflag("", "exact", "filters match exactly") .optflag("", "exact", "filters match exactly")
.optopt( .optopt(
@ -234,6 +235,12 @@ pub fn parse_config(args: Vec<String>) -> Config {
mode.parse::<PassMode>() mode.parse::<PassMode>()
.unwrap_or_else(|_| panic!("unknown `--pass` option `{}` given", mode)) .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)), logfile: matches.opt_str("logfile").map(|s| PathBuf::from(&s)),
runtool: matches.opt_str("runtool"), runtool: matches.opt_str("runtool"),
host_rustcflags: matches.opt_str("host-rustcflags"), host_rustcflags: matches.opt_str("host-rustcflags"),

View file

@ -317,6 +317,7 @@ enum TestOutput {
enum WillExecute { enum WillExecute {
Yes, Yes,
No, No,
Disabled,
} }
/// Should `--emit metadata` be used? /// Should `--emit metadata` be used?
@ -357,13 +358,22 @@ impl<'test> TestCx<'test> {
} }
fn should_run(&self, pm: Option<PassMode>) -> WillExecute { fn should_run(&self, pm: Option<PassMode>) -> 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) => { Ui if pm == Some(PassMode::Run) || self.props.fail_mode == Some(FailMode::Run) => {
WillExecute::Yes true
} }
MirOpt if pm == Some(PassMode::Run) => WillExecute::Yes, MirOpt if pm == Some(PassMode::Run) => true,
Ui | MirOpt => WillExecute::No, Ui | MirOpt => false,
mode => panic!("unimplemented for mode {:?}", mode), 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. // Only use `make_exe_name` when the test ends up being executed.
let output_file = match will_execute { let output_file = match will_execute {
WillExecute::Yes => TargetLocation::ThisFile(self.make_exe_name()), 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 { let allow_unused = match self.config.mode {