1use proc_macro::TokenStream;
2use quote::quote;
3use syn::{parse_macro_input, spanned::Spanned, AttributeArgs, ItemFn, Meta, NestedMeta};
4
5#[proc_macro_attribute]
6pub fn test(args: TokenStream, item: TokenStream) -> TokenStream {
7 let mut args = parse_macro_input!(args as AttributeArgs);
8 let item = parse_macro_input!(item as ItemFn);
9
10 let init = match args.as_slice() {
11 [NestedMeta::Meta(Meta::Path(init)), ..] => init.clone(),
12 _ => {
13 return syn::Error::new(
14 item.span(),
15 "Must specify an init function as the first argument.",
16 )
17 .to_compile_error()
18 .into()
19 }
20 };
21
22 args.remove(0);
23
24 let ItemFn {
25 attrs,
26 vis,
27 sig,
28 block,
29 } = item;
30
31 quote! {
32 #[::tea_sdk::third::tokio::test(#(#args),*)]
33 #(#attrs)*
34 #vis #sig {
35 ::tea_sdk::actorx::runtime::with_host(#init, async move #block).await
36 }
37 }
38 .into()
39}