Closed phil-davis closed 3 years ago
@ciaranmcnulty this fixes the problem. Please review.
After looking at the code, it seemed quite unfortunate that when sitting at a comment and doing parseExpression()
it ends up "eating" the comment and returning the next token after the comment. That puts the Lexer past both the comment and "the next token". It seemed useful to be able to tell the Lexer to "just skip" the current token so that the code can look at "the next token" and decide what to do without actually "eating" the token. In this case I skip any comments.
@stof @pamil @weaverryan @everzet (all the members of https://github.com/orgs/Behat/people
Is anyone available to review this, merge if OK, and make release 4.7.1 ?
Can you resolve the conflict?
Can you resolve the conflict?
@ciaranmcnulty done
Thanks @phil-davis
No problem - it was a weird edge-case in code that we contributed to in the first place!
Fixes issue #187
1) New scenarios from PR #188 2) Add another outline to tags_sample.feature ready for more failing tests (this outline passes fine) 3) Add failing test case to tags_sample.feature - this has, after a Scenario Outline, some tags, then a comment, then a Scenario.
That last commit fails with:
The problem is that
Parser.php
parseOutline()
does not know how to nicely stop consuming lines of the feature file after it finds more tags. It expects that there can be tags, andExamples
table, more tags, anotherExamples
table... After it finds the tags line, it then doespredictTokenType()
and finds a comment, so there could be another Examples table coming after the comment. So it doesparseExpression()
and sadly, rather than returning a comment string, it returns the nextScenario
, and the code raises aParserException
.The problem does not happen when the tags and scenario are not separated by a comment, because the
while
loop ends up being exited.The code needs to "see what is next" after a comment, without actually "gobbling up" the next thing.
4) Explicitly skip comments when parsing a scenario outline - this avoids calling
parseExpression()
to "see what is next". Thewhile
loop will "see what is next" usingpredictTokenType()
and that will correctly detect the upcoming Scenario and exit the while loop. The upcoming Scenario will be sitting in the Lexer as thestashedToken
and will be happily found by the higher-level processing of the Parser.