mirror of https://github.com/aya-rs/aya
tests: use libtest-mimic and fix CI
parent
27f22f205d
commit
34e040b8e9
@ -1,74 +1,21 @@
|
|||||||
use log::info;
|
use libtest_mimic::{Arguments, Trial};
|
||||||
|
|
||||||
mod tests;
|
mod tests;
|
||||||
use tests::IntegrationTest;
|
use tests::IntegrationTest;
|
||||||
|
|
||||||
use clap::Parser;
|
fn main() {
|
||||||
|
|
||||||
#[derive(Debug, Parser)]
|
|
||||||
#[clap(author, version, about, long_about = None)]
|
|
||||||
#[clap(propagate_version = true)]
|
|
||||||
pub struct RunOptions {
|
|
||||||
#[clap(short, long, value_parser)]
|
|
||||||
tests: Option<Vec<String>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Parser)]
|
|
||||||
struct Cli {
|
|
||||||
#[clap(subcommand)]
|
|
||||||
command: Option<Command>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Parser)]
|
|
||||||
enum Command {
|
|
||||||
/// Run one or more tests: ... -- run -t test1 -t test2
|
|
||||||
Run(RunOptions),
|
|
||||||
/// List all the tests: ... -- list
|
|
||||||
List,
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! exec_test {
|
|
||||||
($test:expr) => {{
|
|
||||||
info!("Running {}", $test.name);
|
|
||||||
($test.test_fn)();
|
|
||||||
}};
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! exec_all_tests {
|
|
||||||
() => {{
|
|
||||||
for t in inventory::iter::<IntegrationTest> {
|
|
||||||
exec_test!(t)
|
|
||||||
}
|
|
||||||
}};
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() -> anyhow::Result<()> {
|
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
|
let mut args = Arguments::from_args();
|
||||||
let cli = Cli::parse();
|
// Force to run single-threaded
|
||||||
|
args.test_threads = Some(1);
|
||||||
match &cli.command {
|
let tests = inventory::iter::<IntegrationTest>
|
||||||
Some(Command::Run(opts)) => match &opts.tests {
|
.into_iter()
|
||||||
Some(tests) => {
|
.map(|test| {
|
||||||
for t in inventory::iter::<IntegrationTest> {
|
Trial::test(test.name, move || {
|
||||||
if tests.contains(&t.name.into()) {
|
(test.test_fn)();
|
||||||
exec_test!(t)
|
Ok(())
|
||||||
}
|
})
|
||||||
}
|
})
|
||||||
}
|
.collect();
|
||||||
None => {
|
libtest_mimic::run(&args, tests).exit();
|
||||||
exec_all_tests!()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Some(Command::List) => {
|
|
||||||
for t in inventory::iter::<IntegrationTest> {
|
|
||||||
info!("{}", t.name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
exec_all_tests!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue