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 proc_macro2::TokenStream as TokenStream2;
17
18/// The End-to-End test with all required information.
19pub struct InkE2ETest {
20    /// The function which was annotated.
21    pub item_fn: E2EFn,
22    /// The specified configuration.
23    pub config: E2EConfig,
24}
25
26/// The End-to-End test with all required information.
27#[derive(derive_more::From)]
28pub struct E2EFn {
29    /// The function which was annotated.
30    pub item_fn: syn::ItemFn,
31}
32
33impl InkE2ETest {
34    /// Returns `Ok` if the test matches all requirements for an
35    /// ink! E2E test definition.
36    pub fn new(attrs: TokenStream2, input: TokenStream2) -> Result<Self, syn::Error> {
37        let e2e_config = E2EConfig::from_attr_tokens(attrs)?;
38        let item_fn = syn::parse2::<syn::ItemFn>(input)?;
39        let e2e_fn = E2EFn::from(item_fn);
40        Ok(Self {
41            item_fn: e2e_fn,
42            config: e2e_config,
43        })
44    }
45}