From 3f03171dabba01e59298d3a1ade52b0f853c3ed0 Mon Sep 17 00:00:00 2001 From: Softonik Date: Mon, 22 Aug 2022 14:00:00 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BF=D0=BE=D0=B4=D0=B4=D0=B5=D1=80=D0=B6=D0=BA?= =?UTF-8?q?=D0=B0=20=D1=82=D0=B5=D1=81=D1=82=D0=BE=D0=B2=20=D1=81=20f-?= =?UTF-8?q?=D1=82=D0=B5=D0=B3=D0=BE=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Magefile.go | 24 +++++++++++++++++++ features/tags.feature | 28 ++++++++++++++++++++++ internal/tags/tag_filter.go | 17 ++++++++++++++ internal/tags/tag_filter_f_test.go | 37 ++++++++++++++++++++++++++++++ 4 files changed, 106 insertions(+) create mode 100644 internal/tags/tag_filter_f_test.go diff --git a/Magefile.go b/Magefile.go index 43f96fa..ab3c0a1 100644 --- a/Magefile.go +++ b/Magefile.go @@ -64,6 +64,30 @@ func TestSnippets() { '`) } +func TestTags() { + Bash(`sudo docker run -ti --rm \ + -h host \ + --net=bridge \ + -v /etc/localtime:/etc/localtime:ro \ + -v ` + GolangVolume + `:/usr/local/go:ro \ + \ + -v /gopath:/gopath:rw \ + -v ${PWD}:/app \ + \ + -e GOPATH=/gopath \ + -e GOCACHE=/gopath/gocache \ + \ + -w /app \ + -u 1000 \ + \ + --entrypoint=/bin/bash \ + \ + ` + ImageName + " -c '" + `set -x; \ + godog run -f progress -c 4 \ + features/tags.feature \ + '`) +} + func Install() { Bash(`sudo docker run -ti --rm \ -h host \ diff --git a/features/tags.feature b/features/tags.feature index bf182fd..0d058f3 100644 --- a/features/tags.feature +++ b/features/tags.feature @@ -125,3 +125,31 @@ Feature: tag filters """ a feature path "four" """ + + Scenario: empty filter and scenarios with f-tag - are executed only + Given a feature "normal.feature" file: + """ + Feature: f-tagged + + Scenario: one + Given a feature path "one" + + Scenario: two + Given a feature path "two" + + @f + Scenario: three + Given a feature path "three" + + @f + Scenario: four + Given a feature path "four" + """ + When I run feature suite with tags "" + Then the suite should have passed + And I should have 2 scenario registered + And the following steps should be passed: + """ + a feature path "three" + a feature path "four" + """ diff --git a/internal/tags/tag_filter.go b/internal/tags/tag_filter.go index 06801b2..e4c8417 100644 --- a/internal/tags/tag_filter.go +++ b/internal/tags/tag_filter.go @@ -10,6 +10,11 @@ import ( // array of pickles and returned the filtered list. func ApplyTagFilter(filter string, pickles []*messages.Pickle) []*messages.Pickle { if filter == "" { + ff := filterF(pickles) + if len(ff) > 0 { + return ff + } + return pickles } @@ -60,3 +65,15 @@ func contains(tags []*messages.PickleTag, tag string) bool { return false } + +func filterF(pickles []*messages.Pickle) []*messages.Pickle { + var result = []*messages.Pickle{} + + for _, pickle := range pickles { + if contains(pickle.Tags, "f") { + result = append(result, pickle) + } + } + + return result +} diff --git a/internal/tags/tag_filter_f_test.go b/internal/tags/tag_filter_f_test.go new file mode 100644 index 0000000..ce73550 --- /dev/null +++ b/internal/tags/tag_filter_f_test.go @@ -0,0 +1,37 @@ +package tags_test + +import ( + "testing" + + "github.com/stretchr/testify/assert" + + "github.com/cucumber/godog/internal/tags" +) + +type testcaseF struct { + filter string + input []*pickle + expected []*pickle +} + +var testdataNonF = []*pickle{p1n, p2n, p3n} +var testdataF = []*pickle{p1n, p2n, p3withF} +var p1n = &pickle{Id: "one", Tags: []*tag{}} +var p2n = &pickle{Id: "two", Tags: []*tag{{Name: "@wip"}}} +var p3n = &pickle{Id: "three", Tags: []*tag{}} +var p3withF = &pickle{Id: "three", Tags: []*tag{{Name: "@f"}}} + +var testcasesF = []testcaseF{ + {filter: "", input: testdataNonF, expected: testdataNonF}, + {filter: "", input: testdataF, expected: []*pickle{p3withF}}, + {filter: "@wip", input: testdataF, expected: []*pickle{p2n}}, +} + +func Test_ApplyTagFilterWithF(t *testing.T) { + for _, tc := range testcasesF { + t.Run("", func(t *testing.T) { + actual := tags.ApplyTagFilter(tc.filter, tc.input) + assert.Equal(t, tc.expected, actual) + }) + } +}