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 72b4512..29763c2 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) + }) + } +}