Clean change on pretty. Make test on new TC meaningfull again.
Этот коммит содержится в:
родитель
32741b9662
коммит
fe2a967670
6 изменённых файлов: 58 добавлений и 64 удалений
|
@ -300,21 +300,32 @@ Feature: pretty formatter
|
||||||
|
|
||||||
Scenario: test scenario
|
Scenario: test scenario
|
||||||
Given Ignore I save some value X under key Y
|
Given Ignore I save some value X under key Y
|
||||||
|
And I allow variable injection
|
||||||
When Ignore I use value {{Y}}
|
When Ignore I use value {{Y}}
|
||||||
Then Ignore Godog rendering should not break
|
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"
|
When I run feature suite with formatter "pretty"
|
||||||
Then the rendered output will be as follows:
|
Then the rendered output will be as follows:
|
||||||
"""
|
"""
|
||||||
Feature: inject long value
|
Feature: inject long value
|
||||||
|
|
||||||
Scenario: test scenario # features/inject.feature:3
|
Scenario: test scenario # features/inject.feature:3
|
||||||
Given Ignore I save some value X under key Y # suite_context.go:0 -> SuiteContext.func7
|
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
|
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
|
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)
|
1 scenarios (1 passed)
|
||||||
3 steps (3 passed)
|
6 steps (6 passed)
|
||||||
0s
|
0s
|
||||||
"""
|
"""
|
|
@ -2627,7 +2627,7 @@
|
||||||
"name": "a feature \"features/inject.feature\" file:",
|
"name": "a feature \"features/inject.feature\" file:",
|
||||||
"line": 297,
|
"line": 297,
|
||||||
"doc_string": {
|
"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": "",
|
"content_type": "",
|
||||||
"line": 298
|
"line": 298
|
||||||
},
|
},
|
||||||
|
@ -2639,22 +2639,10 @@
|
||||||
"duration": 0
|
"duration": 0
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"keyword": "And ",
|
|
||||||
"name": "I allow variable injection",
|
|
||||||
"line": 306,
|
|
||||||
"match": {
|
|
||||||
"location": "suite_context.go:0"
|
|
||||||
},
|
|
||||||
"result": {
|
|
||||||
"status": "passed",
|
|
||||||
"duration": 0
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"keyword": "When ",
|
"keyword": "When ",
|
||||||
"name": "I run feature suite with formatter \"pretty\"",
|
"name": "I run feature suite with formatter \"pretty\"",
|
||||||
"line": 307,
|
"line": 312,
|
||||||
"match": {
|
"match": {
|
||||||
"location": "suite_context.go:0"
|
"location": "suite_context.go:0"
|
||||||
},
|
},
|
||||||
|
@ -2666,11 +2654,11 @@
|
||||||
{
|
{
|
||||||
"keyword": "Then ",
|
"keyword": "Then ",
|
||||||
"name": "the rendered output will be as follows:",
|
"name": "the rendered output will be as follows:",
|
||||||
"line": 308,
|
"line": 313,
|
||||||
"doc_string": {
|
"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": "",
|
"content_type": "",
|
||||||
"line": 309
|
"line": 314
|
||||||
},
|
},
|
||||||
"match": {
|
"match": {
|
||||||
"location": "suite_context.go:0"
|
"location": "suite_context.go:0"
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
...................................................................... 140
|
...................................................................... 140
|
||||||
...................................................................... 210
|
...................................................................... 210
|
||||||
...................................................................... 280
|
...................................................................... 280
|
||||||
........................... 307
|
.......................... 306
|
||||||
|
|
||||||
|
|
||||||
79 scenarios (79 passed)
|
79 scenarios (79 passed)
|
||||||
307 steps (307 passed)
|
306 steps (306 passed)
|
||||||
0s
|
0s
|
|
@ -124,13 +124,12 @@ func (f *pretty) printUndefinedScenario(sc interface{}) {
|
||||||
case *gherkin.Scenario:
|
case *gherkin.Scenario:
|
||||||
f.commentPos = f.longestStep(t.Steps, f.length(sc))
|
f.commentPos = f.longestStep(t.Steps, f.length(sc))
|
||||||
text := s(f.indent) + keywordAndName(t.Keyword, t.Name)
|
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)
|
fmt.Fprintln(f.out, "\n"+text)
|
||||||
case *gherkin.ScenarioOutline:
|
case *gherkin.ScenarioOutline:
|
||||||
f.commentPos = f.longestStep(t.Steps, f.length(sc))
|
f.commentPos = f.longestStep(t.Steps, f.length(sc))
|
||||||
text := s(f.indent) + keywordAndName(t.Keyword, t.Name)
|
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)
|
fmt.Fprintln(f.out, "\n"+text)
|
||||||
|
|
||||||
for _, example := range t.Examples {
|
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 {
|
for i, cell := range row.Cells {
|
||||||
val := clr(cell.Value)
|
val := clr(cell.Value)
|
||||||
ln := utf8.RuneCountInString(val)
|
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) {
|
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 {
|
for i, cell := range example.TableHeader.Cells {
|
||||||
val := cyan(cell.Value)
|
val := cyan(cell.Value)
|
||||||
ln := utf8.RuneCountInString(val)
|
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) {
|
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 += c(step.Text)
|
||||||
}
|
}
|
||||||
text += s(f.commentPos-f.length(step)+1) + blackb(fmt.Sprintf("# %s", def.definitionID()))
|
text += s(f.commentPos-f.length(step)+1) + blackb(fmt.Sprintf("# %s", def.definitionID()))
|
||||||
|
|
||||||
default:
|
default:
|
||||||
text += c(step.Text)
|
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.indent) + keywordAndName(f.scenario.Keyword, f.scenario.Name)
|
||||||
text += s(f.commentPos-f.length(f.scenario)+1) + f.line(f.scenario.Location)
|
text += s(f.commentPos-f.length(f.scenario)+1) + f.line(f.scenario.Location)
|
||||||
|
|
||||||
fmt.Fprintln(f.out, "\n"+text)
|
fmt.Fprintln(f.out, "\n"+text)
|
||||||
f.scenarioKeyword = true
|
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.indent) + keywordAndName(f.outline.Keyword, f.outline.Name)
|
||||||
text += s(f.commentPos-f.length(f.outline)+1) + f.line(f.outline.Location)
|
text += s(f.commentPos-f.length(f.outline)+1) + f.line(f.outline.Location)
|
||||||
|
|
||||||
fmt.Fprintln(f.out, "\n"+text)
|
fmt.Fprintln(f.out, "\n"+text)
|
||||||
f.scenarioKeyword = true
|
f.scenarioKeyword = true
|
||||||
}
|
}
|
||||||
|
@ -404,9 +400,9 @@ func (f *pretty) printTable(t *gherkin.DataTable, c colors.ColorFunc) {
|
||||||
for i, cell := range row.Cells {
|
for i, cell := range row.Cells {
|
||||||
val := c(cell.Value)
|
val := c(cell.Value)
|
||||||
ln := utf8.RuneCountInString(val)
|
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"
|
"github.com/cucumber/godog/gherkin"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
allowInjection = true
|
|
||||||
)
|
|
||||||
|
|
||||||
// SuiteContext provides steps for godog suite execution and
|
// SuiteContext provides steps for godog suite execution and
|
||||||
// can be used for meta-testing of godog features/steps themselves.
|
// can be used for meta-testing of godog features/steps themselves.
|
||||||
//
|
//
|
||||||
|
@ -107,25 +103,27 @@ func SuiteContext(s *Suite, additionalContextInitializers ...func(suite *Suite))
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
s.BeforeStep(func(step *gherkin.Step) {
|
s.BeforeStep(c.inject)
|
||||||
if !allowInjection {
|
}
|
||||||
return
|
func (s *suiteContext) inject(step *gherkin.Step) {
|
||||||
}
|
if !s.allowInjection {
|
||||||
step.Text = injectAll(step.Text)
|
return
|
||||||
args := step.Argument
|
}
|
||||||
if args != nil {
|
|
||||||
switch arg := args.(type) {
|
step.Text = injectAll(step.Text)
|
||||||
case *gherkin.DataTable:
|
args := step.Argument
|
||||||
for i := 0; i < len(arg.Rows); i++ {
|
if args != nil {
|
||||||
for n, cell := range arg.Rows[i].Cells {
|
switch arg := args.(type) {
|
||||||
arg.Rows[i].Cells[n].Value = injectAll(cell.Value)
|
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)
|
|
||||||
}
|
}
|
||||||
|
case *gherkin.DocString:
|
||||||
|
arg.Content = injectAll(arg.Content)
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func injectAll(inTo string) string {
|
func injectAll(inTo string) string {
|
||||||
|
@ -148,11 +146,12 @@ type firedEvent struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type suiteContext struct {
|
type suiteContext struct {
|
||||||
paths []string
|
paths []string
|
||||||
testedSuite *Suite
|
testedSuite *Suite
|
||||||
extraCIs []func(suite *Suite)
|
extraCIs []func(suite *Suite)
|
||||||
events []*firedEvent
|
events []*firedEvent
|
||||||
out bytes.Buffer
|
out bytes.Buffer
|
||||||
|
allowInjection bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *suiteContext) ResetBeforeEachScenario(interface{}) {
|
func (s *suiteContext) ResetBeforeEachScenario(interface{}) {
|
||||||
|
@ -164,10 +163,11 @@ func (s *suiteContext) ResetBeforeEachScenario(interface{}) {
|
||||||
SuiteContext(s.testedSuite, s.extraCIs...)
|
SuiteContext(s.testedSuite, s.extraCIs...)
|
||||||
// reset all fired events
|
// reset all fired events
|
||||||
s.events = []*firedEvent{}
|
s.events = []*firedEvent{}
|
||||||
|
s.allowInjection = false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *suiteContext) iSetVariableInjectionTo(to string) error {
|
func (s *suiteContext) iSetVariableInjectionTo(to string) error {
|
||||||
allowInjection = to == "allow"
|
s.allowInjection = to == "allow"
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,7 +189,6 @@ func (s *suiteContext) iRunFeatureSuiteWithFormatter(name string) error {
|
||||||
if f == nil {
|
if f == nil {
|
||||||
return fmt.Errorf(`formatter "%s" is not available`, name)
|
return fmt.Errorf(`formatter "%s" is not available`, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
s.testedSuite.fmt = f("godog", colors.Uncolored(&s.out))
|
s.testedSuite.fmt = f("godog", colors.Uncolored(&s.out))
|
||||||
if err := s.parseFeatures(); err != nil {
|
if err := s.parseFeatures(); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
2
utils.go
2
utils.go
|
@ -20,7 +20,7 @@ var (
|
||||||
|
|
||||||
// repeats a space n times
|
// repeats a space n times
|
||||||
func s(n int) string {
|
func s(n int) string {
|
||||||
if n <= 0 {
|
if n < 0 {
|
||||||
n = 1
|
n = 1
|
||||||
}
|
}
|
||||||
return strings.Repeat(" ", n)
|
return strings.Repeat(" ", n)
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче