use anyhow::{Context, Result};
use clap::Parser;
use tarantool_runner::Cli as RunnerCli;
use tarantool_test::{TestsConfig, DEFAULT_TEST_ENTRYPOINT_NAME};
#[derive(Parser)]
#[command(author, version, about, long_about = None)]
struct Cli {
#[arg(
short,
long,
help = r#"Path to the package where tests would be executed. Package must follow the rules established in the `tarantool-runner` utility."#
)]
path: String,
#[arg(
short,
long,
help = r#"An explicit entrypoint name to use. If not specified, default test entrypoint name is used."#
)]
entrypoint: Option<String>,
#[arg(
short,
long,
help = "Filter out needed tests by passing their fullname or even part of the name."
)]
filter: Option<String>,
#[arg(
last = true,
help = r#"An OPTIONAL `tarantool-runner` override parameters. You must not use `-e`, `-p` and input(`--`) here, as they are used internally by tarantool-test."#
)]
runner_overrides: Option<Vec<String>>,
}
fn process_test_command(args: Cli) -> Result<()> {
let setup_config = TestsConfig {
filter: args.filter,
};
let serialized_config = serde_json::to_string(&setup_config)
.with_context(|| "failed to serialize test config to json")?;
let entrypoint = args
.entrypoint
.as_deref()
.unwrap_or(DEFAULT_TEST_ENTRYPOINT_NAME);
let runner_arguments = ["", "run", "-e", entrypoint, "-p", args.path.as_str()];
let runner_overrides = args.runner_overrides.unwrap_or_default();
let runner_overrides = runner_overrides.iter().map(|params| params.as_str());
let runner_input = ["--", &serialized_config];
let runner_arguments = runner_arguments
.into_iter()
.chain(runner_overrides)
.chain(runner_input);
let runner = RunnerCli::try_parse_from(runner_arguments)?;
runner.process_command()?;
Ok(())
}
fn main() -> Result<()> {
let cli = Cli::parse();
process_test_command(cli)?;
Ok(())
}