test-setup: macro rules based test setup macro
easier on the compiler
less intrusive
@@ -27,6 +27,43 @@ pub use test_api_args::{DatasourceBlock, TestApiArgs};
type AnyError = Box<dyn std::error::Error + Send + Sync + 'static>;
+#[macro_export]
+macro_rules! only {
+ ($($tag:ident),* $(;)?) => {
+ only!($($tag,)* ; exclude: )
+ };
+
+ ($($tag:ident),* ; exclude: $($excludeTag:ident),*) => {
+ {
+ let (skip, db) = only_impl(
+ enumflags2::bitflags!($($tag |)*),
+ enumflags2::bitflag!($($excludeTag |)*)
+ );
+ if skip { return }
+ db
+ }
+ };
+}
+
+pub struct TestDb(&'static test_api_args::DbUnderTest);
+
+#[doc(hidden)]
+#[inline(never)]
+pub fn only_impl(include_tagged: BitFlags<Tags>, exclude_tags: BitFlags<Tags>) -> (bool, TestDb) {
+ let db = TestDb(test_api_args::db_under_test());
+ if !include_tagged.intersects(db.0.tags) {
+ println!("Test skipped");
+ return (true, db);
+ }
+
+ if exclude_tags.intersects(db.0.tags) {
+ println!("Test skipped");
+ return (true, db);
+ }
+
+ (false, db)
+}
+
#[inline(never)]
pub fn should_skip_test(
include_tagged: BitFlags<Tags>,
