cucumber-rs / cucumber

Cucumber testing framework for Rust. Fully native, no external test runners or dependencies.
https://cucumber-rs.github.io/cucumber/main
Apache License 2.0
563 stars 69 forks source link

Externally defined steps not included in binary #304

Closed yds12 closed 11 months ago

yds12 commented 11 months ago

I have a kinda complicated setup, so it would be hard to provide a minimal reproducible version, but I'll try to describe it.

In summary, I have a wrapper around cucumber, and various crates that define their own steps, using this wrapper for the World implementation. This most of the time works fine, and I'm able to create a runner crate that uses all of those crates, and use the steps defined on them, but in some occasions, which I could not fully identify, I noticed that the steps are simply not included in the compiled binary. I get the step doesn't match any function error.

There was one occasion where compiling in release or debug mode would yield different results: one of them had the steps, the other didn't (I don't recall which was which, but I'd assume it could happen that the release mode compilation removed the steps as an optimization?).

I inspected the binary using unix's string utility (parts of strings used in the step names should be visible in the binary as they are static), but could not find any trace of those steps.

I suspect this has to do with the way steps are registered via the inventory crate. That crate says something about calls to collect! being in the same crate that defines the plugin type. Not sure if this is the issue here.

Just opening this to raise awareness of this issue, I cannot easily reproduce it, it just happens in certain situations involving multiple crates defining steps.

tyranron commented 11 months ago

@yds12 this is something we're dependent on inventory for. Not sure, we can do something about it from our side, because the way we're using inventory is quite trivial, no shenanigans at all.

Can you also specify at which platform does this happen?

Also, try codegen-units = 1 for this, it has helped us many times with inventory.

yds12 commented 11 months ago

Hi @tyranron, thanks for the reply. I have only observed this bug in MacOS (Ventura). I'll try your suggestion later today and let you know in case it works.

yds12 commented 11 months ago

The suggestion to use codegen-units = 1 solved the issue for me. Thank you!

tyranron commented 11 months ago

Closing this, as resolving it is up to upstream: https://github.com/dtolnay/inventory/issues/52