Добавлена поддержка focused-тестов во множестве feature-файлов
Этот коммит содержится в:
родитель
4fecb1bba8
коммит
1a7826f87f
4 изменённых файлов: 142 добавлений и 7 удалений
|
@ -153,3 +153,47 @@ Feature: tag filters
|
|||
a feature path "three"
|
||||
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"
|
||||
"""
|
||||
|
|
|
@ -186,7 +186,7 @@ func ParseFeatures(fsys fs.FS, filter, dialect string, paths []string) ([]*model
|
|||
features[idx] = feature
|
||||
}
|
||||
|
||||
features = filterFeatures(filter, features)
|
||||
features = FilterFeatures(filter, features)
|
||||
|
||||
return features, nil
|
||||
}
|
||||
|
@ -225,19 +225,61 @@ func ParseFromBytes(filter, dialect string, featuresInputs []FeatureContent) ([]
|
|||
features[idx] = feature
|
||||
}
|
||||
|
||||
features = filterFeatures(filter, features)
|
||||
features = FilterFeatures(filter, features)
|
||||
|
||||
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 {
|
||||
ft.Pickles = tags.ApplyTagFilter(filter, ft.Pickles)
|
||||
|
||||
if containsFocusedPickle(ft.Pickles) {
|
||||
focused = true
|
||||
}
|
||||
|
||||
if ft.Feature != nil && len(ft.Pickles) > 0 {
|
||||
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
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/cucumber/godog/internal/parser"
|
||||
"github.com/cucumber/messages-go/v16"
|
||||
)
|
||||
|
||||
func Test_FeatureFilePathParser(t *testing.T) {
|
||||
|
@ -307,3 +308,54 @@ Funksie: dummy
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@ import (
|
|||
"github.com/cucumber/godog/internal/models"
|
||||
"github.com/cucumber/godog/internal/parser"
|
||||
"github.com/cucumber/godog/internal/storage"
|
||||
"github.com/cucumber/godog/internal/tags"
|
||||
"github.com/cucumber/godog/internal/utils"
|
||||
)
|
||||
|
||||
|
@ -275,9 +274,7 @@ func (tc *godogFeaturesScenario) iRunFeatureSuiteWithTagsAndFormatter(filter str
|
|||
return err
|
||||
}
|
||||
|
||||
for _, feat := range tc.features {
|
||||
feat.Pickles = tags.ApplyTagFilter(filter, feat.Pickles)
|
||||
}
|
||||
tc.features = parser.FilterFeatures(filter, tc.features)
|
||||
|
||||
tc.testedSuite.storage = storage.NewStorage()
|
||||
for _, feat := range tc.features {
|
||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче