Skip to content

Commit

Permalink
Showing 2 changed files with 45 additions and 9 deletions.
30 changes: 30 additions & 0 deletions run_test.go
Original file line number Diff line number Diff line change
@@ -245,3 +245,33 @@ func bufErrorPipe(t *testing.T) (io.ReadCloser, func()) {
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 changes: 15 additions & 9 deletions suite.go
Original file line number Diff line number Diff line change
@@ -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) {
byPath := make(map[string]*feature)
var order int
for _, pat := range paths {
// check if line number is specified
parts := strings.Split(pat, ":")
path := parts[0]
line := -1
path, line := extractFeaturePathLine(pat)
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
err = filepath.Walk(path, func(p string, f os.FileInfo, err error) error {
if err == nil && !f.IsDir() && strings.HasSuffix(p, ".feature") {

0 comments on commit ee4ee47

Please sign in to comment.