From 08a9aa35f21fd3b81ce246cccc5330313cfdffe3 Mon Sep 17 00:00:00 2001 From: ibraheemdev Date: Thu, 6 May 2021 11:57:42 -0400 Subject: [PATCH] add tests for async-test macro --- futures-macro/src/executor.rs | 3 ++- futures/tests/test_macro.rs | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 futures/tests/test_macro.rs diff --git a/futures-macro/src/executor.rs b/futures-macro/src/executor.rs index 48f510ffaa..1efb48c7c7 100644 --- a/futures-macro/src/executor.rs +++ b/futures-macro/src/executor.rs @@ -3,10 +3,11 @@ use quote::quote; pub(crate) fn test(args: TokenStream, item: TokenStream) -> TokenStream { if !args.is_empty() { - return syn::Error::new_spanned(args, "invalid argument")) + return syn::Error::new_spanned(proc_macro2::TokenStream::from(args), "invalid argument") .to_compile_error() .into(); } + let mut input = syn::parse_macro_input!(item as syn::ItemFn); let attrs = &input.attrs; let vis = &input.vis; diff --git a/futures/tests/test_macro.rs b/futures/tests/test_macro.rs new file mode 100644 index 0000000000..4b3b44634e --- /dev/null +++ b/futures/tests/test_macro.rs @@ -0,0 +1,18 @@ +#[cfg(test)] +mod tests { + #[futures_test::test] + async fn it_works() { + let fut = async { true }; + assert!(fut.await); + + let fut = async { false }; + assert!(!fut.await); + } + + #[futures_test::test] + #[should_panic] + async fn it_is_being_run() { + let fut = async { false }; + assert!(fut.await); + } +}