Clean change on pretty. Make test on new TC meaningfull again.

Этот коммит содержится в:
tfreville 2020-03-09 14:55:30 +01:00
родитель 32741b9662
коммит fe2a967670
6 изменённых файлов: 58 добавлений и 64 удалений

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

@ -300,10 +300,15 @@ Feature: pretty formatter
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
"""
And I allow variable injection
When I run feature suite with formatter "pretty"
Then the rendered output will be as follows:
"""
@ -311,10 +316,16 @@ Feature: pretty formatter
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)
3 steps (3 passed)
6 steps (6 passed)
0s
"""

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

@ -2627,7 +2627,7 @@
"name": "a feature \"features/inject.feature\" file:",
"line": 297,
"doc_string": {
"value": " Feature: inject long value\n\n Scenario: test scenario\n Given Ignore I save some value X under key Y\n When Ignore I use value someverylonginjectionsoweacanbesureitsurpasstheinitiallongeststeplenghtanditwillhelptestsmethodsafety\n Then Ignore Godog rendering should not break",
"value": " Feature: inject long value\n\n Scenario: test scenario\n Given Ignore I save some value X under key Y\n And I allow variable injection\n When Ignore I use value {{Y}}\n Then Ignore Godog rendering should not break\n And Ignore test\n | key | val |\n | 1 | 2 |\n | 3 | 4 |\n And I disable variable injection",
"content_type": "",
"line": 298
},
@ -2639,22 +2639,10 @@
"duration": 0
}
},
{
"keyword": "And ",
"name": "I allow variable injection",
"line": 306,
"match": {
"location": "suite_context.go:0"
},
"result": {
"status": "passed",
"duration": 0
}
},
{
"keyword": "When ",
"name": "I run feature suite with formatter \"pretty\"",
"line": 307,
"line": 312,
"match": {
"location": "suite_context.go:0"
},
@ -2666,11 +2654,11 @@
{
"keyword": "Then ",
"name": "the rendered output will be as follows:",
"line": 308,
"line": 313,
"doc_string": {
"value": " Feature: inject long value\n\n Scenario: test scenario # features/inject.feature:3\n Given Ignore I save some value X under key Y # suite_context.go:0 -\u003e SuiteContext.func7\n When Ignore I use value someverylonginjectionsoweacanbesureitsurpasstheinitiallongeststeplenghtanditwillhelptestsmethodsafety # suite_context.go:0 -\u003e SuiteContext.func7\n Then Ignore Godog rendering should not break # suite_context.go:0 -\u003e SuiteContext.func7\n\n 1 scenarios (1 passed)\n 3 steps (3 passed)\n 0s",
"value": " Feature: inject long value\n\n Scenario: test scenario # features/inject.feature:3\n Given Ignore I save some value X under key Y # suite_context.go:0 -\u003e SuiteContext.func7\n And I allow variable injection # suite_context.go:0 -\u003e *suiteContext\n When Ignore I use value someverylonginjectionsoweacanbesureitsurpasstheinitiallongeststeplenghtanditwillhelptestsmethodsafety # suite_context.go:0 -\u003e SuiteContext.func7\n Then Ignore Godog rendering should not break # suite_context.go:0 -\u003e SuiteContext.func7\n And Ignore test # suite_context.go:0 -\u003e SuiteContext.func7\n | key | val |\n | 1 | 2 |\n | 3 | 4 |\n And I disable variable injection # suite_context.go:0 -\u003e *suiteContext\n\n 1 scenarios (1 passed)\n 6 steps (6 passed)\n 0s",
"content_type": "",
"line": 309
"line": 314
},
"match": {
"location": "suite_context.go:0"

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

@ -2,9 +2,9 @@
...................................................................... 140
...................................................................... 210
...................................................................... 280
........................... 307
.......................... 306
79 scenarios (79 passed)
307 steps (307 passed)
306 steps (306 passed)
0s

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

@ -124,13 +124,12 @@ func (f *pretty) printUndefinedScenario(sc interface{}) {
case *gherkin.Scenario:
f.commentPos = f.longestStep(t.Steps, f.length(sc))
text := s(f.indent) + keywordAndName(t.Keyword, t.Name)
text += s(f.commentPos-f.length(t)) + f.line(t.Location)
text += s(f.commentPos-f.length(t)+1) + f.line(t.Location)
fmt.Fprintln(f.out, "\n"+text)
case *gherkin.ScenarioOutline:
f.commentPos = f.longestStep(t.Steps, f.length(sc))
text := s(f.indent) + keywordAndName(t.Keyword, t.Name)
text += s(f.commentPos-f.length(t)) + f.line(t.Location)
text += s(f.commentPos-f.length(t)+1) + f.line(t.Location)
fmt.Fprintln(f.out, "\n"+text)
for _, example := range t.Examples {
@ -249,9 +248,9 @@ func (f *pretty) printExampleRow(row *gherkin.TableRow, max []int, clr colors.Co
for i, cell := range row.Cells {
val := clr(cell.Value)
ln := utf8.RuneCountInString(val)
cells[i] = val + s(max[i]-ln+1)
cells[i] = val + s(max[i]-ln)
}
fmt.Fprintln(f.out, s(f.indent*3)+"| "+strings.Join(cells, "| ")+"|")
fmt.Fprintln(f.out, s(f.indent*3)+"| "+strings.Join(cells, " | ")+" |")
}
func (f *pretty) printExampleHeader(example *gherkin.Examples, max []int) {
@ -263,9 +262,9 @@ func (f *pretty) printExampleHeader(example *gherkin.Examples, max []int) {
for i, cell := range example.TableHeader.Cells {
val := cyan(cell.Value)
ln := utf8.RuneCountInString(val)
cells[i] = val + s(max[i]-ln+1)
cells[i] = val + s(max[i]-ln)
}
fmt.Fprintln(f.out, s(f.indent*3)+"| "+strings.Join(cells, "| ")+"|")
fmt.Fprintln(f.out, s(f.indent*3)+"| "+strings.Join(cells, " | ")+" |")
}
func (f *pretty) printStep(step *gherkin.Step, def *StepDef, c colors.ColorFunc) {
@ -290,7 +289,6 @@ func (f *pretty) printStep(step *gherkin.Step, def *StepDef, c colors.ColorFunc)
text += c(step.Text)
}
text += s(f.commentPos-f.length(step)+1) + blackb(fmt.Sprintf("# %s", def.definitionID()))
default:
text += c(step.Text)
}
@ -344,7 +342,6 @@ func (f *pretty) printStepKind(res *stepResult) {
}
text := s(f.indent) + keywordAndName(f.scenario.Keyword, f.scenario.Name)
text += s(f.commentPos-f.length(f.scenario)+1) + f.line(f.scenario.Location)
fmt.Fprintln(f.out, "\n"+text)
f.scenarioKeyword = true
}
@ -360,7 +357,6 @@ func (f *pretty) printStepKind(res *stepResult) {
}
text := s(f.indent) + keywordAndName(f.outline.Keyword, f.outline.Name)
text += s(f.commentPos-f.length(f.outline)+1) + f.line(f.outline.Location)
fmt.Fprintln(f.out, "\n"+text)
f.scenarioKeyword = true
}
@ -404,9 +400,9 @@ func (f *pretty) printTable(t *gherkin.DataTable, c colors.ColorFunc) {
for i, cell := range row.Cells {
val := c(cell.Value)
ln := utf8.RuneCountInString(val)
cols[i] = val + s(l[i]-ln+1)
cols[i] = val + s(l[i]-ln)
}
fmt.Fprintln(f.out, s(f.indent*3)+"| "+strings.Join(cols, "| ")+"|")
fmt.Fprintln(f.out, s(f.indent*3)+"| "+strings.Join(cols, " | ")+" |")
}
}

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

@ -16,10 +16,6 @@ import (
"github.com/cucumber/godog/gherkin"
)
var (
allowInjection = true
)
// SuiteContext provides steps for godog suite execution and
// can be used for meta-testing of godog features/steps themselves.
//
@ -107,10 +103,13 @@ func SuiteContext(s *Suite, additionalContextInitializers ...func(suite *Suite))
return nil
})
s.BeforeStep(func(step *gherkin.Step) {
if !allowInjection {
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 {
@ -125,7 +124,6 @@ func SuiteContext(s *Suite, additionalContextInitializers ...func(suite *Suite))
arg.Content = injectAll(arg.Content)
}
}
})
}
func injectAll(inTo string) string {
@ -153,6 +151,7 @@ type suiteContext struct {
extraCIs []func(suite *Suite)
events []*firedEvent
out bytes.Buffer
allowInjection bool
}
func (s *suiteContext) ResetBeforeEachScenario(interface{}) {
@ -164,10 +163,11 @@ func (s *suiteContext) ResetBeforeEachScenario(interface{}) {
SuiteContext(s.testedSuite, s.extraCIs...)
// reset all fired events
s.events = []*firedEvent{}
s.allowInjection = false
}
func (s *suiteContext) iSetVariableInjectionTo(to string) error {
allowInjection = to == "allow"
s.allowInjection = to == "allow"
return nil
}
@ -189,7 +189,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

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

@ -20,7 +20,7 @@ var (
// repeats a space n times
func s(n int) string {
if n <= 0 {
if n < 0 {
n = 1
}
return strings.Repeat(" ", n)