fluence_sdk_test_macro_impl/fce_test/fce_test_impl.rs
1/*
2 * Copyright 2021 Fluence Labs Limited
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17use crate::attributes::FCETestAttributes;
18use crate::TResult;
19use crate::fce_test::glue_code_generator::generate_test_glue_code;
20
21use proc_macro2::TokenStream;
22use darling::FromMeta;
23use syn::parse::Parser;
24
25pub fn fce_test_impl(attrs: TokenStream, input: TokenStream) -> TResult<TokenStream> {
26 // from https://github.com/dtolnay/syn/issues/788
27 let parser = syn::punctuated::Punctuated::<syn::NestedMeta, syn::Token![,]>::parse_terminated;
28 let attrs = parser.parse2(attrs)?;
29 let attrs: Vec<syn::NestedMeta> = attrs.into_iter().collect();
30 let attrs = FCETestAttributes::from_list(&attrs)?;
31
32 let func_item = syn::parse2::<syn::ItemFn>(input)?;
33
34 generate_test_glue_code(func_item, attrs)
35}