reduce boilerplate with common enums
This commit is contained in:
parent
9bc8bb91de
commit
0aaf9d58a2
@ -12,59 +12,45 @@ use lazycell::LazyCell;
|
||||
use std::collections::HashSet;
|
||||
use test::{ColorConfig, OutputFormat};
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Debug)]
|
||||
pub enum Mode {
|
||||
RunPassValgrind,
|
||||
Pretty,
|
||||
DebugInfo,
|
||||
Codegen,
|
||||
Rustdoc,
|
||||
RustdocJson,
|
||||
CodegenUnits,
|
||||
Incremental,
|
||||
RunMake,
|
||||
Ui,
|
||||
JsDocTest,
|
||||
MirOpt,
|
||||
Assembly,
|
||||
macro_rules! string_enum {
|
||||
($(#[$meta:meta])* $vis:vis enum $name:ident { $($variant:ident => $repr:expr,)* }) => {
|
||||
$(#[$meta])*
|
||||
$vis enum $name {
|
||||
$($variant,)*
|
||||
}
|
||||
|
||||
impl Mode {
|
||||
pub fn disambiguator(self) -> &'static str {
|
||||
// Pretty-printing tests could run concurrently, and if they do,
|
||||
// they need to keep their output segregated.
|
||||
impl $name {
|
||||
$vis const VARIANTS: &'static [Self] = &[$(Self::$variant,)*];
|
||||
|
||||
$vis fn to_str(&self) -> &'static str {
|
||||
match self {
|
||||
Pretty => ".pretty",
|
||||
_ => "",
|
||||
$(Self::$variant => $repr,)*
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for Mode {
|
||||
impl fmt::Display for $name {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
fmt::Display::fmt(self.to_str(), f)
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for $name {
|
||||
type Err = ();
|
||||
fn from_str(s: &str) -> Result<Mode, ()> {
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, ()> {
|
||||
match s {
|
||||
"run-pass-valgrind" => Ok(RunPassValgrind),
|
||||
"pretty" => Ok(Pretty),
|
||||
"debuginfo" => Ok(DebugInfo),
|
||||
"codegen" => Ok(Codegen),
|
||||
"rustdoc" => Ok(Rustdoc),
|
||||
"rustdoc-json" => Ok(RustdocJson),
|
||||
"codegen-units" => Ok(CodegenUnits),
|
||||
"incremental" => Ok(Incremental),
|
||||
"run-make" => Ok(RunMake),
|
||||
"ui" => Ok(Ui),
|
||||
"js-doc-test" => Ok(JsDocTest),
|
||||
"mir-opt" => Ok(MirOpt),
|
||||
"assembly" => Ok(Assembly),
|
||||
$($repr => Ok(Self::$variant),)*
|
||||
_ => Err(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Mode {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let s = match *self {
|
||||
string_enum! {
|
||||
#[derive(Clone, Copy, PartialEq, Debug)]
|
||||
pub enum Mode {
|
||||
RunPassValgrind => "run-pass-valgrind",
|
||||
Pretty => "pretty",
|
||||
DebugInfo => "debuginfo",
|
||||
@ -78,38 +64,26 @@ impl fmt::Display for Mode {
|
||||
JsDocTest => "js-doc-test",
|
||||
MirOpt => "mir-opt",
|
||||
Assembly => "assembly",
|
||||
};
|
||||
fmt::Display::fmt(s, f)
|
||||
}
|
||||
}
|
||||
|
||||
impl Mode {
|
||||
pub fn disambiguator(self) -> &'static str {
|
||||
// Pretty-printing tests could run concurrently, and if they do,
|
||||
// they need to keep their output segregated.
|
||||
match self {
|
||||
Pretty => ".pretty",
|
||||
_ => "",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string_enum! {
|
||||
#[derive(Clone, Copy, PartialEq, Debug, Hash)]
|
||||
pub enum PassMode {
|
||||
Check,
|
||||
Build,
|
||||
Run,
|
||||
}
|
||||
|
||||
impl FromStr for PassMode {
|
||||
type Err = ();
|
||||
fn from_str(s: &str) -> Result<Self, ()> {
|
||||
match s {
|
||||
"check" => Ok(PassMode::Check),
|
||||
"build" => Ok(PassMode::Build),
|
||||
"run" => Ok(PassMode::Run),
|
||||
_ => Err(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for PassMode {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let s = match *self {
|
||||
PassMode::Check => "check",
|
||||
PassMode::Build => "build",
|
||||
PassMode::Run => "run",
|
||||
};
|
||||
fmt::Display::fmt(s, f)
|
||||
Check => "check",
|
||||
Build => "build",
|
||||
Run => "run",
|
||||
}
|
||||
}
|
||||
|
||||
@ -120,69 +94,23 @@ pub enum FailMode {
|
||||
Run,
|
||||
}
|
||||
|
||||
string_enum! {
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum CompareMode {
|
||||
Polonius,
|
||||
Chalk,
|
||||
NextSolver,
|
||||
SplitDwarf,
|
||||
SplitDwarfSingle,
|
||||
}
|
||||
|
||||
impl CompareMode {
|
||||
pub(crate) const VARIANTS: &'static [CompareMode] = &[
|
||||
CompareMode::Polonius,
|
||||
CompareMode::Chalk,
|
||||
CompareMode::NextSolver,
|
||||
CompareMode::SplitDwarf,
|
||||
CompareMode::SplitDwarfSingle,
|
||||
];
|
||||
|
||||
pub(crate) fn to_str(&self) -> &'static str {
|
||||
match *self {
|
||||
CompareMode::Polonius => "polonius",
|
||||
CompareMode::Chalk => "chalk",
|
||||
CompareMode::NextSolver => "next-solver",
|
||||
CompareMode::SplitDwarf => "split-dwarf",
|
||||
CompareMode::SplitDwarfSingle => "split-dwarf-single",
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse(s: String) -> CompareMode {
|
||||
match s.as_str() {
|
||||
"polonius" => CompareMode::Polonius,
|
||||
"chalk" => CompareMode::Chalk,
|
||||
"next-solver" => CompareMode::NextSolver,
|
||||
"split-dwarf" => CompareMode::SplitDwarf,
|
||||
"split-dwarf-single" => CompareMode::SplitDwarfSingle,
|
||||
x => panic!("unknown --compare-mode option: {}", x),
|
||||
}
|
||||
Polonius => "polonius",
|
||||
Chalk => "chalk",
|
||||
NextSolver => "next-solver",
|
||||
SplitDwarf => "split-dwarf",
|
||||
SplitDwarfSingle => "split-dwarf-single",
|
||||
}
|
||||
}
|
||||
|
||||
string_enum! {
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub enum Debugger {
|
||||
Cdb,
|
||||
Gdb,
|
||||
Lldb,
|
||||
}
|
||||
|
||||
impl Debugger {
|
||||
pub(crate) const VARIANTS: &'static [Debugger] =
|
||||
&[Debugger::Cdb, Debugger::Gdb, Debugger::Lldb];
|
||||
|
||||
pub(crate) fn to_str(&self) -> &'static str {
|
||||
match self {
|
||||
Debugger::Cdb => "cdb",
|
||||
Debugger::Gdb => "gdb",
|
||||
Debugger::Lldb => "lldb",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Debugger {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
fmt::Display::fmt(self.to_str(), f)
|
||||
Cdb => "cdb",
|
||||
Gdb => "gdb",
|
||||
Lldb => "lldb",
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
extern crate test;
|
||||
|
||||
use crate::common::{expected_output_path, output_base_dir, output_relative_path, UI_EXTENSIONS};
|
||||
use crate::common::{CompareMode, Config, Debugger, Mode, PassMode, TestPaths};
|
||||
use crate::common::{Config, Debugger, Mode, PassMode, TestPaths};
|
||||
use crate::util::logv;
|
||||
use build_helper::git::{get_git_modified_files, get_git_untracked_files};
|
||||
use core::panic;
|
||||
@ -293,7 +293,9 @@ pub fn parse_config(args: Vec<String>) -> Config {
|
||||
only_modified: matches.opt_present("only-modified"),
|
||||
color,
|
||||
remote_test_client: matches.opt_str("remote-test-client").map(PathBuf::from),
|
||||
compare_mode: matches.opt_str("compare-mode").map(CompareMode::parse),
|
||||
compare_mode: matches
|
||||
.opt_str("compare-mode")
|
||||
.map(|s| s.parse().expect("invalid --compare-mode provided")),
|
||||
rustfix_coverage: matches.opt_present("rustfix-coverage"),
|
||||
has_tidy,
|
||||
channel: matches.opt_str("channel").unwrap(),
|
||||
|
Loading…
x
Reference in New Issue
Block a user