async-test-attr 0.1.0

A helper macro for attribute generation on async tests
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use proc_macro::TokenStream;
use quote::quote;
use syn::{ItemFn, parse_macro_input};

/// Generates the appropriate async test attribute based on feature flags:
/// - If "tokio" feature is enabled: generates `#[tokio::test]`
/// - If "futures" feature is enabled: generates `#[apply(test!)]`
#[proc_macro_attribute]
pub fn async_test(_attr: TokenStream, item: TokenStream) -> TokenStream {
    let input = parse_macro_input!(item as ItemFn);
    let output = quote! {
        #[cfg_attr(feature = "tokio", tokio::test)]
        #[cfg_attr(all(any(feature = "futures"), not(feature = "tokio")), apply(test!))]
        #input
    };
    output.into()
}