Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reducing boilerplate with proc macros #81

Closed
tyranron opened this issue Oct 20, 2020 · 3 comments · Fixed by #87
Closed

Reducing boilerplate with proc macros #81

tyranron opened this issue Oct 20, 2020 · 3 comments · Fixed by #87
Assignees
Labels
enhancement Improvement of existing features or bugfix

Comments

@tyranron
Copy link
Member

In our codebase we've built some proc macro machinery, which allows us to reduce boilerplate using this library. An example could've looked something like this:

use std::convert::Infallible;

use async_trait::async_trait;
use cucumber::gherkin::Step;
use cucumber_codegen::given;

#[derive(cucumber_codegen::World)]
pub struct World {
    pub foo: i32,
}

#[async_trait(?Send)]
impl cucumber::World for World {
    type Error = Infallible;

    async fn new() -> Result<Self, Self::Error> {
        Ok(Self { foo: 0 })
    }
}

#[given(regex = r"(\S+) is (\d+)")]
async fn test_regex_async(
    w: &mut World,
    step: String,
    #[given(step)] s: &Step,
    num: usize,
) {
    tokio::time::delay_for(std::time::Duration::new(1, 0)).await;

    assert_eq!(step, "foo");
    assert_eq!(num, 0);
    assert_eq!(s.value, "foo is 0");

    w.foo += 1;
}

#[tokio::main]
async fn main() {
    use cucumber_codegen::WorldInit as _;

    let runner = World::init(&["./features"]);
    runner.run().await;
}

Under-the-hood it uses code generation via proc macros, some additional glue type definitions, and inventory for automatic step assertions registration.

We want to make public that machinery.

Are you interested with adding all of that to this crate? Or should we go with a diffent one?

@bbqsrc
Copy link
Member

bbqsrc commented Oct 20, 2020

I'd be pretty happy to integrate that, sure. 😄

@bbqsrc bbqsrc added the enhancement Improvement of existing features or bugfix label Oct 26, 2020
@bbqsrc bbqsrc changed the title Reducing boilberplate with proc macros Reducing boilerplate with proc macros Nov 9, 2020
@bbqsrc
Copy link
Member

bbqsrc commented Nov 9, 2020

Hey @tyranron, need any assistance with the integration work?

@tyranron
Copy link
Member Author

@bbqsrc nope, thanks. I'm just quite a bit limited in time dedicated to this. Will try to land it this/next week.

tyranron added a commit to tyranron/cucumber-rust that referenced this issue Nov 10, 2020
- add 'cucumber_rust_codegen' sub-crate

Co-authored-by: Ilya Solovyiov <[email protected]>
bbqsrc added a commit that referenced this issue Nov 10, 2020
Steps auto-wiring and proc macros (#81)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvement of existing features or bugfix
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants