Allow test functions to return results
@@ -109,6 +109,12 @@ fn test_each_connector_async_wrapper_functions(
quote! { .with_subscriber(test_setup::logging::test_tracing_subscriber(#log_config)) }
});
+ let optional_unwrap = if function_returns_result(&test_function) {
+ Some(quote!(.unwrap()))
+ } else {
+ None
+ };
+
for connector in args.connectors_to_test() {
let connector_test_fn_name = Ident::new(&format!("{}_on_{}", test_fn_name, connector), Span::call_site());
let connector_api_factory = Ident::new(&format!("{}_test_api", connector), Span::call_site());
@@ -120,7 +126,7 @@ fn test_each_connector_async_wrapper_functions(
let fut = async {
let api = #connector_api_factory(#test_fn_name_str).await;
- #test_fn_name(&api).await
+ #test_fn_name(&api).await#optional_unwrap
}#optional_logging;
test_setup::runtime::run_with_tokio(fut)
@@ -148,6 +154,11 @@ pub fn test_one_connector(attr: TokenStream, input: TokenStream) -> TokenStream
Span::call_site(),
);
let api_factory = Ident::new(&format!("{}_test_api", args.connector), Span::call_site());
+ let optional_unwrap = if function_returns_result(&test_function) {
+ Some(quote!(.unwrap()))
+ } else {
+ None
+ };
let output = if async_test {
let optional_logging = args.log.as_ref().map(|log_config| {
@@ -161,7 +172,7 @@ pub fn test_one_connector(attr: TokenStream, input: TokenStream) -> TokenStream
let fut = async {
let api = #api_factory(#test_impl_name_str).await;
- #test_impl_name(&api)#optional_logging.await
+ #test_impl_name(&api)#optional_logging.await#optional_unwrap
};
test_setup::runtime::run_with_tokio(fut)
@@ -184,3 +195,11 @@ pub fn test_one_connector(attr: TokenStream, input: TokenStream) -> TokenStream
output.into()
}
+
+fn function_returns_result(func: &ItemFn) -> bool {
+ match func.sig.output {
+ syn::ReturnType::Default => false,
+ // just assume it's a result
+ syn::ReturnType::Type(_, _) => true,
+ }
+}
