ensure source formatting with golint, go vet and go fmt

Этот коммит содержится в:
gedi 2015-06-23 15:27:22 +03:00
родитель 2e509414d1
коммит d5755df70c
13 изменённых файлов: 96 добавлений и 83 удалений

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

@ -6,13 +6,23 @@ go:
- tip
script:
# pull all dependencies manually to see how many we have
# linters and vet
- go get golang.org/x/tools/cmd/vet
- go get github.com/golang/lint/golint
# pull all external dependencies
# remove them at all if possible
- go get golang.org/x/tools/imports
- go get github.com/shiena/ansicolor
# run standard go tests
- go test -v ./...
- go test -race ./...
# test me with myself
- go run cmd/godog/main.go
- go run cmd/godog/main.go -f progress
# code correctness
- sh -c 'if [ ! -z "$(go fmt ./...)" ]; then exit 1; fi'
- golint ./...
- go vet ./...

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

@ -18,7 +18,7 @@ func init() {
})
}
var outlinePlaceholderRegexp *regexp.Regexp = regexp.MustCompile("<[^>]+>")
var outlinePlaceholderRegexp = regexp.MustCompile("<[^>]+>")
// a built in default pretty formatter
type pretty struct {
@ -306,7 +306,7 @@ func (f *pretty) printStepKind(stepAction interface{}) {
case step.Background != nil && f.backgroundSteps == 0:
return
case step.Background != nil && f.backgroundSteps > 0:
f.backgroundSteps -= 1
f.backgroundSteps--
}
if f.outlineExamples != 0 {
@ -314,7 +314,7 @@ func (f *pretty) printStepKind(stepAction interface{}) {
if len(f.outlineSteps) == f.outlineNumSteps {
// an outline example steps has went through
f.printOutlineExample(step.Scenario)
f.outlineExamples -= 1
f.outlineExamples--
}
return // wait till example steps
}

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

@ -109,7 +109,7 @@ func (f *progress) step(step interface{}) {
case *undefined:
fmt.Print(cl("U", yellow))
}
f.steps += 1
f.steps++
if math.Mod(float64(f.steps), float64(f.stepsPerRow)) == 0 {
fmt.Printf(" %d\n", f.steps)
}

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

@ -117,8 +117,8 @@ func Test_parse_feature_with_newlines(t *testing.T) {
}
p.assertMatchesTypes([]TokenType{
NEW_LINE,
NEW_LINE,
NEWLINE,
NEWLINE,
FEATURE,
}, t)
}

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

@ -227,7 +227,7 @@ func (p *parser) peek() *Token {
return p.peeked
}
for p.peeked = p.lx.read(); p.peeked.OfType(COMMENT, NEW_LINE); p.peeked = p.lx.read() {
for p.peeked = p.lx.read(); p.peeked.OfType(COMMENT, NEWLINE); p.peeked = p.lx.read() {
p.ast = append(p.ast, p.peeked) // record comments and newlines
}
@ -292,7 +292,7 @@ func (p *parser) parseFeature() (ft *Feature, err error) {
}
// there must be a scenario or scenario outline otherwise
if !tok.OfType(SCENARIO, SCENARIO_OUTLINE) {
if !tok.OfType(SCENARIO, OUTLINE) {
if tok.Type == EOF {
return ft, nil // there may not be a scenario defined after background
}
@ -324,7 +324,7 @@ func (p *parser) parseScenario() (s *Scenario, err error) {
if examples := p.peek(); examples.Type == EXAMPLES {
p.next() // jump over the peeked token
peek := p.peek()
if peek.Type != TABLE_ROW {
if peek.Type != TABLEROW {
return s, p.err(strings.Join([]string{
"expected a table row,",
"but got '" + peek.Type.String() + "' instead, for scenario outline examples",
@ -359,7 +359,7 @@ func (p *parser) parseSteps() (steps []*Step, err error) {
return steps, err
}
step.PyString.Step = step
case TABLE_ROW:
case TABLEROW:
if step.Table, err = p.parseTable(); err != nil {
return steps, err
}
@ -394,7 +394,7 @@ func (p *parser) parsePystring() (*PyString, error) {
func (p *parser) parseTable() (*Table, error) {
tbl := &Table{Token: p.peek()}
for row := p.peek(); row.Type == TABLE_ROW; row = p.peek() {
for row := p.peek(); row.Type == TABLEROW; row = p.peek() {
var cols []string
for _, r := range strings.Split(strings.Trim(row.Value, "|"), "|") {
cols = append(cols, strings.TrimFunc(r, unicode.IsSpace))

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

@ -24,25 +24,25 @@ var matchers = map[string]*regexp.Regexp{
// for now only english language is supported
var keywords = map[TokenType]string{
// special
ILLEGAL: "Illegal",
EOF: "End of file",
NEW_LINE: "New line",
TAGS: "Tags",
COMMENT: "Comment",
PYSTRING: "PyString",
TABLE_ROW: "Table row",
TEXT: "Text",
ILLEGAL: "Illegal",
EOF: "End of file",
NEWLINE: "New line",
TAGS: "Tags",
COMMENT: "Comment",
PYSTRING: "PyString",
TABLEROW: "Table row",
TEXT: "Text",
// general
GIVEN: "Given",
WHEN: "When",
THEN: "Then",
AND: "And",
BUT: "But",
FEATURE: "Feature",
BACKGROUND: "Background",
SCENARIO: "Scenario",
SCENARIO_OUTLINE: "Scenario Outline",
EXAMPLES: "Examples",
GIVEN: "Given",
WHEN: "When",
THEN: "Then",
AND: "And",
BUT: "But",
FEATURE: "Feature",
BACKGROUND: "Background",
SCENARIO: "Scenario",
OUTLINE: "Scenario Outline",
EXAMPLES: "Examples",
}
type lexer struct {
@ -70,9 +70,9 @@ func (l *lexer) read() *Token {
// newline
if len(line) == 0 {
return &Token{
Type: NEW_LINE,
Type: NEWLINE,
Line: l.lines,
Keyword: keywords[NEW_LINE],
Keyword: keywords[NEWLINE],
}
}
// comment
@ -172,25 +172,25 @@ func (l *lexer) read() *Token {
// table row
if m := matchers["table_row"].FindStringSubmatch(line); len(m) > 0 {
return &Token{
Type: TABLE_ROW,
Type: TABLEROW,
Indent: len(m[1]),
Line: l.lines,
Value: strings.TrimSpace(m[2]),
Text: line,
Comment: strings.Trim(m[3], " #"),
Keyword: keywords[TABLE_ROW],
Keyword: keywords[TABLEROW],
}
}
// scenario outline
if m := matchers["scenario_outline"].FindStringSubmatch(line); len(m) > 0 {
return &Token{
Type: SCENARIO_OUTLINE,
Type: OUTLINE,
Indent: len(m[1]),
Line: l.lines,
Value: strings.TrimSpace(m[2]),
Text: line,
Comment: strings.Trim(m[3], " #"),
Keyword: keywords[SCENARIO_OUTLINE],
Keyword: keywords[OUTLINE],
}
}
// examples

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

@ -133,11 +133,11 @@ func Test_minimal_feature(t *testing.T) {
TEXT,
TEXT,
TEXT,
NEW_LINE,
NEWLINE,
BACKGROUND,
GIVEN,
NEW_LINE,
NEWLINE,
COMMENT,
SCENARIO,
@ -171,9 +171,9 @@ func Test_table_row_reading(t *testing.T) {
expectedTypes := []TokenType{
BACKGROUND,
GIVEN,
TABLE_ROW,
TABLE_ROW,
TABLE_ROW,
TABLEROW,
TABLEROW,
TABLEROW,
GIVEN,
}
expectedIndents := []int{2, 4, 6, 6, 6, 4}
@ -200,18 +200,18 @@ func Test_lexing_of_scenario_outline(t *testing.T) {
tokens = append(tokens, tok.Type)
}
expected := []TokenType{
SCENARIO_OUTLINE,
OUTLINE,
GIVEN,
AND,
AND,
WHEN,
THEN,
NEW_LINE,
NEWLINE,
EXAMPLES,
TABLE_ROW,
TABLE_ROW,
TABLE_ROW,
TABLEROW,
TABLEROW,
TABLEROW,
}
for i := 0; i < len(expected); i++ {
if expected[i] != tokens[i] {

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

@ -8,7 +8,7 @@ import (
func (a *parser) assertMatchesTypes(expected []TokenType, t *testing.T) {
key := -1
for _, tok := range a.ast {
key += 1
key++
if len(expected) <= key {
t.Fatalf("there are more tokens in AST then expected, next is '%s'", tok.Type)
}
@ -72,19 +72,19 @@ func Test_parse_feature_file(t *testing.T) {
TEXT,
TEXT,
TEXT,
NEW_LINE,
NEWLINE,
BACKGROUND,
GIVEN,
TABLE_ROW,
NEW_LINE,
TABLEROW,
NEWLINE,
SCENARIO,
GIVEN,
AND,
WHEN,
THEN,
NEW_LINE,
NEWLINE,
TAGS,
SCENARIO,
@ -92,23 +92,23 @@ func Test_parse_feature_file(t *testing.T) {
AND,
WHEN,
THEN,
NEW_LINE,
NEWLINE,
TAGS,
SCENARIO,
NEW_LINE,
NEWLINE,
SCENARIO_OUTLINE,
OUTLINE,
GIVEN,
AND,
AND,
WHEN,
THEN,
NEW_LINE,
NEWLINE,
EXAMPLES,
TABLE_ROW,
TABLE_ROW,
TABLE_ROW,
TABLEROW,
TABLEROW,
TABLEROW,
}, t)
ft.assertHasNumScenarios(4, t)

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

@ -17,7 +17,7 @@ func (s *Scenario) assertOutlineStep(text string, t *testing.T) *Step {
return stp
}
}
t.Fatal("expected scenario '%s' to have step: '%s', but it did not", s.Title, text)
t.Fatalf("expected scenario '%s' to have step: '%s', but it did not", s.Title, text)
return nil
}
@ -27,7 +27,7 @@ func (s *Scenario) assertStep(text string, t *testing.T) *Step {
return stp
}
}
t.Fatal("expected scenario '%s' to have step: '%s', but it did not", s.Title, text)
t.Fatalf("expected scenario '%s' to have step: '%s', but it did not", s.Title, text)
return nil
}
@ -61,17 +61,17 @@ func Test_parse_scenario_outline(t *testing.T) {
s.assertTitle("ls supports kinds of options", t)
p.assertMatchesTypes([]TokenType{
SCENARIO_OUTLINE,
OUTLINE,
GIVEN,
AND,
AND,
WHEN,
THEN,
NEW_LINE,
NEWLINE,
EXAMPLES,
TABLE_ROW,
TABLE_ROW,
TABLE_ROW,
TABLEROW,
TABLEROW,
TABLEROW,
}, t)
s.assertOutlineStep(`I am in a directory "test"`, t)

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

@ -146,7 +146,7 @@ func Test_parse_hash_table_given_step(t *testing.T) {
p.next() // step over to eof
p.assertMatchesTypes([]TokenType{
GIVEN,
TABLE_ROW,
TABLEROW,
EOF,
}, t)
}
@ -172,9 +172,9 @@ func Test_parse_table_given_step(t *testing.T) {
p.next() // step over to eof
p.assertMatchesTypes([]TokenType{
GIVEN,
TABLE_ROW,
TABLE_ROW,
TABLE_ROW,
TABLEROW,
TABLEROW,
TABLEROW,
EOF,
}, t)
}

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

@ -5,21 +5,23 @@ import (
"unicode"
)
// TokenType defines a gherkin token type
type TokenType int
// TokenType constants
const (
ILLEGAL TokenType = iota
COMMENT
NEW_LINE
NEWLINE
EOF
TEXT
TAGS
TABLE_ROW
TABLEROW
PYSTRING
FEATURE
BACKGROUND
SCENARIO
SCENARIO_OUTLINE
OUTLINE
EXAMPLES
GIVEN
WHEN

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

@ -58,6 +58,7 @@ type StepDef struct {
// executions are catching panic error since it may
// be a context specific error.
type Suite interface {
Run()
Step(expr Regexp, h StepHandler)
// suite events
BeforeSuite(f func())
@ -84,10 +85,9 @@ type suite struct {
afterSuiteHandlers []func()
}
// New initializes a suite which supports the Suite
// interface. The instance is passed around to all
// context initialization functions from *_test.go files
func New() *suite {
// New initializes a Suite. The instance is passed around
// to all context initialization functions from *_test.go files
func New() Suite {
return &suite{}
}
@ -378,18 +378,19 @@ func (s *suite) runScenario(scenario *gherkin.Scenario) (err error) {
return
}
func (st *suite) printStepDefinitions() {
func (s *suite) printStepDefinitions() {
var longest int
for _, def := range st.stepHandlers {
for _, def := range s.stepHandlers {
if longest < len(def.Expr.String()) {
longest = len(def.Expr.String())
}
}
for _, def := range st.stepHandlers {
for _, def := range s.stepHandlers {
location := runtime.FuncForPC(reflect.ValueOf(def.Handler).Pointer()).Name()
fmt.Println(cl(def.Expr.String(), yellow)+s(longest-len(def.Expr.String())), cl("# "+location, black))
spaces := strings.Repeat(" ", longest-len(def.Expr.String()))
fmt.Println(cl(def.Expr.String(), yellow)+spaces, cl("# "+location, black))
}
if len(st.stepHandlers) == 0 {
if len(s.stepHandlers) == 0 {
fmt.Println("there were no contexts registered, could not find any step definition..")
}
}

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

@ -54,7 +54,7 @@ func (s *suiteContext) HandleBeforeScenario(*gherkin.Scenario) {
}
func (s *suiteContext) followingStepsShouldHave(args ...*Arg) error {
var expected []string = args[1].PyString().Lines
var expected = args[1].PyString().Lines
var actual, unmatched []string
var matched []int