diff --git a/.gitignore b/.gitignore index 396cb22..cae3286 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ Gopkg.lock Gopkg.toml -.DS_Store \ No newline at end of file +.DS_Store +.idea \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e6b326..bae4c66 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,6 @@ This document is formatted according to the principles of [Keep A CHANGELOG](htt - Run godog features in CircleCI in strict mode ([jaysonesmith]) - Removed TestMain call in `suite_test.go` for CI. ([jaysonesmith]) -- Migrated to [gherkin-go - v9.2.0](https://github.com/cucumber/gherkin-go/releases/tag/v9.2.0). ([240](https://github.com/cucumber/godog/pull/240) - [lonnblad]) ### Deprecated @@ -28,6 +27,7 @@ This document is formatted according to the principles of [Keep A CHANGELOG](htt - Re enable custom formatters. ([238](https://github.com/cucumber/godog/pull/238) - [ericmcbride]) - Added back suite_test.go ([jaysonesmith]) - Normalise module paths for use on Windows ([242](https://github.com/cucumber/godog/pull/242) - [gjtaylor]) +- Fixed panic in indenting function `s`([247](https://github.com/cucumber/godog/pull/247) - [titouanfreville]) ## [0.8.1] @@ -78,3 +78,4 @@ This document is formatted according to the principles of [Keep A CHANGELOG](htt [smikulcik]: https://github.com/smikulcik [ericmcbride]: https://github.com/ericmcbride [gjtaylor]: https://github.com/gjtaylor +[titouanfreville]: https://github.com/titouanfreville diff --git a/README.md b/README.md index 45934af..3f8e609 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,23 @@ executable to determine compiler and linker. The following about section was taken from [cucumber](https://cucumber.io/) homepage. +## Notice: + +**If your project depend on the master version of godog instead of a specific release, please read this.** + +Due to dependency changes in a coming merge to master, including breaking changes, you should update how you install or depend on godog so that you have a version specified. + +### Install +``` +go get github.com/cucumber/godog/cmd/godog@v0.8.1 +``` +Adding `@v0.8.1` will install v0.8.1 specifically instead of master. + +Running `within the $GOPATH`, you would also need to set `GO111MODULE=on`, like this: +``` +GO111MODULE=on go get github.com/cucumber/godog/cmd/godog@v0.8.1 +``` + ## About #### A single source of truth diff --git a/features/formatter/pretty.feature b/features/formatter/pretty.feature index cdd538f..1de2977 100644 --- a/features/formatter/pretty.feature +++ b/features/formatter/pretty.feature @@ -45,6 +45,7 @@ Feature: pretty formatter No steps 0s """ + Scenario: Support of Feature Plus Scenario Outline Given a feature "features/simple.feature" file: """ @@ -111,6 +112,7 @@ Feature: pretty formatter No steps 0s """ + Scenario: Support of Feature Plus Scenario With Steps Given a feature "features/simple.feature" file: """ @@ -146,6 +148,7 @@ Feature: pretty formatter 2 steps (1 passed, 1 failed) 0s """ + Scenario: Support of Feature Plus Scenario Outline With Steps Given a feature "features/simple.feature" file: """ @@ -214,6 +217,7 @@ Feature: pretty formatter No steps 0s """ + Scenario: Support of Docstrings Given a feature "features/simple.feature" file: """ @@ -244,6 +248,7 @@ Feature: pretty formatter 1 steps (1 passed) 0s """ + Scenario: Support of Undefined, Pending and Skipped status Given a feature "features/simple.feature" file: """ @@ -286,3 +291,41 @@ Feature: pretty formatter s.Step(`^undefined$`, undefined) } """ + + # Ensure s will not break when injecting data from BeforeStep + Scenario: Support data injection in BeforeStep + Given a feature "features/inject.feature" file: + """ + Feature: inject long value + + Scenario: test scenario + Given Ignore I save some value X under key Y + And I allow variable injection + When Ignore I use value {{Y}} + Then Ignore Godog rendering should not break + And Ignore test + | key | val | + | 1 | 2 | + | 3 | 4 | + And I disable variable injection + """ + When I run feature suite with formatter "pretty" + Then the rendered output will be as follows: + """ + Feature: inject long value + + Scenario: test scenario # features/inject.feature:3 + Given Ignore I save some value X under key Y # suite_context.go:0 -> SuiteContext.func7 + And I allow variable injection # suite_context.go:0 -> *suiteContext + When Ignore I use value someverylonginjectionsoweacanbesureitsurpasstheinitiallongeststeplenghtanditwillhelptestsmethodsafety # suite_context.go:0 -> SuiteContext.func7 + Then Ignore Godog rendering should not break # suite_context.go:0 -> SuiteContext.func7 + And Ignore test # suite_context.go:0 -> SuiteContext.func7 + | key | val | + | 1 | 2 | + | 3 | 4 | + And I disable variable injection # suite_context.go:0 -> *suiteContext + + 1 scenarios (1 passed) + 6 steps (6 passed) + 0s + """ \ No newline at end of file diff --git a/fixtures/junit_output.xml b/fixtures/junit_output.xml index cc03682..0bdc75b 100644 --- a/fixtures/junit_output.xml +++ b/fixtures/junit_output.xml @@ -1,5 +1,5 @@ - + @@ -35,7 +35,7 @@ - + @@ -45,6 +45,7 @@ + diff --git a/fixtures/progress_output.txt b/fixtures/progress_output.txt index 2d2565d..1c45625 100644 --- a/fixtures/progress_output.txt +++ b/fixtures/progress_output.txt @@ -2,9 +2,9 @@ ...................................................................... 140 ...................................................................... 210 ...................................................................... 280 -....................... 303 +.......................... 306 -78 scenarios (78 passed) -303 steps (303 passed) +79 scenarios (79 passed) +306 steps (306 passed) 0s \ No newline at end of file diff --git a/suite_context.go b/suite_context.go index 11670dd..9544436 100644 --- a/suite_context.go +++ b/suite_context.go @@ -45,6 +45,7 @@ func SuiteContext(s *Suite, additionalContextInitializers ...func(suite *Suite)) s.Step(`^I run feature suite$`, c.iRunFeatureSuite) s.Step(`^I run feature suite with tags "([^"]*)"$`, c.iRunFeatureSuiteWithTags) s.Step(`^I run feature suite with formatter "([^"]*)"$`, c.iRunFeatureSuiteWithFormatter) + s.Step(`^(?:I )(allow|disable) variable injection`, c.iSetVariableInjectionTo) s.Step(`^(?:a )?feature "([^"]*)"(?: file)?:$`, c.aFeatureFile) s.Step(`^the suite should have (passed|failed)$`, c.theSuiteShouldHave) @@ -99,6 +100,46 @@ func SuiteContext(s *Suite, additionalContextInitializers ...func(suite *Suite)) s.Step(`^(?:a )?failing nested multistep$`, func() Steps { return Steps{"passing step", "passing multistep", "failing multistep"} }) + // Default recovery step + s.Step(`Ignore.*`, func() error { + return nil + }) + + s.BeforeStep(c.inject) +} +func (s *suiteContext) inject(step *gherkin.Step) { + if !s.allowInjection { + return + } + + step.Text = injectAll(step.Text) + args := step.Argument + if args != nil { + switch arg := args.(type) { + case *gherkin.DataTable: + for i := 0; i < len(arg.Rows); i++ { + for n, cell := range arg.Rows[i].Cells { + arg.Rows[i].Cells[n].Value = injectAll(cell.Value) + } + } + case *gherkin.DocString: + arg.Content = injectAll(arg.Content) + } + } +} + +func injectAll(inTo string) string { + re := regexp.MustCompile(`{{[^{}]+}}`) + return re.ReplaceAllStringFunc( + inTo, + func(key string) string { + injectRegex := regexp.MustCompile(`^{{.+}}$`) + if injectRegex.MatchString(key) { + return "someverylonginjectionsoweacanbesureitsurpasstheinitiallongeststeplenghtanditwillhelptestsmethodsafety" + } + return key + }, + ) } type firedEvent struct { @@ -107,11 +148,12 @@ type firedEvent struct { } type suiteContext struct { - paths []string - testedSuite *Suite - extraCIs []func(suite *Suite) - events []*firedEvent - out bytes.Buffer + paths []string + testedSuite *Suite + extraCIs []func(suite *Suite) + events []*firedEvent + out bytes.Buffer + allowInjection bool } func (s *suiteContext) ResetBeforeEachScenario(*messages.Pickle) { @@ -123,6 +165,12 @@ func (s *suiteContext) ResetBeforeEachScenario(*messages.Pickle) { SuiteContext(s.testedSuite, s.extraCIs...) // reset all fired events s.events = []*firedEvent{} + s.allowInjection = false +} + +func (s *suiteContext) iSetVariableInjectionTo(to string) error { + s.allowInjection = to == "allow" + return nil } func (s *suiteContext) iRunFeatureSuiteWithTags(tags string) error { @@ -143,7 +191,6 @@ func (s *suiteContext) iRunFeatureSuiteWithFormatter(name string) error { if f == nil { return fmt.Errorf(`formatter "%s" is not available`, name) } - s.testedSuite.fmt = f("godog", colors.Uncolored(&s.out)) if err := s.parseFeatures(); err != nil { return err diff --git a/utils.go b/utils.go index 403425d..ac63a55 100644 --- a/utils.go +++ b/utils.go @@ -20,6 +20,9 @@ var ( // repeats a space n times func s(n int) string { + if n < 0 { + n = 1 + } return strings.Repeat(" ", n) }