use clap::{Parser, ValueEnum};
#[derive(Parser, Debug, Clone, Default)]
#[command(
help_template = "USAGE: [OPTIONS] [FILTER]\n\n{all-args}\n\n\n{after-help}",
disable_version_flag = true,
after_help = "By default, all tests are run in parallel. This can be altered with the \n\
--test-threads flag when running tests (set it to 1).",
)]
pub struct Arguments {
#[arg(long = "include-ignored", help = "Run ignored tests")]
pub include_ignored: bool,
#[arg(long = "ignored", help = "Run ignored tests")]
pub ignored: bool,
#[arg(
long = "test",
conflicts_with = "bench",
help = "Run tests and not benchmarks",
)]
pub test: bool,
#[arg(long = "bench", help = "Run benchmarks instead of tests")]
pub bench: bool,
#[arg(long = "list", help = "List all tests and benchmarks")]
pub list: bool,
#[arg(long = "nocapture", help = "No-op (libtest-mimic always runs in no-capture mode)")]
pub nocapture: bool,
#[arg(long = "show-output")]
pub show_output: bool,
#[arg(short = 'Z')]
pub unstable_flags: Option<UnstableFlags>,
#[arg(
long = "exact",
help = "Exactly match filters rather than by substring",
)]
pub exact: bool,
#[arg(
short = 'q',
long = "quiet",
conflicts_with = "format",
help = "Display one character per test instead of one line. Alias to --format=terse",
)]
pub quiet: bool,
#[arg(
long = "test-threads",
help = "Number of threads used for running tests in parallel. If set to 1, \n\
all tests are run in the main thread.",
)]
pub test_threads: Option<usize>,
#[arg(
long = "logfile",
value_name = "PATH",
help = "Write logs to the specified file instead of stdout",
)]
pub logfile: Option<String>,
#[arg(
long = "skip",
value_name = "FILTER",
help = "Skip tests whose names contain FILTER (this flag can be used multiple times)",
)]
pub skip: Vec<String>,
#[arg(
long = "color",
value_enum,
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>,
#[arg(
long = "format",
value_enum,
value_name = "pretty|terse|json",
help = "Configure formatting of output: \n\
- pretty = Print verbose output\n\
- terse = Display one character per test\n\
- json = Print json events\n",
)]
pub format: Option<FormatSetting>,
#[arg(
value_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: Option<String>,
}
impl Arguments {
pub fn from_args() -> Self {
Parser::parse()
}
pub fn from_iter<I>(iter: I) -> Self
where
Self: Sized,
I: IntoIterator,
I::Item: Into<std::ffi::OsString> + Clone,
{
Parser::parse_from(iter)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
pub enum ColorSetting {
Auto,
Always,
Never,
}
impl Default for ColorSetting {
fn default() -> Self {
ColorSetting::Auto
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
pub enum UnstableFlags {
UnstableOptions,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
pub enum FormatSetting {
Pretty,
Terse,
Json,
}
impl Default for FormatSetting {
fn default() -> Self {
FormatSetting::Pretty
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn verify_cli() {
use clap::CommandFactory;
Arguments::command().debug_assert();
}
}