Browse Source

add list, run cli flags to integration tests.
fixes: #338

abhijeetbhagat 2 years ago
parent
commit
5b3e0ee856
2 changed files with 52 additions and 6 deletions
  1. 2 1
      test/integration-test/Cargo.toml
  2. 50 5
      test/integration-test/src/main.rs

+ 2 - 1
test/integration-test/Cargo.toml

@@ -7,6 +7,8 @@ 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"
@@ -14,4 +16,3 @@ 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"

+ 50 - 5
test/integration-test/src/main.rs

@@ -3,14 +3,59 @@ use log::info;
 mod tests;
 use tests::IntegrationTest;
 
+use clap::Parser;
+#[derive(Debug, Parser)]
+pub struct RunOptions {
+    #[clap(short, long, value_parser)]
+    tests: Option<Vec<String>>,
+}
+
+#[derive(Debug, Parser)]
+struct Options {
+    #[clap(subcommand)]
+    command: Command,
+}
+
+#[derive(Debug, Parser)]
+enum Command {
+    /// Run one or more tests: ... -- run -t test1 -t test2
+    Run(RunOptions),
+    /// List all the tests: ... -- list
+    List
+}
+
 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 cmd = Command::parse();
+
+    match cmd {
+        Command::Run(opts) => {
+            match opts.tests {
+                Some(tests) => {
+                    for t in inventory::iter::<IntegrationTest> {
+                        if tests.contains(&t.name.into()) {
+                            info!("Running {}", t.name);
+                            if let Err(e) = (t.test_fn)() {
+                                panic!("{}", e)
+                            }
+                        }
+                    }
+                }
+                None => {
+                    for t in inventory::iter::<IntegrationTest> {
+                        info!("Running {}", t.name);
+                        if let Err(e) = (t.test_fn)() {
+                            panic!("{}", e)
+                        }
+                    }
+                }
+            }
+        }
+        Command::List => {
+            for t in inventory::iter::<IntegrationTest> {
+                info!("{}", t.name);
+            }
         }
     }