| [package] | |
| name = "my-crate" | |
| version = "0.1.0" | |
| edition = "2018" | |
| [lib] | |
| proc-macro = true | |
| path = 'lib.rs' | |
| [[test]] | |
| name = 'smoke' | |
| path = 'test.rs' | |
| [dependencies] | |
| syn = { version = "0.15.23", features = ["full"] } | |
| quote = "0.6.10" | |
| [dev-dependencies] | |
| env_logger = "0.6.0" | |
| log = "0.4.6" |
| extern crate proc_macro; | |
| use proc_macro::TokenStream; | |
| #[proc_macro_attribute] | |
| pub fn my_test(_attr: TokenStream, item: TokenStream) -> TokenStream { | |
| let f = syn::parse_macro_input!(item as syn::ItemFn); | |
| let attrs = &f.attrs; | |
| let ident = &f.ident; | |
| let block = &f.block; | |
| (quote::quote! { | |
| #(#attrs)* | |
| #[test] | |
| fn #ident() { | |
| drop(env_logger::try_init()); | |
| #block | |
| } | |
| }).into() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment