Fix execution of scenarios provided as a list of path:line (#414)

Этот коммит содержится в:
Viacheslav Poturaev 2021-08-07 22:37:31 +02:00 коммит произвёл GitHub
родитель 6fb74a5334
коммит 09d7d85abf
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 120 добавлений и 4 удалений

Просмотреть файл

@ -33,6 +33,7 @@ This document is formatted according to the principles of [Keep A CHANGELOG](htt
- Incorrect step definition output for Data Tables ([411](https://github.com/cucumber/godog/pull/411) - [karfrank]) - Incorrect step definition output for Data Tables ([411](https://github.com/cucumber/godog/pull/411) - [karfrank])
- `ScenarioContext.AfterStep` not invoked after a failed case (([409](https://github.com/cucumber/godog/pull/409)) - [vearutop])) - `ScenarioContext.AfterStep` not invoked after a failed case (([409](https://github.com/cucumber/godog/pull/409)) - [vearutop]))
- Can't execute multiple specific scenarios in the same feature file (([414](https://github.com/cucumber/godog/pull/414)) - [vearutop]))
## [v0.11.0] ## [v0.11.0]

Просмотреть файл

@ -329,3 +329,106 @@ Feature: pretty formatter
6 steps (6 passed) 6 steps (6 passed)
0s 0s
""" """
Scenario: Should scenarios identified with path:line and preserve the order.
Given a feature path "features/load.feature:6"
And a feature path "features/multistep.feature:6"
And a feature path "features/load.feature:26"
And a feature path "features/multistep.feature:23"
When I run feature suite with formatter "pretty"
Then the rendered output will be as follows:
"""
Feature: load features
In order to run features
As a test suite
I need to be able to load features
Scenario: load features within path # features/load.feature:6
Given a feature path "features" # suite_context_test.go:0 -> *godogFeaturesScenario
When I parse features # suite_context_test.go:0 -> *godogFeaturesScenario
Then I should have 13 feature files: # suite_context_test.go:0 -> *godogFeaturesScenario
\"\"\"
features/background.feature
features/events.feature
features/formatter/cucumber.feature
features/formatter/events.feature
features/formatter/junit.feature
features/formatter/pretty.feature
features/lang.feature
features/load.feature
features/multistep.feature
features/outline.feature
features/run.feature
features/snippets.feature
features/tags.feature
\"\"\"
Feature: run features with nested steps
In order to test multisteps
As a test suite
I need to be able to execute multisteps
Scenario: should run passing multistep successfully # features/multistep.feature:6
Given a feature "normal.feature" file: # suite_context_test.go:0 -> *godogFeaturesScenario
\"\"\"
Feature: normal feature
Scenario: run passing multistep
Given passing step
Then passing multistep
\"\"\"
When I run feature suite # suite_context_test.go:0 -> *godogFeaturesScenario
Then the suite should have passed # suite_context_test.go:0 -> *godogFeaturesScenario
And the following steps should be passed: # suite_context_test.go:0 -> *godogFeaturesScenario
\"\"\"
passing step
passing multistep
\"\"\"
Feature: load features
In order to run features
As a test suite
I need to be able to load features
Scenario: load a specific feature file # features/load.feature:26
Given a feature path "features/load.feature" # suite_context_test.go:0 -> *godogFeaturesScenario
When I parse features # suite_context_test.go:0 -> *godogFeaturesScenario
Then I should have 1 feature file: # suite_context_test.go:0 -> *godogFeaturesScenario
\"\"\"
features/load.feature
\"\"\"
Feature: run features with nested steps
In order to test multisteps
As a test suite
I need to be able to execute multisteps
Scenario: should fail multistep # features/multistep.feature:23
Given a feature "failed.feature" file: # suite_context_test.go:0 -> *godogFeaturesScenario
\"\"\"
Feature: failed feature
Scenario: run failing multistep
Given passing step
When failing multistep
Then I should have 1 scenario registered
\"\"\"
When I run feature suite # suite_context_test.go:0 -> *godogFeaturesScenario
Then the suite should have failed # suite_context_test.go:0 -> *godogFeaturesScenario
And the following step should be failed: # suite_context_test.go:0 -> *godogFeaturesScenario
\"\"\"
failing multistep
\"\"\"
And the following steps should be skipped: # suite_context_test.go:0 -> *godogFeaturesScenario
\"\"\"
I should have 1 scenario registered
\"\"\"
And the following steps should be passed: # suite_context_test.go:0 -> *godogFeaturesScenario
\"\"\"
passing step
\"\"\"
4 scenarios (4 passed)
16 steps (16 passed)
0s
"""

Просмотреть файл

@ -527,6 +527,9 @@ func (f *pretty) longestStep(steps []*messages.Step, pickleLength int) int {
// a line number representation in feature file // a line number representation in feature file
func line(path string, loc *messages.Location) string { func line(path string, loc *messages.Location) string {
// Path can contain a line number already.
// This line number has to be trimmed to avoid duplication.
path = strings.TrimSuffix(path, fmt.Sprintf(":%d", loc.Line))
return " " + blackb(fmt.Sprintf("# %s:%d", path, loc.Line)) return " " + blackb(fmt.Sprintf("# %s:%d", path, loc.Line))
} }

Просмотреть файл

@ -99,10 +99,19 @@ func parsePath(path string, newIDFunc func() string) ([]*models.Feature, error)
// filter scenario by line number // filter scenario by line number
var pickles []*messages.Pickle var pickles []*messages.Pickle
if line != -1 {
ft.Uri += ":" + strconv.Itoa(line)
}
for _, pickle := range ft.Pickles { for _, pickle := range ft.Pickles {
sc := ft.FindScenario(pickle.AstNodeIds[0]) sc := ft.FindScenario(pickle.AstNodeIds[0])
if line == -1 || int64(line) == sc.Location.Line { if line == -1 || int64(line) == sc.Location.Line {
if line != -1 {
pickle.Uri += ":" + strconv.Itoa(line)
}
pickles = append(pickles, pickle) pickles = append(pickles, pickle)
} }
} }

Просмотреть файл

@ -414,11 +414,11 @@ func Test_AllFeaturesRun(t *testing.T) {
...................................................................... 140 ...................................................................... 140
...................................................................... 210 ...................................................................... 210
...................................................................... 280 ...................................................................... 280
............................. 309 ................................... 315
81 scenarios (81 passed) 82 scenarios (82 passed)
309 steps (309 passed) 315 steps (315 passed)
0s 0s
` `