|
7 | 7 | "reflect" |
8 | 8 | "regexp" |
9 | 9 | "runtime/debug" |
| 10 | + "strings" |
10 | 11 | "sync" |
11 | 12 | "testing" |
12 | 13 | "time" |
@@ -137,16 +138,24 @@ func Run(t *testing.T, suite TestingSuite) { |
137 | 138 | methodFinder := reflect.TypeOf(suite) |
138 | 139 | suiteName := methodFinder.Elem().Name() |
139 | 140 |
|
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) |
144 | 145 | if err != nil { |
145 | 146 | fmt.Fprintf(os.Stderr, "testify: invalid regexp for -m: %s\n", err) |
146 | 147 | os.Exit(1) |
147 | 148 | } |
| 149 | + } |
| 150 | + |
| 151 | + for i := 0; i < methodFinder.NumMethod(); i++ { |
| 152 | + method := methodFinder.Method(i) |
148 | 153 |
|
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) { |
150 | 159 | continue |
151 | 160 | } |
152 | 161 |
|
@@ -216,15 +225,6 @@ func Run(t *testing.T, suite TestingSuite) { |
216 | 225 | runTests(t, tests) |
217 | 226 | } |
218 | 227 |
|
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 | | - |
228 | 228 | func runTests(t *testing.T, tests []test) { |
229 | 229 | if len(tests) == 0 { |
230 | 230 | t.Log("warning: no tests to run") |
|
0 commit comments