Skip to content

Commit

Permalink
Merge pull request aya-rs#409 from abhijeetbhagat/integration-tests-c…
Browse files Browse the repository at this point in the history
…li-options

add list, run cli flags to integration tests.
  • Loading branch information
dave-tucker authored Oct 13, 2022
2 parents 77c5543 + c83d012 commit a0b0399
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 6 deletions.
3 changes: 2 additions & 1 deletion test/integration-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ publish = false
[dependencies]
anyhow = "1"
aya = { path = "../../aya" }
clap = { version = "3", features = ["derive"] }
env_logger = "0.9"
inventory = "0.2"
integration-test-macros = { path = "../integration-test-macros" }
lazy_static = "1"
libc = { version = "0.2.105" }
log = "0.4"
object = { version = "0.29", default-features = false, features = ["std", "read_core", "elf"] }
regex = "1"
env_logger = "0.9"
68 changes: 63 additions & 5 deletions test/integration-test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,72 @@ use log::info;
mod tests;
use tests::IntegrationTest;

use clap::Parser;

#[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);
if let Err(e) = ($test.test_fn)() {
panic!("{}", e)
}
}};
}

macro_rules! exec_all_tests {
() => {{
for t in inventory::iter::<IntegrationTest> {
exec_test!(t)
}
}};
}

fn main() -> anyhow::Result<()> {
env_logger::init();

// Run the tests
for t in inventory::iter::<IntegrationTest> {
info!("Running {}", t.name);
if let Err(e) = (t.test_fn)() {
panic!("{}", e)
let cli = Cli::parse();

match &cli.command {
Some(Command::Run(opts)) => match &opts.tests {
Some(tests) => {
for t in inventory::iter::<IntegrationTest> {
if tests.contains(&t.name.into()) {
exec_test!(t)
}
}
}
None => {
exec_all_tests!()
}
},
Some(Command::List) => {
for t in inventory::iter::<IntegrationTest> {
info!("{}", t.name);
}
}
None => {
exec_all_tests!()
}
}

Expand Down

0 comments on commit a0b0399

Please sign in to comment.