closes #160
Этот коммит содержится в:
родитель
331dcaec1a
коммит
ee4ee478e2
2 изменённых файлов: 45 добавлений и 9 удалений
30
run_test.go
30
run_test.go
|
@ -245,3 +245,33 @@ func bufErrorPipe(t *testing.T) (io.ReadCloser, func()) {
|
||||||
os.Stderr = stderr
|
os.Stderr = stderr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestFeatureFilePathParser(t *testing.T) {
|
||||||
|
|
||||||
|
type Case struct {
|
||||||
|
input string
|
||||||
|
path string
|
||||||
|
line int
|
||||||
|
}
|
||||||
|
|
||||||
|
cases := []Case{
|
||||||
|
{"/home/test.feature", "/home/test.feature", -1},
|
||||||
|
{"/home/test.feature:21", "/home/test.feature", 21},
|
||||||
|
{"test.feature", "test.feature", -1},
|
||||||
|
{"test.feature:2", "test.feature", 2},
|
||||||
|
{"", "", -1},
|
||||||
|
{"/c:/home/test.feature", "/c:/home/test.feature", -1},
|
||||||
|
{"/c:/home/test.feature:3", "/c:/home/test.feature", 3},
|
||||||
|
{"D:\\home\\test.feature:3", "D:\\home\\test.feature", 3},
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, c := range cases {
|
||||||
|
p, ln := extractFeaturePathLine(c.input)
|
||||||
|
if p != c.path {
|
||||||
|
t.Fatalf(`result path "%s" != "%s" at %d`, p, c.path, i)
|
||||||
|
}
|
||||||
|
if ln != c.line {
|
||||||
|
t.Fatalf(`result line "%d" != "%d" at %d`, ln, c.line, i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
24
suite.go
24
suite.go
|
@ -617,21 +617,27 @@ func (s *Suite) printStepDefinitions(w io.Writer) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var pathLineRe = regexp.MustCompile(`:([\d]+)$`)
|
||||||
|
|
||||||
|
func extractFeaturePathLine(p string) (string, int) {
|
||||||
|
line := -1
|
||||||
|
retPath := p
|
||||||
|
if m := pathLineRe.FindStringSubmatch(p); len(m) > 0 {
|
||||||
|
if i, err := strconv.Atoi(m[1]); err == nil {
|
||||||
|
line = i
|
||||||
|
retPath = p[:strings.LastIndexByte(p, ':')]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retPath, line
|
||||||
|
}
|
||||||
|
|
||||||
func parseFeatures(filter string, paths []string) ([]*feature, error) {
|
func parseFeatures(filter string, paths []string) ([]*feature, error) {
|
||||||
byPath := make(map[string]*feature)
|
byPath := make(map[string]*feature)
|
||||||
var order int
|
var order int
|
||||||
for _, pat := range paths {
|
for _, pat := range paths {
|
||||||
// check if line number is specified
|
// check if line number is specified
|
||||||
parts := strings.Split(pat, ":")
|
path, line := extractFeaturePathLine(pat)
|
||||||
path := parts[0]
|
|
||||||
line := -1
|
|
||||||
var err error
|
var err error
|
||||||
if len(parts) > 1 {
|
|
||||||
line, err = strconv.Atoi(parts[1])
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("line number should follow after colon path delimiter")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// parse features
|
// parse features
|
||||||
err = filepath.Walk(path, func(p string, f os.FileInfo, err error) error {
|
err = filepath.Walk(path, func(p string, f os.FileInfo, err error) error {
|
||||||
if err == nil && !f.IsDir() && strings.HasSuffix(p, ".feature") {
|
if err == nil && !f.IsDir() && strings.HasSuffix(p, ".feature") {
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче