-
Notifications
You must be signed in to change notification settings - Fork 71
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
Wrap event::Cucumber in Event to allow metadata #145
Conversation
# Conflicts: # src/parser/basic.rs # src/writer/basic.rs # src/writer/normalized.rs
FCM
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ilslv I think we can go with a better design. Ping me tomorrow to discuss this in a talk.
src/runner/basic.rs
Outdated
LocalBoxStream<'static, parser::Result<event::Cucumber<W>>>; | ||
type EventStream = LocalBoxStream< | ||
'static, | ||
(parser::Result<event::Cucumber<W>>, DateTime<Utc>), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO, this is not very good decision, now we have the code base polluted with those tuples and signatures became worse.
I see here two ways:
- Attach
DateTime
directly toevent
s types and errors. - Instead of
(T, DateTime)
pairs haveDateTimed<T>
wrapper, which encapsulates the stuff and provides obvious interface to inner values.
With the option 2, we will need to only change type signatures, without touching any code. Furthermore, this way we can hide it completely behind a feature gate, so it can be used only for those Writer
s which really need it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Attach DateTime directly to events types and errors.
As all events are nested enums, we'll have to put DateTime
in every variant of the Cucumber
event
pub enum Cucumber<World> {
/// [`Cucumber`] execution being started.
Started(DateTime<Utc>),
/// [`Feature`] event.
Feature(DateTime<Utc>, Arc<gherkin::Feature>, Feature<World>),
/// [`Cucumber`] execution being finished.
Finished(DateTime<Utc>),
}
Matching over it will be very painful.
Instead of (T, DateTime) pairs have DateTimed wrapper, which encapsulates the stuff and provides obvious interface to inner values.
👍
With the option 2, we will need to only change type signatures, without touching any code.
Not really, especially in case of writer::Normalized
. There we store only event::Step
and path to it: Feature
, Option<Rule>
, Scenario
. Then we rebuild it with Cucumber::scenario(feat, rule, sc, ev)
when it's time to emit it. But it's pretty easy to store DateTime
s of those events and already done in this PR.
Furthermore, this way we can hide it completely behind a feature gate, so it can be used only for those Writers which really need it.
I'm not sure we should. This will cause Writer
trait to be different in cases when feature is on or off (same for Runner
)
pub trait Writer<World> {
type Cli: StructOptInternal;
async fn handle_event(
&mut self,
ev: parser::Result<event::Cucumber<World>>,
#[cfg(feature = "event_datetime")] // I don't think it's pleasant API to use
at: DateTime<Utc>,
cli: &Self::Cli,
);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A little bit of bikesheddings, but generally, that's it!
@ilslv good job 👍
Synopsis
Despite there is no use for it now, it can become useful later. For example in implementation of
JUnit
Writer
.Solution
Pair
DateTime
with everyCucumber
event to avoid breakingAPI
in the future.Checklist
Draft:
prefixDraft:
prefix is removedThis PR is nominated at RU RustCon Contest