Добавлена поддержка focused-тестов во множестве feature-файлов
Этот коммит содержится в:
родитель
3f03171dab
коммит
6c3e2a2103
4 изменённых файлов: 141 добавлений и 6 удалений
|
@ -153,3 +153,47 @@ Feature: tag filters
|
||||||
a feature path "three"
|
a feature path "three"
|
||||||
a feature path "four"
|
a feature path "four"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
Scenario: two feature files 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"
|
||||||
|
"""
|
||||||
|
And a feature "another.feature" file:
|
||||||
|
"""
|
||||||
|
Feature: non-tagged
|
||||||
|
|
||||||
|
Scenario: five
|
||||||
|
Given a feature path "five"
|
||||||
|
|
||||||
|
Scenario: six
|
||||||
|
Given a feature path "six"
|
||||||
|
|
||||||
|
Scenario: seven
|
||||||
|
Given a feature path "seven"
|
||||||
|
|
||||||
|
Scenario: eight
|
||||||
|
Given a feature path "eight"
|
||||||
|
"""
|
||||||
|
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"
|
||||||
|
"""
|
||||||
|
|
|
@ -157,19 +157,61 @@ func ParseFeatures(filter string, paths []string) ([]*models.Feature, error) {
|
||||||
features[idx] = feature
|
features[idx] = feature
|
||||||
}
|
}
|
||||||
|
|
||||||
features = filterFeatures(filter, features)
|
features = FilterFeatures(filter, features)
|
||||||
|
|
||||||
return features, nil
|
return features, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func filterFeatures(filter string, features []*models.Feature) (result []*models.Feature) {
|
func FilterFeatures(filter string, features []*models.Feature) (result []*models.Feature) {
|
||||||
|
focused := false
|
||||||
|
|
||||||
for _, ft := range features {
|
for _, ft := range features {
|
||||||
ft.Pickles = tags.ApplyTagFilter(filter, ft.Pickles)
|
ft.Pickles = tags.ApplyTagFilter(filter, ft.Pickles)
|
||||||
|
|
||||||
|
if containsFocusedPickle(ft.Pickles) {
|
||||||
|
focused = true
|
||||||
|
}
|
||||||
|
|
||||||
if ft.Feature != nil && len(ft.Pickles) > 0 {
|
if ft.Feature != nil && len(ft.Pickles) > 0 {
|
||||||
result = append(result, ft)
|
result = append(result, ft)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !focused {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var resultF []*models.Feature
|
||||||
|
for _, ft := range result {
|
||||||
|
ft.Pickles = filterFocusedPickles(ft.Pickles)
|
||||||
|
resultF = append(resultF, ft)
|
||||||
|
}
|
||||||
|
|
||||||
|
return resultF
|
||||||
|
}
|
||||||
|
|
||||||
|
func containsFocusedPickle(pickles []*messages.Pickle) bool {
|
||||||
|
for _, p := range pickles {
|
||||||
|
if containsFocusedTag(p.Tags) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
func containsFocusedTag(tags []*messages.PickleTag) bool {
|
||||||
|
for _, t := range tags {
|
||||||
|
if t.Name == "@f" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func filterFocusedPickles(pickles []*messages.Pickle) (result []*messages.Pickle) {
|
||||||
|
for _, p := range pickles {
|
||||||
|
if containsFocusedTag(p.Tags) {
|
||||||
|
result = append(result, p)
|
||||||
|
}
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/cucumber/godog/internal/parser"
|
"github.com/cucumber/godog/internal/parser"
|
||||||
|
"github.com/cucumber/messages-go/v16"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_FeatureFilePathParser(t *testing.T) {
|
func Test_FeatureFilePathParser(t *testing.T) {
|
||||||
|
@ -77,3 +78,54 @@ func Test_ParseFeatures_FromMultiplePaths(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_FilterF_Features_FromMultipleFiles(t *testing.T) {
|
||||||
|
const featureFileName = "godogs.feature"
|
||||||
|
const featureFileContentsF = `Feature: focused
|
||||||
|
|
||||||
|
@f
|
||||||
|
Scenario: Focused
|
||||||
|
Given something
|
||||||
|
When do
|
||||||
|
Then ok`
|
||||||
|
|
||||||
|
const featureFileContentsNormal = `Feature: normal
|
||||||
|
Scenario: normal
|
||||||
|
Given something
|
||||||
|
When do
|
||||||
|
Then ok`
|
||||||
|
|
||||||
|
baseDir := filepath.Join(os.TempDir(), t.Name(), "godogs")
|
||||||
|
errA := os.MkdirAll(baseDir+"/a", 0755)
|
||||||
|
errB := os.MkdirAll(baseDir+"/b", 0755)
|
||||||
|
defer os.RemoveAll(baseDir)
|
||||||
|
|
||||||
|
require.Nil(t, errA)
|
||||||
|
require.Nil(t, errB)
|
||||||
|
|
||||||
|
err := ioutil.WriteFile(filepath.Join(baseDir+"/a", featureFileName), []byte(featureFileContentsF), 0644)
|
||||||
|
require.Nil(t, err)
|
||||||
|
err = ioutil.WriteFile(filepath.Join(baseDir+"/b", featureFileName), []byte(featureFileContentsNormal), 0644)
|
||||||
|
require.Nil(t, err)
|
||||||
|
|
||||||
|
features, err := parser.ParseFeatures("", []string{baseDir + "/a", baseDir + "/b"})
|
||||||
|
assert.Nil(t, err)
|
||||||
|
assert.Len(t, features, 2)
|
||||||
|
|
||||||
|
for _, f := range features {
|
||||||
|
for _, p := range f.Pickles {
|
||||||
|
if !containsFocusedTag(p.Tags) {
|
||||||
|
assert.Failf(t, "found not Focused pickle", "Found not Focused pickle", p.Tags)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func containsFocusedTag(tags []*messages.PickleTag) bool {
|
||||||
|
for _, t := range tags {
|
||||||
|
if t.Name == "@f" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
|
@ -21,7 +21,6 @@ import (
|
||||||
"github.com/cucumber/godog/internal/models"
|
"github.com/cucumber/godog/internal/models"
|
||||||
"github.com/cucumber/godog/internal/parser"
|
"github.com/cucumber/godog/internal/parser"
|
||||||
"github.com/cucumber/godog/internal/storage"
|
"github.com/cucumber/godog/internal/storage"
|
||||||
"github.com/cucumber/godog/internal/tags"
|
|
||||||
"github.com/cucumber/godog/internal/utils"
|
"github.com/cucumber/godog/internal/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -233,9 +232,7 @@ func (tc *godogFeaturesScenario) iRunFeatureSuiteWithTagsAndFormatter(filter str
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, feat := range tc.features {
|
tc.features = parser.FilterFeatures(filter, tc.features)
|
||||||
feat.Pickles = tags.ApplyTagFilter(filter, feat.Pickles)
|
|
||||||
}
|
|
||||||
|
|
||||||
tc.testedSuite.storage = storage.NewStorage()
|
tc.testedSuite.storage = storage.NewStorage()
|
||||||
for _, feat := range tc.features {
|
for _, feat := range tc.features {
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче