forked from regen-network/gocuke
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.go
87 lines (71 loc) · 2.08 KB
/
run.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package gocuke
import (
"os"
"reflect"
"strings"
"testing"
"github.com/bmatcuk/doublestar/v4"
gherkin "github.com/cucumber/gherkin/go/v27"
"gotest.tools/v3/assert"
)
// Run runs the features registered with the runner.
func (r *Runner) Run() {
r.topLevelT.Helper()
paths := r.paths
if len(paths) == 0 {
paths = []string{"features/**/*.feature"}
}
haveTests := false
for _, path := range paths {
var files []string
// use glob paths if we have a * in the path
// if we don't have a glob just check the path directly
// not doing this allows mis-spellings in exact paths to be skipped silently
if strings.Contains(path, "*") {
var err error
files, err = doublestar.FilepathGlob(path)
assert.NilError(r.topLevelT, err)
} else {
files = []string{path}
}
for _, file := range files {
f, err := os.Open(file) //nolint:gosec,EXC0010
assert.NilError(r.topLevelT, err)
haveTests = true
doc, err := gherkin.ParseGherkinDocument(f, r.incr.NewId)
assert.NilError(r.topLevelT, err)
r.topLevelT.Run(doc.Feature.Name, func(t *testing.T) {
t.Helper()
if r.parallel {
t.Parallel()
}
(newDocRunner(r, doc)).runDoc(t)
})
if err = f.Close(); err != nil {
panic(err)
}
}
}
if len(r.suggestions) != 0 {
var suiteTypeName string
if r.suiteType.Kind() == reflect.Ptr {
suiteTypeName = "*" + r.suiteType.Elem().Name()
} else {
suiteTypeName = r.suiteType.Name()
}
suggestionText := "Missing step definitions can be fixed with the following methods:\n"
for _, sig := range r.suggestions {
suggestionText += sig.methodSuggestion(suiteTypeName) + "\n\n"
}
suggestionText += "Steps can be manually registered with the runner for customization using this code:\n"
for _, sig := range r.suggestions {
suggestionText += " " + sig.stepSuggestion(suiteTypeName) + ".\n"
}
suggestionText += "\n\n"
suggestionText += "See https://github.com/regen-network/gocuke for further customization options."
r.topLevelT.Logf(suggestionText)
}
if !haveTests {
r.topLevelT.Fatalf("no tests found in paths: %v", r.paths)
}
}