Refactor veilid_core::tests::native with macros

This commit is contained in:
Teknique 2023-05-25 15:01:50 -07:00
parent 833bb52e23
commit a74b0cf3b6

View File

@ -33,7 +33,7 @@ pub async fn run_all_tests() {
test_crypto::test_all().await; test_crypto::test_all().await;
info!("TEST: test_envelope_receipt"); info!("TEST: test_envelope_receipt");
test_envelope_receipt::test_all().await; test_envelope_receipt::test_all().await;
info!("TEST: veilid_api::test_serialize"); info!("TEST: veilid_api::tests::test_serialize_rkyv");
veilid_api::tests::test_serialize_rkyv::test_all().await; veilid_api::tests::test_serialize_rkyv::test_all().await;
info!("TEST: routing_table::test_serialize"); info!("TEST: routing_table::test_serialize");
routing_table::tests::test_serialize::test_all().await; routing_table::tests::test_serialize::test_all().await;
@ -59,6 +59,34 @@ cfg_if! {
if #[cfg(test)] { if #[cfg(test)] {
use serial_test::serial; use serial_test::serial;
use std::sync::Once; use std::sync::Once;
use paste::paste;
macro_rules! run_test {
($mod:ident, $func:ident) => {
paste! {
#[test]
#[serial]
fn [<run_ $mod _ $func>]() {
setup();
block_on(async {
$mod::tests::$func::test_all().await;
})
}
}
};
($func:ident) => {
paste! {
#[test]
#[serial]
fn [<run_ $func>]() {
setup();
block_on(async {
$func::test_all().await;
})
}
}
};
}
static SETUP_ONCE: Once = Once::new(); static SETUP_ONCE: Once = Once::new();
@ -81,112 +109,28 @@ cfg_if! {
}); });
} }
#[test] run_test!(test_host_interface);
#[serial]
fn run_test_host_interface() {
setup();
block_on(async {
test_host_interface::test_all().await;
});
}
#[test] run_test!(test_types);
#[serial]
fn run_test_dht_key() {
setup();
block_on(async {
test_types::test_all().await;
});
}
#[test] run_test!(test_veilid_core);
#[serial]
fn run_test_veilid_core() {
setup();
block_on(async {
test_veilid_core::test_all().await;
});
}
#[test] run_test!(test_veilid_config);
#[serial]
fn run_test_veilid_config() {
setup();
block_on(async {
test_veilid_config::test_all().await;
})
}
#[test] run_test!(test_connection_table);
#[serial]
fn run_test_connection_table() {
setup();
block_on(async {
test_connection_table::test_all().await;
})
}
#[test] run_test!(test_signed_node_info);
#[serial]
fn run_test_signed_node_info() {
setup();
block_on(async {
test_signed_node_info::test_all().await;
})
}
#[test] run_test!(test_table_store);
#[serial]
fn run_test_table_store() {
setup();
block_on(async {
test_table_store::test_all().await;
})
}
#[test] run_test!(test_protected_store);
#[serial]
fn run_test_protected_store() {
setup();
block_on(async {
test_protected_store::test_all().await;
})
}
#[test] run_test!(test_crypto);
#[serial]
fn run_test_crypto() {
setup();
block_on(async {
test_crypto::test_all().await;
})
}
#[test] run_test!(test_envelope_receipt);
#[serial]
fn run_test_envelope_receipt() {
setup();
block_on(async {
test_envelope_receipt::test_all().await;
})
}
#[test] run_test!(veilid_api, test_serialize_rkyv);
#[serial]
fn run_test_serialize_rkyv() {
setup();
block_on(async {
veilid_api::tests::test_serialize_rkyv::test_all().await;
})
}
#[test] run_test!(routing_table, test_serialize);
#[serial]
fn run_test_routing_table_serialize() {
setup();
block_on(async {
routing_table::tests::test_serialize::test_all().await;
})
}
} }
} }