Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Aug 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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])
- `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]

Expand Down
105 changes: 104 additions & 1 deletion features/formatter/pretty.feature
Original file line number Diff line number Diff line change
Expand Up @@ -328,4 +328,107 @@ Feature: pretty formatter
1 scenarios (1 passed)
6 steps (6 passed)
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
"""
3 changes: 3 additions & 0 deletions internal/formatters/fmt_pretty.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,9 @@ func (f *pretty) longestStep(steps []*messages.Step, pickleLength int) int {

// a line number representation in feature file
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))
}

Expand Down
9 changes: 9 additions & 0 deletions internal/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,19 @@ func parsePath(path string, newIDFunc func() string) ([]*models.Feature, error)

// filter scenario by line number
var pickles []*messages.Pickle

if line != -1 {
ft.Uri += ":" + strconv.Itoa(line)
}

for _, pickle := range ft.Pickles {
sc := ft.FindScenario(pickle.AstNodeIds[0])

if line == -1 || int64(line) == sc.Location.Line {
if line != -1 {
pickle.Uri += ":" + strconv.Itoa(line)
}

pickles = append(pickles, pickle)
}
}
Expand Down
6 changes: 3 additions & 3 deletions run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,11 +414,11 @@ func Test_AllFeaturesRun(t *testing.T) {
...................................................................... 140
...................................................................... 210
...................................................................... 280
............................. 309
................................... 315


81 scenarios (81 passed)
309 steps (309 passed)
82 scenarios (82 passed)
315 steps (315 passed)
0s
`

Expand Down