From 09d7d85abfd9a05526122b3c1d41ec35a2161de4 Mon Sep 17 00:00:00 2001 From: Viacheslav Poturaev Date: Sat, 7 Aug 2021 22:37:31 +0200 Subject: [PATCH] Fix execution of scenarios provided as a list of path:line (#414) --- CHANGELOG.md | 1 + features/formatter/pretty.feature | 105 +++++++++++++++++++++++++++++- internal/formatters/fmt_pretty.go | 3 + internal/parser/parser.go | 9 +++ run_test.go | 6 +- 5 files changed, 120 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 74d7bb1..b6762b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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] diff --git a/features/formatter/pretty.feature b/features/formatter/pretty.feature index 82d35b4..225a718 100644 --- a/features/formatter/pretty.feature +++ b/features/formatter/pretty.feature @@ -328,4 +328,107 @@ Feature: pretty formatter 1 scenarios (1 passed) 6 steps (6 passed) 0s - """ \ No newline at end of file + """ + + 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 + """ diff --git a/internal/formatters/fmt_pretty.go b/internal/formatters/fmt_pretty.go index d0fcf75..ab0c3d0 100644 --- a/internal/formatters/fmt_pretty.go +++ b/internal/formatters/fmt_pretty.go @@ -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)) } diff --git a/internal/parser/parser.go b/internal/parser/parser.go index 9c5ee90..c505cde 100644 --- a/internal/parser/parser.go +++ b/internal/parser/parser.go @@ -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) } } diff --git a/run_test.go b/run_test.go index c58b1e8..4f001f9 100644 --- a/run_test.go +++ b/run_test.go @@ -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 `