Skip to content

Commit 929a212

Browse files
authored
Merge pull request #1758 from stretchr/dolmen/suite-faster-method-filtering
suite: faster methods filtering (internal refactor)
2 parents c58bc90 + bc7459e commit 929a212

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

suite/suite.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"reflect"
88
"regexp"
99
"runtime/debug"
10+
"strings"
1011
"sync"
1112
"testing"
1213
"time"
@@ -137,16 +138,24 @@ func Run(t *testing.T, suite TestingSuite) {
137138
methodFinder := reflect.TypeOf(suite)
138139
suiteName := methodFinder.Elem().Name()
139140

140-
for i := 0; i < methodFinder.NumMethod(); i++ {
141-
method := methodFinder.Method(i)
142-
143-
ok, err := methodFilter(method.Name)
141+
var matchMethodRE *regexp.Regexp
142+
if *matchMethod != "" {
143+
var err error
144+
matchMethodRE, err = regexp.Compile(*matchMethod)
144145
if err != nil {
145146
fmt.Fprintf(os.Stderr, "testify: invalid regexp for -m: %s\n", err)
146147
os.Exit(1)
147148
}
149+
}
150+
151+
for i := 0; i < methodFinder.NumMethod(); i++ {
152+
method := methodFinder.Method(i)
148153

149-
if !ok {
154+
if !strings.HasPrefix(method.Name, "Test") {
155+
continue
156+
}
157+
// Apply -testify.m filter
158+
if matchMethodRE != nil && !matchMethodRE.MatchString(method.Name) {
150159
continue
151160
}
152161

@@ -216,15 +225,6 @@ func Run(t *testing.T, suite TestingSuite) {
216225
runTests(t, tests)
217226
}
218227

219-
// Filtering method according to set regular expression
220-
// specified command-line argument -m
221-
func methodFilter(name string) (bool, error) {
222-
if ok, _ := regexp.MatchString("^Test", name); !ok {
223-
return false, nil
224-
}
225-
return regexp.MatchString(*matchMethod, name)
226-
}
227-
228228
func runTests(t *testing.T, tests []test) {
229229
if len(tests) == 0 {
230230
t.Log("warning: no tests to run")

0 commit comments

Comments
 (0)