From 6ffe7fecbf3e2b01bd8c554caad3dfa349448f21 Mon Sep 17 00:00:00 2001 From: Rafael Bachmann Date: Tue, 14 Nov 2023 23:32:38 +0100 Subject: [PATCH 1/6] Run RustFmt --- src/writer/summarize.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/writer/summarize.rs b/src/writer/summarize.rs index 9d492ef5..01ae744c 100644 --- a/src/writer/summarize.rs +++ b/src/writer/summarize.rs @@ -541,7 +541,7 @@ impl Summarize { /// // `Writer`s pipeline is constructed in a reversed order. /// writer::Basic::stdout() // And, finally, print them. /// .summarized() // Only then, count summary for them. -/// .fail_on_skipped() // First, transform skipped steps to failed. +/// .fail_on_skipped(), // First, transform skipped steps to failed. /// ) /// .run_and_exit("tests/features/readme") /// .await; From f73ee798fcc3f164d1556b99812f7615c43b7a7e Mon Sep 17 00:00:00 2001 From: Rafael Bachmann Date: Tue, 14 Nov 2023 23:33:02 +0100 Subject: [PATCH 2/6] Format Cargo.toml --- Cargo.toml | 50 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5f92a35d..fed28fa3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,17 @@ repository = "https://github.com/cucumber-rs/cucumber" readme = "README.md" categories = ["asynchronous", "development-tools::testing"] keywords = ["cucumber", "testing", "bdd", "atdd", "async"] -include = ["/src/", "/tests/json.rs", "/tests/junit.rs", "/tests/libtest.rs", "/tests/tracing.rs", "/tests/wait.rs", "/LICENSE-*", "/README.md", "/CHANGELOG.md"] +include = [ + "/src/", + "/tests/json.rs", + "/tests/junit.rs", + "/tests/libtest.rs", + "/tests/tracing.rs", + "/tests/wait.rs", + "/LICENSE-*", + "/README.md", + "/CHANGELOG.md", +] [package.metadata.docs.rs] all-features = true @@ -30,9 +40,21 @@ default = ["macros"] # Enables compatibility with Rust libtest (like outputting in its JSON format). libtest = ["dep:serde", "dep:serde_json", "timestamps"] # Enables step attributes and auto-wiring. -macros = ["dep:anyhow", "dep:cucumber-codegen", "dep:cucumber-expressions", "dep:inventory"] +macros = [ + "dep:anyhow", + "dep:cucumber-codegen", + "dep:cucumber-expressions", + "dep:inventory", +] # Enables support for outputting in Cucumber JSON format. -output-json = ["dep:base64", "dep:Inflector", "dep:mime", "dep:serde", "dep:serde_json", "timestamps"] +output-json = [ + "dep:base64", + "dep:Inflector", + "dep:mime", + "dep:serde", + "dep:serde_json", + "timestamps", +] # Enables support for outputting JUnit XML report. output-junit = ["dep:junit-report", "timestamps"] # Enables timestamps collecting for all events. @@ -44,7 +66,16 @@ tracing = ["dep:crossbeam-utils", "dep:tracing", "dep:tracing-subscriber"] async-trait = "0.1.43" clap = { version = "4.3.2", features = ["derive", "wrap_help"] } console = "0.15" -derive_more = { version = "0.99.17", features = ["as_ref", "deref", "deref_mut", "display", "error", "from", "from_str", "into"], default_features = false } +derive_more = { version = "0.99.17", features = [ + "as_ref", + "deref", + "deref_mut", + "display", + "error", + "from", + "from_str", + "into", +], default_features = false } drain_filter_polyfill = "0.1.2" either = "1.6" futures = "0.3.17" @@ -63,7 +94,9 @@ smart-default = "0.7.1" # "macros" feature dependencies. anyhow = { version = "1.0.58", optional = true } cucumber-codegen = { version = "0.20.1", path = "./codegen", optional = true } -cucumber-expressions = { version = "0.3", features = ["into-regex"], optional = true } +cucumber-expressions = { version = "0.3", features = [ + "into-regex", +], optional = true } inventory = { version = "0.3", optional = true } # "output-json" and/or "libtest" features dependencies. @@ -85,7 +118,12 @@ tracing-subscriber = { version = "0.3.16", optional = true } derive_more = "0.99.17" rand = "0.8" tempfile = "3.2" -tokio = { version = "1.12", features = ["macros", "rt-multi-thread", "sync", "time"] } +tokio = { version = "1.12", features = [ + "macros", + "rt-multi-thread", + "sync", + "time", +] } [[test]] name = "json" From 186b050a4e00d973676579c6d4b825591554520c Mon Sep 17 00:00:00 2001 From: Rafael Bachmann Date: Tue, 14 Nov 2023 23:38:00 +0100 Subject: [PATCH 3/6] Fix clippy --- codegen/src/attribute.rs | 12 ++++++------ src/event.rs | 2 +- src/runner/basic.rs | 8 ++++---- src/writer/normalize.rs | 32 ++++++++++++++++---------------- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/codegen/src/attribute.rs b/codegen/src/attribute.rs index f392ec8a..c702d5ae 100644 --- a/codegen/src/attribute.rs +++ b/codegen/src/attribute.rs @@ -53,7 +53,7 @@ struct Step { /// reference. /// /// [`gherkin::Step`]: https://bit.ly/3j42hcd - step_arg_name: Option, + arg_name: Option, } impl Step { @@ -97,7 +97,7 @@ impl Step { attr_name, attr_arg, func, - step_arg_name, + arg_name: step_arg_name, }) } @@ -274,7 +274,7 @@ impl Step { Ok((func_args, addon_parsing)) } - } else if self.step_arg_name.is_some() { + } else if self.arg_name.is_some() { Ok(( quote! { ::std::borrow::Borrow::borrow(&__cucumber_ctx.step), }, None, @@ -304,7 +304,7 @@ impl Step { let (ident, ty) = parse_fn_arg(arg)?; let is_ctx_arg = - self.step_arg_name.as_ref().map(|i| *i == *ident) == Some(true); + self.arg_name.as_ref().map(|i| *i == *ident) == Some(true); let decl = if is_ctx_arg { quote! { @@ -385,7 +385,7 @@ impl Step { &self, arg: &syn::FnArg, ) -> syn::Result { - if let Some(name) = &self.step_arg_name { + if let Some(name) = &self.arg_name { let (ident, _) = parse_fn_arg(arg)?; if name == ident { return Ok(quote! { @@ -444,7 +444,7 @@ impl Step { ) -> syn::Result { let expr = expr.value(); let params = - Parameters::new(&expr, &self.func, self.step_arg_name.as_ref())?; + Parameters::new(&expr, &self.func, self.arg_name.as_ref())?; let provider_impl = params.gen_provider_impl(&parse_quote! { Provider }); diff --git a/src/event.rs b/src/event.rs index 4ac255b0..7440e9a6 100644 --- a/src/event.rs +++ b/src/event.rs @@ -54,7 +54,7 @@ pub struct Event { impl Event { /// Creates a new [`Event`] out of the given `value`. #[must_use] - pub fn new(value: T) -> Self { + pub const fn new(value: T) -> Self { Self { #[cfg(feature = "timestamps")] at: SystemTime::now(), diff --git a/src/runner/basic.rs b/src/runner/basic.rs index 6a7cf753..f85a2c33 100644 --- a/src/runner/basic.rs +++ b/src/runner/basic.rs @@ -1074,7 +1074,7 @@ async fn execute( } } #[cfg(not(feature = "tracing"))] - let _ = id; + let _: ScenarioId = id; if fail_fast && scenario_failed && !retried { started_scenarios = ControlFlow::Break(()); @@ -1485,7 +1485,7 @@ where (fut, span_id) }; #[cfg(not(feature = "tracing"))] - let _ = scenario_id; + let _: ScenarioId = scenario_id; let result = fut.then_yield().await; @@ -1606,7 +1606,7 @@ where waiter.wait_for_span_close(id).then_yield().await; } #[cfg(not(feature = "tracing"))] - let _ = scenario_id; + let _: ScenarioId = scenario_id; match result { Ok((Some(captures), loc, Some(world))) => { @@ -1762,7 +1762,7 @@ where (fut, span_id) }; #[cfg(not(feature = "tracing"))] - let _ = scenario_id; + let _: ScenarioId = scenario_id; let res = fut.then_yield().await; diff --git a/src/writer/normalize.rs b/src/writer/normalize.rs index 4149eba0..391ed383 100644 --- a/src/writer/normalize.rs +++ b/src/writer/normalize.rs @@ -347,7 +347,7 @@ impl Normalized for AssertNormalized {} #[derive(Clone, Debug)] struct Queue { /// Underlying FIFO queue of values. - queue: LinkedHashMap, + fifo: LinkedHashMap, /// Initial [`Metadata`] of this [`Queue`] creation. /// @@ -363,7 +363,7 @@ impl Queue { /// Creates a new normalization [`Queue`] with an initial metadata. fn new(initial: Metadata) -> Self { Self { - queue: LinkedHashMap::new(), + fifo: LinkedHashMap::new(), initial: Some(initial), state: FinishedState::NotFinished, } @@ -385,7 +385,7 @@ impl Queue { /// Removes the given `key` from this [`Queue`]. fn remove(&mut self, key: &K) { - drop(self.queue.remove(key)); + drop(self.fifo.remove(key)); } } @@ -489,7 +489,7 @@ impl CucumberQueue { /// [`Feature`]: gherkin::Feature fn new_feature(&mut self, feat: Event>) { let (feat, meta) = feat.split(); - drop(self.queue.insert(feat, FeatureQueue::new(meta))); + drop(self.fifo.insert(feat, FeatureQueue::new(meta))); } /// Marks a [`Feature`] as finished on [`event::Feature::Finished`]. @@ -500,7 +500,7 @@ impl CucumberQueue { /// [`Feature`]: gherkin::Feature fn feature_finished(&mut self, feat: Event<&gherkin::Feature>) { let (feat, meta) = feat.split(); - self.queue + self.fifo .get_mut(feat) .unwrap_or_else(|| panic!("No Feature {}", feat.name)) .finished(meta); @@ -514,7 +514,7 @@ impl CucumberQueue { feat: &gherkin::Feature, rule: Event>, ) { - self.queue + self.fifo .get_mut(feat) .unwrap_or_else(|| panic!("No Feature {}", feat.name)) .new_rule(rule); @@ -531,7 +531,7 @@ impl CucumberQueue { feat: &gherkin::Feature, rule: Event>, ) { - self.queue + self.fifo .get_mut(feat) .unwrap_or_else(|| panic!("No Feature {}", feat.name)) .rule_finished(rule); @@ -545,7 +545,7 @@ impl CucumberQueue { scenario: Arc, event: Event>, ) { - self.queue + self.fifo .get_mut(feat) .unwrap_or_else(|| panic!("No Feature {}", feat.name)) .insert_scenario_event(rule, scenario, event.retries, event); @@ -559,7 +559,7 @@ impl<'me, World> Emitter for &'me mut CucumberQueue { type EmittedPath = (); fn current_item(self) -> Option { - self.queue + self.fifo .iter_mut() .next() .map(|(f, ev)| (Arc::clone(f), ev)) @@ -641,7 +641,7 @@ impl FeatureQueue { fn new_rule(&mut self, rule: Event>) { let (rule, meta) = rule.split(); drop( - self.queue.insert( + self.fifo.insert( Either::Left(rule), Either::Left(RulesQueue::new(meta)), ), @@ -653,7 +653,7 @@ impl FeatureQueue { /// [`Rule`]: gherkin::Rule fn rule_finished(&mut self, rule: Event>) { let (rule, meta) = rule.split(); - match self.queue.get_mut(&Either::Left(rule)) { + match self.fifo.get_mut(&Either::Left(rule)) { Some(Either::Left(ev)) => { ev.finished(meta); } @@ -673,12 +673,12 @@ impl FeatureQueue { ) { if let Some(r) = rule { match self - .queue + .fifo .get_mut(&Either::Left(Arc::clone(&r))) .unwrap_or_else(|| panic!("No Rule {}", r.name)) { Either::Left(rules) => rules - .queue + .fifo .entry((scenario, retries)) .or_insert_with(ScenariosQueue::new) .0 @@ -687,7 +687,7 @@ impl FeatureQueue { } } else { match self - .queue + .fifo .entry(Either::Right((scenario, retries))) .or_insert_with(|| Either::Right(ScenariosQueue::new())) { @@ -705,7 +705,7 @@ impl<'me, World> Emitter for &'me mut FeatureQueue { type EmittedPath = Arc; fn current_item(self) -> Option { - Some(match self.queue.iter_mut().next()? { + Some(match self.fifo.iter_mut().next()? { (Either::Left(rule), Either::Left(events)) => { Either::Left((Arc::clone(rule), events)) } @@ -748,7 +748,7 @@ impl<'me, World> Emitter for &'me mut RulesQueue { type EmittedPath = (Arc, Arc); fn current_item(self) -> Option { - self.queue + self.fifo .iter_mut() .next() .map(|((sc, _), ev)| (Arc::clone(sc), ev)) From 73b28f7a5ffdd1e1873442acdc6bbfcf4020431d Mon Sep 17 00:00:00 2001 From: tyranron Date: Tue, 21 Nov 2023 15:41:28 +0100 Subject: [PATCH 4/6] Revert unpleasant changes --- Cargo.toml | 22 +++------------------- codegen/src/attribute.rs | 12 ++++++------ src/writer/normalize.rs | 32 ++++++++++++++++---------------- 3 files changed, 25 insertions(+), 41 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5ea98326..7fc1c013 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -66,16 +66,7 @@ tracing = ["dep:crossbeam-utils", "dep:tracing", "dep:tracing-subscriber"] async-trait = "0.1.43" clap = { version = "4.3.2", features = ["derive", "wrap_help"] } console = "0.15" -derive_more = { version = "0.99.17", features = [ - "as_ref", - "deref", - "deref_mut", - "display", - "error", - "from", - "from_str", - "into", -], default_features = false } +derive_more = { version = "0.99.17", features = ["as_ref", "deref", "deref_mut", "display", "error", "from", "from_str", "into"], default_features = false } drain_filter_polyfill = "0.1.2" either = "1.6" futures = "0.3.17" @@ -94,9 +85,7 @@ smart-default = "0.7.1" # "macros" feature dependencies. anyhow = { version = "1.0.58", optional = true } cucumber-codegen = { version = "0.20.1", path = "./codegen", optional = true } -cucumber-expressions = { version = "0.3", features = [ - "into-regex", -], optional = true } +cucumber-expressions = { version = "0.3", features = ["into-regex"], optional = true } inventory = { version = "0.3", optional = true } # "output-json" and/or "libtest" features dependencies. @@ -118,12 +107,7 @@ tracing-subscriber = { version = "0.3.16", optional = true } derive_more = "0.99.17" rand = "0.8" tempfile = "3.2" -tokio = { version = "1.12", features = [ - "macros", - "rt-multi-thread", - "sync", - "time", -] } +tokio = { version = "1.12", features = ["macros", "rt-multi-thread", "sync", "time"] } [[test]] name = "json" diff --git a/codegen/src/attribute.rs b/codegen/src/attribute.rs index c702d5ae..f392ec8a 100644 --- a/codegen/src/attribute.rs +++ b/codegen/src/attribute.rs @@ -53,7 +53,7 @@ struct Step { /// reference. /// /// [`gherkin::Step`]: https://bit.ly/3j42hcd - arg_name: Option, + step_arg_name: Option, } impl Step { @@ -97,7 +97,7 @@ impl Step { attr_name, attr_arg, func, - arg_name: step_arg_name, + step_arg_name, }) } @@ -274,7 +274,7 @@ impl Step { Ok((func_args, addon_parsing)) } - } else if self.arg_name.is_some() { + } else if self.step_arg_name.is_some() { Ok(( quote! { ::std::borrow::Borrow::borrow(&__cucumber_ctx.step), }, None, @@ -304,7 +304,7 @@ impl Step { let (ident, ty) = parse_fn_arg(arg)?; let is_ctx_arg = - self.arg_name.as_ref().map(|i| *i == *ident) == Some(true); + self.step_arg_name.as_ref().map(|i| *i == *ident) == Some(true); let decl = if is_ctx_arg { quote! { @@ -385,7 +385,7 @@ impl Step { &self, arg: &syn::FnArg, ) -> syn::Result { - if let Some(name) = &self.arg_name { + if let Some(name) = &self.step_arg_name { let (ident, _) = parse_fn_arg(arg)?; if name == ident { return Ok(quote! { @@ -444,7 +444,7 @@ impl Step { ) -> syn::Result { let expr = expr.value(); let params = - Parameters::new(&expr, &self.func, self.arg_name.as_ref())?; + Parameters::new(&expr, &self.func, self.step_arg_name.as_ref())?; let provider_impl = params.gen_provider_impl(&parse_quote! { Provider }); diff --git a/src/writer/normalize.rs b/src/writer/normalize.rs index 391ed383..4149eba0 100644 --- a/src/writer/normalize.rs +++ b/src/writer/normalize.rs @@ -347,7 +347,7 @@ impl Normalized for AssertNormalized {} #[derive(Clone, Debug)] struct Queue { /// Underlying FIFO queue of values. - fifo: LinkedHashMap, + queue: LinkedHashMap, /// Initial [`Metadata`] of this [`Queue`] creation. /// @@ -363,7 +363,7 @@ impl Queue { /// Creates a new normalization [`Queue`] with an initial metadata. fn new(initial: Metadata) -> Self { Self { - fifo: LinkedHashMap::new(), + queue: LinkedHashMap::new(), initial: Some(initial), state: FinishedState::NotFinished, } @@ -385,7 +385,7 @@ impl Queue { /// Removes the given `key` from this [`Queue`]. fn remove(&mut self, key: &K) { - drop(self.fifo.remove(key)); + drop(self.queue.remove(key)); } } @@ -489,7 +489,7 @@ impl CucumberQueue { /// [`Feature`]: gherkin::Feature fn new_feature(&mut self, feat: Event>) { let (feat, meta) = feat.split(); - drop(self.fifo.insert(feat, FeatureQueue::new(meta))); + drop(self.queue.insert(feat, FeatureQueue::new(meta))); } /// Marks a [`Feature`] as finished on [`event::Feature::Finished`]. @@ -500,7 +500,7 @@ impl CucumberQueue { /// [`Feature`]: gherkin::Feature fn feature_finished(&mut self, feat: Event<&gherkin::Feature>) { let (feat, meta) = feat.split(); - self.fifo + self.queue .get_mut(feat) .unwrap_or_else(|| panic!("No Feature {}", feat.name)) .finished(meta); @@ -514,7 +514,7 @@ impl CucumberQueue { feat: &gherkin::Feature, rule: Event>, ) { - self.fifo + self.queue .get_mut(feat) .unwrap_or_else(|| panic!("No Feature {}", feat.name)) .new_rule(rule); @@ -531,7 +531,7 @@ impl CucumberQueue { feat: &gherkin::Feature, rule: Event>, ) { - self.fifo + self.queue .get_mut(feat) .unwrap_or_else(|| panic!("No Feature {}", feat.name)) .rule_finished(rule); @@ -545,7 +545,7 @@ impl CucumberQueue { scenario: Arc, event: Event>, ) { - self.fifo + self.queue .get_mut(feat) .unwrap_or_else(|| panic!("No Feature {}", feat.name)) .insert_scenario_event(rule, scenario, event.retries, event); @@ -559,7 +559,7 @@ impl<'me, World> Emitter for &'me mut CucumberQueue { type EmittedPath = (); fn current_item(self) -> Option { - self.fifo + self.queue .iter_mut() .next() .map(|(f, ev)| (Arc::clone(f), ev)) @@ -641,7 +641,7 @@ impl FeatureQueue { fn new_rule(&mut self, rule: Event>) { let (rule, meta) = rule.split(); drop( - self.fifo.insert( + self.queue.insert( Either::Left(rule), Either::Left(RulesQueue::new(meta)), ), @@ -653,7 +653,7 @@ impl FeatureQueue { /// [`Rule`]: gherkin::Rule fn rule_finished(&mut self, rule: Event>) { let (rule, meta) = rule.split(); - match self.fifo.get_mut(&Either::Left(rule)) { + match self.queue.get_mut(&Either::Left(rule)) { Some(Either::Left(ev)) => { ev.finished(meta); } @@ -673,12 +673,12 @@ impl FeatureQueue { ) { if let Some(r) = rule { match self - .fifo + .queue .get_mut(&Either::Left(Arc::clone(&r))) .unwrap_or_else(|| panic!("No Rule {}", r.name)) { Either::Left(rules) => rules - .fifo + .queue .entry((scenario, retries)) .or_insert_with(ScenariosQueue::new) .0 @@ -687,7 +687,7 @@ impl FeatureQueue { } } else { match self - .fifo + .queue .entry(Either::Right((scenario, retries))) .or_insert_with(|| Either::Right(ScenariosQueue::new())) { @@ -705,7 +705,7 @@ impl<'me, World> Emitter for &'me mut FeatureQueue { type EmittedPath = Arc; fn current_item(self) -> Option { - Some(match self.fifo.iter_mut().next()? { + Some(match self.queue.iter_mut().next()? { (Either::Left(rule), Either::Left(events)) => { Either::Left((Arc::clone(rule), events)) } @@ -748,7 +748,7 @@ impl<'me, World> Emitter for &'me mut RulesQueue { type EmittedPath = (Arc, Arc); fn current_item(self) -> Option { - self.fifo + self.queue .iter_mut() .next() .map(|((sc, _), ev)| (Arc::clone(sc), ev)) From 38c202ef73bff5b86b4c9c639e51cad0db399ebf Mon Sep 17 00:00:00 2001 From: tyranron Date: Tue, 21 Nov 2023 15:54:33 +0100 Subject: [PATCH 5/6] Some corrections --- Cargo.toml | 2 +- src/event.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7fc1c013..26b5fa47 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,9 +26,9 @@ include = [ "/tests/libtest.rs", "/tests/tracing.rs", "/tests/wait.rs", + "/CHANGELOG.md", "/LICENSE-*", "/README.md", - "/CHANGELOG.md", ] [package.metadata.docs.rs] diff --git a/src/event.rs b/src/event.rs index 7440e9a6..4ac255b0 100644 --- a/src/event.rs +++ b/src/event.rs @@ -54,7 +54,7 @@ pub struct Event { impl Event { /// Creates a new [`Event`] out of the given `value`. #[must_use] - pub const fn new(value: T) -> Self { + pub fn new(value: T) -> Self { Self { #[cfg(feature = "timestamps")] at: SystemTime::now(), From 25b3dcdb83aa800e0e137ecd8b26277d0c983f03 Mon Sep 17 00:00:00 2001 From: tyranron Date: Tue, 21 Nov 2023 15:57:49 +0100 Subject: [PATCH 6/6] Check `not(feature = ...)` code in `cargo.lint` Makefile command --- Makefile | 1 + src/event.rs | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/Makefile b/Makefile index 54564122..7da1e7fd 100644 --- a/Makefile +++ b/Makefile @@ -73,6 +73,7 @@ cargo.fmt: # make cargo.lint cargo.lint: + cargo clippy --workspace -- -D warnings cargo clippy --workspace --all-features -- -D warnings diff --git a/src/event.rs b/src/event.rs index 4ac255b0..e08a4cab 100644 --- a/src/event.rs +++ b/src/event.rs @@ -53,6 +53,10 @@ pub struct Event { impl Event { /// Creates a new [`Event`] out of the given `value`. + #[cfg_attr( + not(feature = "timestamps"), + allow(clippy::missing_const_for_fn) + )] #[must_use] pub fn new(value: T) -> Self { Self {