Skip to content

Commit ee4ee47

Browse files
committed
closes #160
1 parent 331dcae commit ee4ee47

File tree

2 files changed

+45
-9
lines changed

2 files changed

+45
-9
lines changed

run_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,3 +245,33 @@ func bufErrorPipe(t *testing.T) (io.ReadCloser, func()) {
245245
os.Stderr = stderr
246246
}
247247
}
248+
249+
func TestFeatureFilePathParser(t *testing.T) {
250+
251+
type Case struct {
252+
input string
253+
path string
254+
line int
255+
}
256+
257+
cases := []Case{
258+
{"/home/test.feature", "/home/test.feature", -1},
259+
{"/home/test.feature:21", "/home/test.feature", 21},
260+
{"test.feature", "test.feature", -1},
261+
{"test.feature:2", "test.feature", 2},
262+
{"", "", -1},
263+
{"/c:/home/test.feature", "/c:/home/test.feature", -1},
264+
{"/c:/home/test.feature:3", "/c:/home/test.feature", 3},
265+
{"D:\\home\\test.feature:3", "D:\\home\\test.feature", 3},
266+
}
267+
268+
for i, c := range cases {
269+
p, ln := extractFeaturePathLine(c.input)
270+
if p != c.path {
271+
t.Fatalf(`result path "%s" != "%s" at %d`, p, c.path, i)
272+
}
273+
if ln != c.line {
274+
t.Fatalf(`result line "%d" != "%d" at %d`, ln, c.line, i)
275+
}
276+
}
277+
}

suite.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -617,21 +617,27 @@ func (s *Suite) printStepDefinitions(w io.Writer) {
617617
}
618618
}
619619

620+
var pathLineRe = regexp.MustCompile(`:([\d]+)$`)
621+
622+
func extractFeaturePathLine(p string) (string, int) {
623+
line := -1
624+
retPath := p
625+
if m := pathLineRe.FindStringSubmatch(p); len(m) > 0 {
626+
if i, err := strconv.Atoi(m[1]); err == nil {
627+
line = i
628+
retPath = p[:strings.LastIndexByte(p, ':')]
629+
}
630+
}
631+
return retPath, line
632+
}
633+
620634
func parseFeatures(filter string, paths []string) ([]*feature, error) {
621635
byPath := make(map[string]*feature)
622636
var order int
623637
for _, pat := range paths {
624638
// check if line number is specified
625-
parts := strings.Split(pat, ":")
626-
path := parts[0]
627-
line := -1
639+
path, line := extractFeaturePathLine(pat)
628640
var err error
629-
if len(parts) > 1 {
630-
line, err = strconv.Atoi(parts[1])
631-
if err != nil {
632-
return nil, fmt.Errorf("line number should follow after colon path delimiter")
633-
}
634-
}
635641
// parse features
636642
err = filepath.Walk(path, func(p string, f os.FileInfo, err error) error {
637643
if err == nil && !f.IsDir() && strings.HasSuffix(p, ".feature") {

0 commit comments

Comments
 (0)