Step Analysis / Code Generation #208
Replies: 1 comment 8 replies
-
Yes, this is certainly a good idea. I was also thinking about this as a long term goal. There are (and probably there will be) cases where dynamic binding would be required, but still, I think vast majority of the step-calls are static. When I was thinking about this, my imagined solution was to generate a code that first verifies if dynamic binding is needed (this can be a quick check, for most of the projects as simple as "return false") and if not, than move on with the statically generated stuff. Nevertheless I am not sure I fully understand the technical solution you summarized. Could you maybe demonstrate this with some simple pseudo-code (ie. what the user needs to do and what do we generate compile time) though a concrete example? |
Beta Was this translation helpful? Give feedback.
-
Because I like to juggle multiple parallel things, and inspired by similar static analysis available for Microsoft's logging system, I thought I would look into adding a Roslyn analyser for Reqnroll steps. Specifically, something that would look at the attributes assigned to a step and verify:
But then I also got thinking: why are we compiling step bindings at runtime when we could be doing that at compile-time? This is how the new compile-time Regular Expression support works, turning a partial method decorated with an attribute into a complete implementation of a regular expression. Likewise, we could turn every step binding attribute into a compiled member that can match and invoke the step.
This means we'd have:
There's overlap here; any validation performed by a static analyzer would be somewhat redundant if a code-generator was also going to repeat that work, but both could exist side-by-side.
What would it take to achieve an analyzer?
What would it take to achieve code-generation?
Does this seem useful? I certainly like moving runtime concerns to compile-time concerns wherever possible and this seems like a pretty good candidate. The only thing that might make it undesirable is if we eventually wanted to abandon step discovery at runtime completely - make it so we can only bind to steps that are discoverable at runtime so that feature code generation would match feature steps to step definitions at compile-time and add direct invocation. There's a lot of drawbacks and challenges to doing so (can't use dynamically loaded assemblies, data-sources have to be available at compile-time, etc), but I know the idea has been brought up as potentially being a long-term goal.
Beta Was this translation helpful? Give feedback.
All reactions