From 638cf514fb62d4b14f5d9756be95212bf3258cda Mon Sep 17 00:00:00 2001 From: abhijeetbhagat Date: Tue, 11 Oct 2022 13:32:41 +0530 Subject: [PATCH] use macro to log, execute test and handle error --- test/integration-test/src/main.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/test/integration-test/src/main.rs b/test/integration-test/src/main.rs index a61bf088..b2ad10be 100644 --- a/test/integration-test/src/main.rs +++ b/test/integration-test/src/main.rs @@ -24,6 +24,15 @@ enum Command { List } +macro_rules! exec_test { + ($test:expr) => {{ + info!("Running {}", $test.name); + if let Err(e) = ($test.test_fn)() { + panic!("{}", e) + } + }}; +} + fn main() -> anyhow::Result<()> { env_logger::init(); @@ -35,19 +44,13 @@ fn main() -> anyhow::Result<()> { Some(tests) => { for t in inventory::iter:: { if tests.contains(&t.name.into()) { - info!("Running {}", t.name); - if let Err(e) = (t.test_fn)() { - panic!("{}", e) - } + exec_test!(t) } } } None => { for t in inventory::iter:: { - info!("Running {}", t.name); - if let Err(e) = (t.test_fn)() { - panic!("{}", e) - } + exec_test!(t) } } }