Fix -test.run test selection with gotestmain
matchString was implemented separately on older go versions since they didn't want a build dependency on the regex package from the testing package. Starting in Go 1.8, this is implemented using a internal package to break the dependency, but until we require that everywhere, just copy the regex implementation like the old `go test` did. I'm not sure we'll be able to use the internal package in the future anyways. Change-Id: Ief37542640026f9d73a75fd802f2691af50e2511
This commit is contained in:
parent
e8a33ee623
commit
10e4357dbb
1 changed files with 13 additions and 2 deletions
|
@ -85,6 +85,7 @@ var testMainTmpl = template.Must(template.New("testMain").Parse(`
|
|||
package main
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
pkg "{{.Package}}"
|
||||
|
@ -96,8 +97,18 @@ var t = []testing.InternalTest{
|
|||
{{end}}
|
||||
}
|
||||
|
||||
func matchString(pat, str string) (bool, error) {
|
||||
return true, nil
|
||||
var matchPat string
|
||||
var matchRe *regexp.Regexp
|
||||
|
||||
func matchString(pat, str string) (result bool, err error) {
|
||||
if matchRe == nil || matchPat != pat {
|
||||
matchPat = pat
|
||||
matchRe, err = regexp.Compile(matchPat)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
return matchRe.MatchString(str), nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
|
Loading…
Reference in a new issue