Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@acoulton
Copy link
Contributor

@acoulton acoulton commented May 5, 2025

For parity with cucumber/gherkin, do not accept feature files that end with @tags with no subsequent content.

cucumber/gherkin is relatively permissive about incomplete files in some cases (for example, it is explicitly valid to have a file with a Feature: but no scenarios, or a Scenario: with no steps). I suspect this is intentional to avoid parser errors while iterating on a partially-complete feature file.

However, the presence of @tags at the end of the file is unusual and suggests that the file is incomplete or damaged. cucumber/gherkin treats this as an exception and so should we.

For parity with cucumber/gherkin, do not accept feature files that
end with `@tags` with no subsequent content.

cucumber/gherkin is relatively permissive about incomplete files in
some cases (for example, it is explicitly valid to have a file with a
Feature: but no scenarios, or a Scenario: with no steps). I suspect this
is intentional to avoid parser errors while iterating on a feature.

However, the presence of `@tags` at the end of the file is unusual and
suggests that the file is incomplete or damaged. cucumber/gherkin treats
this as an exception and so should we.
Comment on lines -51 to +63
$parser->parse(
<<<'FEATURE'
Feature:
Scenario:
Given step
@skipped
FEATURE
);
try {
$parser->parse(
<<<'FEATURE'
Feature:
Scenario:
Given step
@skipped
FEATURE,
);
} catch (ParserException $e) {
// expected - features cannot end with tags
$this->assertSame('Unexpected end of file after tags on line 5', $e->getMessage());
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test relied on us parsing tags at the end of a file, but I don't think that was expected end-user behaviour. It was simply to prove that the parser state resets correctly on moving to the next file, and since we already know that tags are reset between features / scenarios / etc, the test had to create an artificial case where the tag was not attached to any node.

@codecov
Copy link

codecov bot commented May 5, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.23%. Comparing base (99c5226) to head (c4ebefc).
Report is 4 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master     #313      +/-   ##
============================================
+ Coverage     96.21%   96.23%   +0.01%     
- Complexity      596      598       +2     
============================================
  Files            35       35              
  Lines          1745     1751       +6     
============================================
+ Hits           1679     1685       +6     
  Misses           66       66              
Flag Coverage Δ
php8.1 96.23% <100.00%> (?)
php8.1--with=symfony/yaml:^5.4 96.23% <100.00%> (?)
php8.1--with=symfony/yaml:^6.4 96.23% <100.00%> (?)
php8.2 96.23% <100.00%> (+0.01%) ⬆️
php8.3 96.23% <100.00%> (+0.01%) ⬆️
php8.4 96.23% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@acoulton acoulton requested a review from carlos-granados May 5, 2025 15:40
Copy link
Contributor

@carlos-granados carlos-granados left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks @acoulton

@acoulton acoulton merged commit a26228b into Behat:master May 6, 2025
10 checks passed
@acoulton acoulton deleted the throw-on-tags-eof branch May 6, 2025 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants