use std::str::FromStr;
use structopt;
#[derive(StructOpt, Debug, Clone)]
#[structopt(
template = "USAGE: [FLAGS] [OPTIONS] [FILTER]\n\n{all-args}\n\n\n{after-help}",
setting = structopt::clap::AppSettings::DisableVersion,
after_help = "By default, all tests are run in parallel. This can be altered with the \n\
--test-threads flag or the RUST_TEST_THREADS environment variable when running \n\
tests (set it to 1).\n\
\n\
All tests have their standard output and standard error captured by default. \n\
This can be overridden with the --nocapture flag or setting RUST_TEST_NOCAPTURE \n\
environment variable to a value other than \"0\". Logging is not captured by default.",
)]
pub struct Arguments {
#[structopt(long = "--ignored", help = "Run ignored tests")]
pub ignored: bool,
#[structopt(
long = "--test",
conflicts_with = "bench",
help = "Run tests and not benchmarks",
)]
pub test: bool,
#[structopt(long = "--bench", help = "Run benchmarks instead of tests")]
pub bench: bool,
#[structopt(long = "--list", help = "List all tests and benchmarks")]
pub list: bool,
#[structopt(
long = "--nocapture",
help = "don't capture stdout/stderr of each task, allow printing directly",
)]
pub nocapture: bool,
#[structopt(
long = "--exact",
help = "Exactly match filters rather than by substring",
)]
pub exact: bool,
#[structopt(
short = "q",
long = "--quiet",
conflicts_with = "format",
help = "Display one character per test instead of one line. Alias to --format=terse",
)]
pub quiet: bool,
#[structopt(
long = "--test-threads",
help = "Number of threads used for running tests in parallel",
)]
pub num_threads: Option<usize>,
#[structopt(
long = "--logfile",
value_name = "PATH",
help = "Write logs to the specified file instead of stdout",
)]
pub logfile: Option<String>,
#[structopt(
long = "--skip",
value_name = "FILTER",
number_of_values = 1,
help = "Skip tests whose names contain FILTER (this flag can be used multiple times)",
)]
pub skip: Vec<String>,
#[structopt(
long = "--color",
possible_values = &["auto", "always", "never"],
value_name = "auto|always|never",
help = "Configure coloring of output: \n\
- auto = colorize if stdout is a tty and tests are run on serially (default)\n\
- always = always colorize output\n\
- never = never colorize output\n",
)]
pub color: Option<ColorSetting>,
#[structopt(
long = "--format",
possible_values = &["pretty", "terse", "json"],
value_name = "pretty|terse|json",
help = "Configure formatting of output: \n\
- pretty = Print verbose output\n\
- terse = Display one character per test\n\
- json = Output a json document\n",
)]
pub format: Option<FormatSetting>,
#[structopt(
name = "FILTER",
help = "The FILTER string is tested against the name of all tests, and only those tests \
whose names contain the filter are run.",
)]
pub filter_string: Option<String>,
}
impl Arguments {
pub fn from_args() -> Self {
structopt::StructOpt::from_args()
}
pub fn from_iter<I>(iter: I) -> Self
where
Self: Sized,
I: IntoIterator,
I::Item: Into<std::ffi::OsString> + Clone,
{
structopt::StructOpt::from_iter(iter)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ColorSetting {
Auto,
Always,
Never,
}
impl Default for ColorSetting {
fn default() -> Self {
ColorSetting::Auto
}
}
impl FromStr for ColorSetting {
type Err = &'static str;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"auto" => Ok(ColorSetting::Auto),
"always" => Ok(ColorSetting::Always),
"never" => Ok(ColorSetting::Never),
_ => Err("foo"),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FormatSetting {
Pretty,
Terse,
Json,
}
impl Default for FormatSetting {
fn default() -> Self {
FormatSetting::Pretty
}
}
impl FromStr for FormatSetting {
type Err = &'static str;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"pretty" => Ok(FormatSetting::Pretty),
"terse" => Ok(FormatSetting::Terse),
"json" => Ok(FormatSetting::Json),
_ => Err("foo"),
}
}
}