
* added basic detection for ambiguous steps, but causes an error and not yet recorded in the reports as 'Ambiguous', and no test cases figured out yet * added initial support for detection of ambiguous steps - further work take a look at how cuke jvm report ambiguous steps and sets the step status to 'ambiguous' rather than my current solution which just blows the test up as a regular step error * added suite_context_test and also introduced missing 'ambiguous' status to make cucumber jvm' * update CHANGELOG for ambiguous step defs * missed file from commit * added internal/formatters/fmt_multi_test.go * add tests for other peoples code * added "ambigous" to the help text * tests * added some more tests for attachments * Update internal/flags/flags.go Co-authored-by: Viacheslav Poturaev <nanopeni@gmail.com> --------- Co-authored-by: Viacheslav Poturaev <nanopeni@gmail.com>
102 строки
2,6 КиБ
Go
102 строки
2,6 КиБ
Go
package formatters
|
|
|
|
import (
|
|
"io"
|
|
"regexp"
|
|
|
|
messages "github.com/cucumber/messages/go/v21"
|
|
)
|
|
|
|
type registeredFormatter struct {
|
|
name string
|
|
description string
|
|
fmt FormatterFunc
|
|
}
|
|
|
|
var registeredFormatters []*registeredFormatter
|
|
|
|
// FindFmt searches available formatters registered
|
|
// and returns FormaterFunc matched by given
|
|
// format name or nil otherwise
|
|
func FindFmt(name string) FormatterFunc {
|
|
for _, el := range registeredFormatters {
|
|
if el.name == name {
|
|
return el.fmt
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// Format registers a feature suite output
|
|
// formatter by given name, description and
|
|
// FormatterFunc constructor function, to initialize
|
|
// formatter with the output recorder.
|
|
func Format(name, description string, f FormatterFunc) {
|
|
registeredFormatters = append(registeredFormatters, ®isteredFormatter{
|
|
name: name,
|
|
fmt: f,
|
|
description: description,
|
|
})
|
|
}
|
|
|
|
// AvailableFormatters gives a map of all
|
|
// formatters registered with their name as key
|
|
// and description as value
|
|
func AvailableFormatters() map[string]string {
|
|
fmts := make(map[string]string, len(registeredFormatters))
|
|
|
|
for _, f := range registeredFormatters {
|
|
fmts[f.name] = f.description
|
|
}
|
|
|
|
return fmts
|
|
}
|
|
|
|
// Formatter is an interface for feature runner
|
|
// output summary presentation.
|
|
//
|
|
// New formatters may be created to represent
|
|
// suite results in different ways. These new
|
|
// formatters needs to be registered with a
|
|
// godog.Format function call
|
|
type Formatter interface {
|
|
TestRunStarted()
|
|
Feature(*messages.GherkinDocument, string, []byte)
|
|
Pickle(*messages.Pickle)
|
|
Defined(*messages.Pickle, *messages.PickleStep, *StepDefinition)
|
|
Failed(*messages.Pickle, *messages.PickleStep, *StepDefinition, error)
|
|
Passed(*messages.Pickle, *messages.PickleStep, *StepDefinition)
|
|
Skipped(*messages.Pickle, *messages.PickleStep, *StepDefinition)
|
|
Undefined(*messages.Pickle, *messages.PickleStep, *StepDefinition)
|
|
Pending(*messages.Pickle, *messages.PickleStep, *StepDefinition)
|
|
Ambiguous(*messages.Pickle, *messages.PickleStep, *StepDefinition, error)
|
|
Summary()
|
|
}
|
|
|
|
// FormatterFunc builds a formatter with given
|
|
// suite name and io.Writer to record output
|
|
type FormatterFunc func(string, io.Writer) Formatter
|
|
|
|
// StepDefinition is a registered step definition
|
|
// contains a StepHandler and regexp which
|
|
// is used to match a step. Args which
|
|
// were matched by last executed step
|
|
//
|
|
// This structure is passed to the formatter
|
|
// when step is matched and is either failed
|
|
// or successful
|
|
type StepDefinition struct {
|
|
Expr *regexp.Regexp
|
|
Handler interface{}
|
|
Keyword Keyword
|
|
}
|
|
|
|
type Keyword int64
|
|
|
|
const (
|
|
Given Keyword = iota
|
|
When
|
|
Then
|
|
None
|
|
)
|