Skip to content

Commit

Permalink
Fix @retry, @serial and @allow.skipped tags semantics inheritan…
Browse files Browse the repository at this point in the history
…ce (#237)
  • Loading branch information
ilslv authored Oct 25, 2022
1 parent 4cad49f commit 38745f2
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 28 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,17 @@ All user visible changes to `cucumber` crate will be documented in this file. Th

[Diff](/../../compare/v0.15.1...v0.15.2) | [Milestone](/../../milestone/17)

### Changed

- Upgraded [`gherkin`] crate to 0.13 version. ([4cad49f8])

### Fixed

- Parsing error on a `Feature` having comment and tag simultaneously. ([cucumber-rs/gherkin#37], [cucumber-rs/gherkin#35])
- Parsing error on a `Feature` having comment and tag simultaneously. ([4cad49f8], [cucumber-rs/gherkin#37], [cucumber-rs/gherkin#35])
- `@retry`, `@serial` and `@allow.skipped` tags semantics inheritance. ([#237])

[#237]: /../../pull/237
[4cad49f8]: /../../commit/4cad49f8d8f5d0458dcb538aa044a5fff1e6fa10
[cucumber-rs/gherkin#35]: https://github.com/cucumber-rs/gherkin/issues/35
[cucumber-rs/gherkin#37]: https://github.com/cucumber-rs/gherkin/pull/37

Expand Down
6 changes: 4 additions & 2 deletions book/src/writing/tags.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,15 @@ To filter out running [scenario]s we may use:

[Tags][tag] may be placed above the following [Gherkin] elements:
- [`Feature`][feature]
- [`Rule`][rule]
- [`Scenario`][scenario]
- [`Scenario Outline`]
- [`Examples`]

It's _not_ possible to place [tag]s above [`Background`](background.md) or [step]s (`Given`, `When`, `Then`, `And` and `But`).

[Tags][tag] are inherited by child elements:
- [`Feature`][feature] [tag]s will be inherited by [`Scenario`][scenario], [`Scenario Outline`], or [`Examples`].
- [`Feature`][feature] and [`Rule`][rule] [tag]s will be inherited by [`Scenario`][scenario], [`Scenario Outline`], or [`Examples`].
- [`Scenario Outline`] [tag]s will be inherited by [`Examples`].

```gherkin
Expand Down Expand Up @@ -221,7 +222,8 @@ Feature: Animal feature
[escaping]: https://github.com/cucumber/tag-expressions/tree/6f444830b23bd8e0c5a2617cd51b91bc2e05adde#escaping
[feature]: https://cucumber.io/docs/gherkin/reference#feature
[Gherkin]: https://cucumber.io/docs/gherkin/reference
[rule]: https://cucumber.io/docs/gherkin/reference#rule
[scenario]: https://cucumber.io/docs/gherkin/reference#example
[step]: https://cucumber.io/docs/gherkin/reference#steps
[tag]: https://cucumber.io/docs/cucumber/api#tags
[tag expressions]: https://cucumber.io/docs/cucumber/api#tag-expressions
[step]: https://cucumber.io/docs/gherkin/reference#steps
5 changes: 1 addition & 4 deletions src/cucumber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -731,10 +731,7 @@ where
tags.eval(
feat.tags
.iter()
.chain(
rule.into_iter()
.flat_map(|r| r.tags.iter()),
)
.chain(rule.iter().flat_map(|r| &r.tags))
.chain(scenario.tags.iter()),
)
},
Expand Down
22 changes: 13 additions & 9 deletions src/runner/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,11 @@ impl RetryOptions {
let apply_cli = |options: Option<_>| {
let matched = cli.retry_tag_filter.as_ref().map_or_else(
|| cli.retry.is_some() || cli.retry_after.is_some(),
|op| op.eval(&scenario.tags),
|op| {
op.eval(scenario.tags.iter().chain(
rule.iter().flat_map(|r| &r.tags).chain(&feature.tags),
))
},
);

(options.is_some() || matched).then(|| Self {
Expand Down Expand Up @@ -388,14 +392,14 @@ impl<World, F, B, A> fmt::Debug for Basic<World, F, B, A> {

impl<World> Default for Basic<World> {
fn default() -> Self {
let which_scenario: WhichScenarioFn = |_, _, scenario| {
let has_serial_tag =
scenario.tags.iter().any(|tag| tag == "serial");
if has_serial_tag {
ScenarioType::Serial
} else {
ScenarioType::Concurrent
}
let which_scenario: WhichScenarioFn = |feature, rule, scenario| {
scenario
.tags
.iter()
.chain(rule.iter().flat_map(|r| &r.tags))
.chain(&feature.tags)
.find(|tag| *tag == "serial")
.map_or(ScenarioType::Concurrent, |_| ScenarioType::Serial)
};

Self {
Expand Down
8 changes: 6 additions & 2 deletions src/writer/fail_on_skipped.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,12 @@ impl<Writer> From<Writer> for FailOnSkipped<Writer> {
fn from(writer: Writer) -> Self {
Self {
writer,
should_fail: |_, _, sc| {
!sc.tags.iter().any(|t| t == "allow.skipped")
should_fail: |feat, rule, sc| {
!sc.tags
.iter()
.chain(rule.iter().flat_map(|r| &r.tags))
.chain(&feat.tags)
.any(|t| t == "allow.skipped")
},
}
}
Expand Down
Loading

0 comments on commit 38745f2

Please sign in to comment.