Этот коммит содержится в:
gedi 2015-06-25 10:13:15 +03:00
родитель 386c787135
коммит 3268237f5c
3 изменённых файлов: 67 добавлений и 15 удалений

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

@ -53,9 +53,10 @@ func usage() {
} }
// --> tags // --> tags
fmt.Println(opt("-t, --tags", "Filter scenarios by tags. Expression can be:")) fmt.Println(opt("-t, --tags", "Filter scenarios by tags. Expression can be:"))
fmt.Println(opt("", s(4)+"- "+cl(`"wip"`, yellow)+": run all scenarios with wip tag")) fmt.Println(opt("", s(4)+"- "+cl(`"@wip"`, yellow)+": run all scenarios with wip tag"))
fmt.Println(opt("", s(4)+"- "+cl(`"!wip"`, yellow)+": exclude all scenarios with wip tag")) fmt.Println(opt("", s(4)+"- "+cl(`"~@wip"`, yellow)+": exclude all scenarios with wip tag"))
fmt.Println(opt("", s(4)+"- "+cl(`"wip !new"`, yellow)+": run wip scenarios, but exclude new")) fmt.Println(opt("", s(4)+"- "+cl(`"@wip && ~@new"`, yellow)+": run wip scenarios, but exclude new"))
fmt.Println(opt("", s(4)+"- "+cl(`"@wip,@undone"`, yellow)+": run wip or undone scenarios"))
// --> stop on failure // --> stop on failure
fmt.Println(opt("--stop-on-failure", "Stop processing on first failed scenario.")) fmt.Println(opt("--stop-on-failure", "Stop processing on first failed scenario."))
// --> version // --> version

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

@ -477,20 +477,30 @@ func (s *suite) applyTagFilter(ft *gherkin.Feature) {
return return
} }
for _, tag := range strings.Split(s.tags, " ") { var scenarios []*gherkin.Scenario
var scenarios []*gherkin.Scenario for _, scenario := range ft.Scenarios {
var inverse bool if s.matchesTags(scenario.Tags) {
if tag[0] == '!' { scenarios = append(scenarios, scenario)
tag = tag[1:]
inverse = true
} }
for _, scenario := range ft.Scenarios { }
if inverse && !scenario.Tags.Has(gherkin.Tag(tag)) { ft.Scenarios = scenarios
scenarios = append(scenarios, scenario) }
} else if !inverse && scenario.Tags.Has(gherkin.Tag(tag)) {
scenarios = append(scenarios, scenario) // based on http://behat.readthedocs.org/en/v2.5/guides/6.cli.html#gherkin-filters
func (s *suite) matchesTags(tags gherkin.Tags) (ok bool) {
ok = true
for _, andTags := range strings.Split(s.tags, "&&") {
var okComma bool
for _, tag := range strings.Split(andTags, ",") {
tag = strings.Replace(strings.TrimSpace(tag), "@", "", -1)
if tag[0] == '~' {
tag = tag[1:]
okComma = !tags.Has(gherkin.Tag(tag)) || okComma
} else {
okComma = tags.Has(gherkin.Tag(tag)) || okComma
} }
} }
ft.Scenarios = scenarios ok = (false != okComma && ok && okComma) || false
} }
return
} }

41
tag_filter_test.go Обычный файл
Просмотреть файл

@ -0,0 +1,41 @@
package godog
import (
"testing"
"github.com/DATA-DOG/godog/gherkin"
)
func assertNotMatchesTagFilter(tags []string, filter string, t *testing.T) {
gtags := gherkin.Tags{}
for _, tag := range tags {
gtags = append(gtags, gherkin.Tag(tag))
}
s := &suite{tags: filter}
if s.matchesTags(gtags) {
t.Errorf(`expected tags: %v not to match tag filter "%s", but it did`, gtags, filter)
}
}
func assertMatchesTagFilter(tags []string, filter string, t *testing.T) {
gtags := gherkin.Tags{}
for _, tag := range tags {
gtags = append(gtags, gherkin.Tag(tag))
}
s := &suite{tags: filter}
if !s.matchesTags(gtags) {
t.Errorf(`expected tags: %v to match tag filter "%s", but it did not`, gtags, filter)
}
}
func Test_tag_filter(t *testing.T) {
assertMatchesTagFilter([]string{"wip"}, "@wip", t)
assertMatchesTagFilter([]string{}, "~@wip", t)
assertMatchesTagFilter([]string{"one", "two"}, "@two,@three", t)
assertMatchesTagFilter([]string{"one", "two"}, "@one&&@two", t)
assertMatchesTagFilter([]string{"one", "two"}, "one && two", t)
assertNotMatchesTagFilter([]string{}, "@wip", t)
assertNotMatchesTagFilter([]string{"one", "two"}, "@one&&~@two", t)
assertNotMatchesTagFilter([]string{"one", "two"}, "@one && ~@two", t)
}