Skip to content

Commit

Permalink
Reduce deps, fix CI for go1.16, format imports
Browse files Browse the repository at this point in the history
  • Loading branch information
vearutop committed May 26, 2023
1 parent 3eae6c0 commit 35820ff
Show file tree
Hide file tree
Showing 25 changed files with 82 additions and 1,274 deletions.
13 changes: 2 additions & 11 deletions _examples/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/cucumber/godog/_examples

go 1.17
go 1.16

replace github.com/cucumber/godog => ../

Expand All @@ -9,19 +9,10 @@ require (
github.com/cucumber/godog v0.12.6
github.com/go-sql-driver/mysql v1.7.1
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.3
github.com/stretchr/testify v1.8.2
)

require (
github.com/cucumber/gherkin/go/v26 v26.2.0 // indirect
github.com/cucumber/messages/go/v21 v21.0.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gofrs/uuid v4.4.0+incompatible // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-memdb v1.3.4 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/lib/pq v1.10.3 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
597 changes: 2 additions & 595 deletions _examples/go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion formatters/fmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"io"
"regexp"

"github.com/cucumber/messages/go/v21"
messages "github.com/cucumber/messages/go/v21"
)

type registeredFormatter struct {
Expand Down
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ go 1.16
require (
github.com/cucumber/gherkin/go/v26 v26.2.0
github.com/hashicorp/go-memdb v1.3.4
github.com/smartystreets/goconvey v1.8.0
github.com/spf13/cobra v1.7.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.3
github.com/stretchr/testify v1.8.2
)

require (
github.com/cucumber/messages/go/v21 v21.0.1
github.com/gofrs/uuid v4.4.0+incompatible // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-uuid v1.0.2 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
Expand Down
600 changes: 2 additions & 598 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion internal/formatters/fmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strconv"
"strings"

"github.com/cucumber/messages/go/v21"
messages "github.com/cucumber/messages/go/v21"

"github.com/cucumber/godog/colors"
"github.com/cucumber/godog/internal/models"
Expand Down
2 changes: 1 addition & 1 deletion internal/formatters/fmt_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"sync"
"unicode"

"github.com/cucumber/messages/go/v21"
messages "github.com/cucumber/messages/go/v21"

"github.com/cucumber/godog/colors"
"github.com/cucumber/godog/formatters"
Expand Down
3 changes: 1 addition & 2 deletions internal/formatters/fmt_cucumber.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ import (
"sort"
"strings"

"github.com/cucumber/messages/go/v21"

"github.com/cucumber/godog/formatters"
"github.com/cucumber/godog/internal/models"
messages "github.com/cucumber/messages/go/v21"
)

func init() {
Expand Down
3 changes: 1 addition & 2 deletions internal/formatters/fmt_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import (
"fmt"
"io"

"github.com/cucumber/messages/go/v21"

"github.com/cucumber/godog/formatters"
"github.com/cucumber/godog/internal/utils"
messages "github.com/cucumber/messages/go/v21"
)

const nanoSec = 1000000
Expand Down
2 changes: 1 addition & 1 deletion internal/formatters/fmt_multi.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/cucumber/godog/formatters"
"github.com/cucumber/godog/internal/storage"
"github.com/cucumber/messages/go/v21"
messages "github.com/cucumber/messages/go/v21"
)

// MultiFormatter passes test progress to multiple formatters.
Expand Down
2 changes: 1 addition & 1 deletion internal/formatters/fmt_pretty.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"
"unicode/utf8"

"github.com/cucumber/messages/go/v21"
messages "github.com/cucumber/messages/go/v21"

"github.com/cucumber/godog/colors"
"github.com/cucumber/godog/formatters"
Expand Down
3 changes: 1 addition & 2 deletions internal/formatters/fmt_progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import (
"sort"
"strings"

"github.com/cucumber/messages/go/v21"

"github.com/cucumber/godog/formatters"
messages "github.com/cucumber/messages/go/v21"
)

func init() {
Expand Down
2 changes: 1 addition & 1 deletion internal/formatters/undefined_snippets_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strings"
"text/template"

"github.com/cucumber/messages/go/v21"
messages "github.com/cucumber/messages/go/v21"
)

// some snippet formatting regexps
Expand Down
2 changes: 1 addition & 1 deletion internal/models/feature.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package models

import (
"github.com/cucumber/messages/go/v21"
messages "github.com/cucumber/messages/go/v21"
)

// Feature is an internal object to group together
Expand Down
2 changes: 1 addition & 1 deletion internal/models/stepdef.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"reflect"
"strconv"

"github.com/cucumber/messages/go/v21"
messages "github.com/cucumber/messages/go/v21"

"github.com/cucumber/godog/formatters"
)
Expand Down
2 changes: 1 addition & 1 deletion internal/models/stepdef_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import (
"strings"
"testing"

"github.com/cucumber/messages/go/v21"
"github.com/stretchr/testify/assert"

"github.com/cucumber/godog"
"github.com/cucumber/godog/formatters"
"github.com/cucumber/godog/internal/models"
messages "github.com/cucumber/messages/go/v21"
)

func TestShouldSupportContext(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion internal/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"sync"

"github.com/cucumber/messages/go/v21"
messages "github.com/cucumber/messages/go/v21"
"github.com/hashicorp/go-memdb"

"github.com/cucumber/godog/internal/models"
Expand Down
2 changes: 1 addition & 1 deletion internal/storage/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"
"time"

"github.com/cucumber/messages/go/v21"
messages "github.com/cucumber/messages/go/v21"
"github.com/stretchr/testify/assert"

"github.com/cucumber/godog/internal/models"
Expand Down
2 changes: 1 addition & 1 deletion internal/tags/tag_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package tags
import (
"strings"

"github.com/cucumber/messages/go/v21"
messages "github.com/cucumber/messages/go/v21"
)

// ApplyTagFilter will apply a filter string on the
Expand Down
2 changes: 1 addition & 1 deletion internal/tags/tag_filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package tags_test
import (
"testing"

"github.com/cucumber/messages/go/v21"
"github.com/stretchr/testify/assert"

"github.com/cucumber/godog/internal/tags"
messages "github.com/cucumber/messages/go/v21"
)

type tag = messages.PickleTag
Expand Down
4 changes: 2 additions & 2 deletions internal/testutils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"strings"
"testing"

"github.com/cucumber/gherkin/go/v26"
"github.com/cucumber/messages/go/v21"
gherkin "github.com/cucumber/gherkin/go/v26"
messages "github.com/cucumber/messages/go/v21"
"github.com/stretchr/testify/require"

"github.com/cucumber/godog/internal/models"
Expand Down
5 changes: 3 additions & 2 deletions run_progress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package godog

import (
"bytes"
"github.com/cucumber/messages/go/v21"
"strings"
"testing"

"github.com/cucumber/gherkin/go/v26"
messages "github.com/cucumber/messages/go/v21"

gherkin "github.com/cucumber/gherkin/go/v26"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand Down
2 changes: 1 addition & 1 deletion suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strings"
"testing"

"github.com/cucumber/messages/go/v21"
messages "github.com/cucumber/messages/go/v21"

"github.com/cucumber/godog/formatters"
"github.com/cucumber/godog/internal/models"
Expand Down
2 changes: 1 addition & 1 deletion test_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/cucumber/godog/internal/builder"
"github.com/cucumber/godog/internal/flags"
"github.com/cucumber/godog/internal/models"
"github.com/cucumber/messages/go/v21"
messages "github.com/cucumber/messages/go/v21"
)

// GherkinDocument represents gherkin document.
Expand Down
94 changes: 52 additions & 42 deletions test_context_test.go
Original file line number Diff line number Diff line change
@@ -1,60 +1,70 @@
package godog

import (
"fmt"
"github.com/stretchr/testify/assert"
"regexp"
"testing"

. "github.com/smartystreets/goconvey/convey"
)

func TestScenarioContext_Step(t *testing.T) {
Convey("When adding steps to ScenarioContext ", t, func() {
ctx := ScenarioContext{suite: &suite{}}

Convey("It should accept steps defined with regexp.Regexp", func() {
re := regexp.MustCompile(`(?:it is a test)?.{10}x*`)
So(func() { ctx.Step(re, okEmptyResult) }, ShouldNotPanic)
})
ctx := ScenarioContext{suite: &suite{}}
re := regexp.MustCompile(`(?:it is a test)?.{10}x*`)

Convey("It should accept steps defined with bytes slice", func() {
So(func() { ctx.Step([]byte("(?:it is a test)?.{10}x*"), okEmptyResult) }, ShouldNotPanic)
})
type tc struct {
f func()
n string
p interface{}
}

Convey("It should accept steps handler with empty return", func() {
So(func() { ctx.Step(".*", okEmptyResult) }, ShouldNotPanic)
for _, c := range []tc{
{n: "ScenarioContext should accept steps defined with regexp.Regexp",
f: func() { ctx.Step(re, okEmptyResult) }},
{n: "ScenarioContext should accept steps defined with bytes slice",
f: func() { ctx.Step([]byte("(?:it is a test)?.{10}x*"), okEmptyResult) }},
{n: "ScenarioContext should accept steps handler with error return",
f: func() { ctx.Step(".*", okEmptyResult) }},
{n: "ScenarioContext should accept steps handler with error return",
f: func() { ctx.Step(".*", okErrorResult) }},
{n: "ScenarioContext should accept steps handler with string slice return",
f: func() { ctx.Step(".*", okSliceResult) }},
} {
t.Run(c.n, func(t *testing.T) {
assert.NotPanics(t, c.f)
})
}

Convey("It should accept steps handler with error return", func() {
So(func() { ctx.Step(".*", okErrorResult) }, ShouldNotPanic)
})
for _, c := range []tc{
{n: "ScenarioContext should panic if step expression is neither a string, regex or byte slice",
p: "expecting expr to be a *regexp.Regexp or a string, got type: int",
f: func() { ctx.Step(1251, okSliceResult) }},
{n: "ScenarioContext should panic if step handler is not a function",
p: "expected handler to be func, but got: int",
f: func() { ctx.Step(".*", 124) }},
{n: "ScenarioContext should panic if step handler has more than 2 return values",
p: "expected handler to return either zero, one or two values, but it has: 3",
f: func() { ctx.Step(".*", nokLimitCase) }},
{n: "ScenarioContext should panic if step handler has more than 2 return values (5)",
p: "expected handler to return either zero, one or two values, but it has: 5",
f: func() { ctx.Step(".*", nokMore) }},

Convey("It should accept steps handler with string slice return", func() {
So(func() { ctx.Step(".*", okSliceResult) }, ShouldNotPanic)
})
{n: "ScenarioContext should panic if step expression is neither a string, regex or byte slice",
p: "expecting expr to be a *regexp.Regexp or a string, got type: int",
f: func() { ctx.Step(1251, okSliceResult) }},

Convey("It should panic if step expression is neither a string, regex or byte slice", func() {
So(func() { ctx.Step(1251, okSliceResult) }, ShouldPanicWith, fmt.Sprintf("expecting expr to be a *regexp.Regexp or a string, got type: %T", 12))
{n: "ScenarioContext should panic if step handler return type is not an error or string slice or void (interface)",
p: "expected handler to return an error or context.Context, but got: interface",
f: func() { ctx.Step(".*", nokInvalidReturnInterfaceType) }},
{n: "ScenarioContext should panic if step handler return type is not an error or string slice or void (slice)",
p: "expected handler to return []string for multistep, but got: []int",
f: func() { ctx.Step(".*", nokInvalidReturnSliceType) }},
{n: "ScenarioContext should panic if step handler return type is not an error or string slice or void (other)",
p: "expected handler to return an error or []string, but got: chan",
f: func() { ctx.Step(".*", nokInvalidReturnOtherType) }},
} {
t.Run(c.n, func(t *testing.T) {
assert.PanicsWithValue(t, c.p, c.f)
})
Convey("It should panic if step handler", func() {
Convey("is not a function", func() {
So(func() { ctx.Step(".*", 124) }, ShouldPanicWith, fmt.Sprintf("expected handler to be func, but got: %T", 12))
})

Convey("has more than 2 return values", func() {
So(func() { ctx.Step(".*", nokLimitCase) }, ShouldPanicWith, "expected handler to return either zero, one or two values, but it has: 3")
So(func() { ctx.Step(".*", nokMore) }, ShouldPanicWith, "expected handler to return either zero, one or two values, but it has: 5")
})

Convey("return type is not an error or string slice or void", func() {
So(func() { ctx.Step(".*", nokInvalidReturnInterfaceType) }, ShouldPanicWith, "expected handler to return an error or context.Context, but got: interface")
So(func() { ctx.Step(".*", nokInvalidReturnSliceType) }, ShouldPanicWith, "expected handler to return []string for multistep, but got: []int")
So(func() { ctx.Step(".*", nokInvalidReturnOtherType) }, ShouldPanicWith, "expected handler to return an error or []string, but got: chan")
})
})

})

}
}

func okEmptyResult() {}
Expand Down

0 comments on commit 35820ff

Please sign in to comment.