main.rs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. use log::info;
  2. mod tests;
  3. use tests::IntegrationTest;
  4. use clap::Parser;
  5. #[derive(Debug, Parser)]
  6. #[clap(author, version, about, long_about = None)]
  7. #[clap(propagate_version = true)]
  8. pub struct RunOptions {
  9. #[clap(short, long, value_parser)]
  10. tests: Option<Vec<String>>,
  11. }
  12. #[derive(Debug, Parser)]
  13. struct Cli {
  14. #[clap(subcommand)]
  15. command: Option<Command>,
  16. }
  17. #[derive(Debug, Parser)]
  18. enum Command {
  19. /// Run one or more tests: ... -- run -t test1 -t test2
  20. Run(RunOptions),
  21. /// List all the tests: ... -- list
  22. List,
  23. }
  24. macro_rules! exec_test {
  25. ($test:expr) => {{
  26. info!("Running {}", $test.name);
  27. ($test.test_fn)();
  28. }};
  29. }
  30. macro_rules! exec_all_tests {
  31. () => {{
  32. for t in inventory::iter::<IntegrationTest> {
  33. exec_test!(t)
  34. }
  35. }};
  36. }
  37. fn main() -> anyhow::Result<()> {
  38. env_logger::init();
  39. let cli = Cli::parse();
  40. match &cli.command {
  41. Some(Command::Run(opts)) => match &opts.tests {
  42. Some(tests) => {
  43. for t in inventory::iter::<IntegrationTest> {
  44. if tests.contains(&t.name.into()) {
  45. exec_test!(t)
  46. }
  47. }
  48. }
  49. None => {
  50. exec_all_tests!()
  51. }
  52. },
  53. Some(Command::List) => {
  54. for t in inventory::iter::<IntegrationTest> {
  55. info!("{}", t.name);
  56. }
  57. }
  58. None => {
  59. exec_all_tests!()
  60. }
  61. }
  62. Ok(())
  63. }