Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use official tag-expressions library #8

Merged
merged 2 commits into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@ module github.com/regen-network/gocuke
go 1.17

require (
github.com/alecthomas/participle/v2 v2.0.0-alpha7
github.com/cockroachdb/apd/v3 v3.1.0
github.com/cucumber/common/gherkin/go/v22 v22.0.0
github.com/cucumber/common/messages/go/v17 v17.1.1
github.com/cucumber/tag-expressions/go/v5 v5.0.1
github.com/google/go-cmp v0.5.5
github.com/stretchr/testify v1.7.0
github.com/stretchr/testify v1.8.1
gotest.tools/v3 v3.1.0
pgregory.net/rapid v0.4.7
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gofrs/uuid v4.2.0+incompatible // indirect
github.com/kr/text v0.2.0 // indirect
github.com/lib/pq v1.10.4 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
22 changes: 19 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ github.com/alecthomas/repr v0.0.0-20181024024818-d37bc2a10ba1 h1:GDQdwm/gAcJcLAK
github.com/alecthomas/repr v0.0.0-20181024024818-d37bc2a10ba1/go.mod h1:xTS7Pm1pD1mvyM075QCDSRqH6qRLXylzS24ZTpRiSzQ=
github.com/cockroachdb/apd/v3 v3.1.0 h1:MK3Ow7LH0W8zkd5GMKA1PvS9qG3bWFI95WaVNfyZJ/w=
github.com/cockroachdb/apd/v3 v3.1.0/go.mod h1:6qgPBMXjATAdD/VefbRP9NoSLKjbB4LCoA7gN4LpHs4=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/cucumber/common/gherkin/go/v22 v22.0.0 h1:4K8NqptbvdOrjL9DEea6HFjSpbdT9+Q5kgLpmmsHYl0=
github.com/cucumber/common/gherkin/go/v22 v22.0.0/go.mod h1:3mJT10B2GGn3MvVPd3FwR7m2u4tLhSRhWUqJU4KN4Fg=
github.com/cucumber/common/messages/go/v17 v17.1.1 h1:RNqopvIFyLWnKv0LfATh34SWBhXeoFTJnSrgm9cT/Ts=
github.com/cucumber/common/messages/go/v17 v17.1.1/go.mod h1:bpGxb57tDE385Rb2EohgUadLkAbhoC4IyCFi89u/JQI=
github.com/cucumber/tag-expressions/go/v5 v5.0.1 h1:ECMVXw8XECJqSWY6UrpMubsG3LZcQmI4ekCVmhia/E8=
github.com/cucumber/tag-expressions/go/v5 v5.0.1/go.mod h1:O6ISvjl7N4d1lSBGV4XjS9+9RI3ZwiY/i6vDhomjYQQ=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand All @@ -16,6 +19,12 @@ github.com/gofrs/uuid v4.2.0+incompatible h1:yyYWMnhkhrKwwr8gAOcOCYxOOscHgDS9yZg
github.com/gofrs/uuid v4.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs=
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/lib/pq v1.10.4 h1:SO9z7FRPzA03QhHKJrH5BXA6HU1rS4V2nIVrrNC1iYk=
github.com/lib/pq v1.10.4/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand All @@ -25,9 +34,14 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
Expand All @@ -52,11 +66,13 @@ golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8T
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools/v3 v3.1.0 h1:rVV8Tcg/8jHUkPUorwjaMTtemIMVXfIPKiOqnhEhakk=
gotest.tools/v3 v3.1.0/go.mod h1:fHy7eyTmJFO5bQbUsEGQ1v4m2J3Jz9eWL54TP2/ZuYQ=
pgregory.net/rapid v0.4.7 h1:MTNRktPuv5FNqOO151TM9mDTa+XHcX6ypYeISDVD14g=
Expand Down
106 changes: 0 additions & 106 deletions internal/tag/expr.go

This file was deleted.

33 changes: 24 additions & 9 deletions internal/tag/tags.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,36 @@
package tag

import "github.com/cucumber/common/messages/go/v17"

type Tags map[string]bool
import (
messages "github.com/cucumber/common/messages/go/v17"
tag "github.com/cucumber/tag-expressions/go/v5"
)

func NewTags(tags ...string) Tags {
res := map[string]bool{}
for _, tag := range tags {
res[tag] = true
have := map[string]bool{}
var res []string
for _, t := range tags {
if !have[t] {
have[t] = true
res = append(res, t)
}
}
return res
}

func NewTagsFromPickleTags(pickleTags []*messages.PickleTag) Tags {
res := map[string]bool{}
for _, tag := range pickleTags {
res[tag.Name] = true
have := map[string]bool{}
var res []string
for _, t := range pickleTags {
if !have[t.Name] {
have[t.Name] = true
res = append(res, t.Name)
}
}
return res
}

type Tags []string

func (t Tags) Match(expr tag.Evaluatable) bool {
return expr.Evaluate(t)
}
14 changes: 8 additions & 6 deletions run_scenario.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
package gocuke

import (
"github.com/cucumber/common/messages/go/v17"
"github.com/regen-network/gocuke/internal/tag"
"pgregory.net/rapid"
"reflect"
"testing"

"github.com/cucumber/common/messages/go/v17"
"pgregory.net/rapid"

"github.com/regen-network/gocuke/internal/tag"
)

func (r *docRunner) runScenario(t *testing.T, pickle *messages.Pickle) {
t.Helper()

tags := tag.NewTagsFromPickleTags(pickle.Tags)
if r.tagExpr != nil && !r.tagExpr.Match(tags) {
if r.tagExpr != nil && !tags.Match(r.tagExpr) {
t.SkipNow()
}

if testing.Short() {
if r.shortTagExpr != nil && !r.shortTagExpr.Match(tags) {
if r.shortTagExpr != nil && !tags.Match(r.shortTagExpr) {
t.SkipNow()
}
}

if globalTagExpr != nil {
if !globalTagExpr.Match(tags) {
if !tags.Match(globalTagExpr) {
t.SkipNow()
}
}
Expand Down
11 changes: 6 additions & 5 deletions runner.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package gocuke

import (
"github.com/cucumber/common/messages/go/v17"
"github.com/regen-network/gocuke/internal/tag"
"pgregory.net/rapid"
"reflect"
"testing"

"github.com/cucumber/common/messages/go/v17"
tag "github.com/cucumber/tag-expressions/go/v5"
"pgregory.net/rapid"
)

// Runner is a test runner.
Expand All @@ -24,8 +25,8 @@ type Runner struct {
beforeStepHooks []*stepDef
afterStepHooks []*stepDef
suiteUsesRapid bool
tagExpr *tag.Expr
shortTagExpr *tag.Expr
tagExpr tag.Evaluatable
shortTagExpr tag.Evaluatable
}

type suiteInjector struct {
Expand Down
13 changes: 7 additions & 6 deletions tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@ package gocuke
import (
"flag"
"fmt"
"github.com/regen-network/gocuke/internal/tag"

tag "github.com/cucumber/tag-expressions/go/v5"
)

var flagTags = flag.String("gocuke.tags", "",
"specify a cucumber tags expression to select tests to run (ex. 'not @long')")

var globalTagExpr *tag.Expr
var globalTagExpr tag.Evaluatable

func initGlobalTagExpr() *tag.Expr {
func initGlobalTagExpr() tag.Evaluatable {
if globalTagExpr == nil {
if flagTags != nil && *flagTags != "" {
var err error
globalTagExpr, err = tag.ParseExpr(*flagTags)
globalTagExpr, err = tag.Parse(*flagTags)
if err != nil {
if err != nil {
panic(fmt.Errorf("error parsing tag expression %q: %v\n", *flagTags, err))
Expand All @@ -32,7 +33,7 @@ func initGlobalTagExpr() *tag.Expr {
// in parentheses to allow expressions like "(@smoke or @ui) and (not @slow)".
func (r *Runner) Tags(tagExpr string) *Runner {
var err error
r.tagExpr, err = tag.ParseExpr(tagExpr)
r.tagExpr, err = tag.Parse(tagExpr)
if err != nil {
r.topLevelT.Fatalf("error parsing tag expression %s: %v", tagExpr, err)
}
Expand All @@ -44,7 +45,7 @@ func (r *Runner) Tags(tagExpr string) *Runner {
// any other tag expression that is applied with Tags() when running short tests.
func (r *Runner) ShortTags(tagExpr string) *Runner {
var err error
r.shortTagExpr, err = tag.ParseExpr(tagExpr)
r.shortTagExpr, err = tag.Parse(tagExpr)
if err != nil {
r.topLevelT.Fatalf("error parsing tag expression %s: %v", tagExpr, err)
}
Expand Down
13 changes: 8 additions & 5 deletions tags_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package gocuke

import (
"github.com/regen-network/gocuke/internal/tag"
"gotest.tools/v3/assert"
"strings"
"testing"

tagexpressions "github.com/cucumber/tag-expressions/go/v5"
"gotest.tools/v3/assert"

"github.com/regen-network/gocuke/internal/tag"
)

func TestTags(t *testing.T) {
Expand All @@ -13,7 +16,7 @@ func TestTags(t *testing.T) {

type tagsSuite struct {
TestingT
expr *tag.Expr
expr tagexpressions.Evaluatable
tags []string
}

Expand All @@ -31,7 +34,7 @@ func (s *tagsSuite) IEatOtherCukes() {

func (s *tagsSuite) TheTagExpression(a DocString) {
var err error
s.expr, err = tag.ParseExpr(a.Content)
s.expr, err = tagexpressions.Parse(a.Content)
assert.NilError(s, err, a.Content)
}

Expand All @@ -40,7 +43,7 @@ func (s *tagsSuite) IMatch(a string) {
}

func (s *tagsSuite) TheResultIs(a string) {
res := s.expr.Match(tag.NewTags(s.tags...))
res := tag.NewTags(s.tags...).Match(s.expr)
switch a {
case "true":
assert.Assert(s, res)
Expand Down