Emit code for a wrapper function around a test function.
(inner_test: &TokenStream2, wrappee: &ItemFn)
| 70 | |
| 71 | /// Emit code for a wrapper function around a test function. |
| 72 | fn expand_wrapper(inner_test: &TokenStream2, wrappee: &ItemFn) -> TokenStream { |
| 73 | let attrs = &wrappee.attrs; |
| 74 | let async_ = &wrappee.sig.asyncness; |
| 75 | let await_ = if async_.is_some() { |
| 76 | quote! {.await} |
| 77 | } else { |
| 78 | quote! {} |
| 79 | }; |
| 80 | let body = &wrappee.block; |
| 81 | let test_name = &wrappee.sig.ident; |
| 82 | |
| 83 | // Note that Rust does not allow us to have a test function with |
| 84 | // #[should_panic] that has a non-unit return value. |
| 85 | let ret = match &wrappee.sig.output { |
| 86 | ReturnType::Default => quote! {}, |
| 87 | ReturnType::Type(_, type_) => quote! {-> #type_}, |
| 88 | }; |
| 89 | |
| 90 | let logging_init = expand_logging_init(); |
| 91 | |
| 92 | let result = quote! { |
| 93 | #[#inner_test] |
| 94 | #(#attrs)* |
| 95 | #async_ fn #test_name() #ret { |
| 96 | #async_ fn test_impl() #ret { |
| 97 | #body |
| 98 | } |
| 99 | |
| 100 | #logging_init |
| 101 | |
| 102 | test_impl()#await_ |
| 103 | } |
| 104 | }; |
| 105 | result.into() |
| 106 | } |
no test coverage detected