ink_e2e_macro/ir.rs
1// Copyright (C) Use Ink (UK) Ltd.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use crate::config::E2EConfig;
16use darling::{
17 ast::NestedMeta,
18 FromMeta,
19};
20use proc_macro2::TokenStream as TokenStream2;
21
22/// The End-to-End test with all required information.
23pub struct InkE2ETest {
24 /// The function which was annotated.
25 pub item_fn: E2EFn,
26 /// The specified configuration.
27 pub config: E2EConfig,
28}
29
30/// The End-to-End test with all required information.
31#[derive(derive_more::From)]
32pub struct E2EFn {
33 /// The function which was annotated.
34 pub item_fn: syn::ItemFn,
35}
36
37impl InkE2ETest {
38 /// Returns `Ok` if the test matches all requirements for an
39 /// ink! E2E test definition.
40 pub fn new(attrs: TokenStream2, input: TokenStream2) -> Result<Self, syn::Error> {
41 let e2e_config = E2EConfig::from_list(&NestedMeta::parse_meta_list(attrs)?)?;
42 let item_fn = syn::parse2::<syn::ItemFn>(input)?;
43 let e2e_fn = E2EFn::from(item_fn);
44 Ok(Self {
45 item_fn: e2e_fn,
46 config: e2e_config,
47 })
48 }
49}