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:
Dan Willemsen 2017-01-18 14:37:13 -08:00
parent e8a33ee623
commit 10e4357dbb

View file

@ -85,6 +85,7 @@ var testMainTmpl = template.Must(template.New("testMain").Parse(`
package main package main
import ( import (
"regexp"
"testing" "testing"
pkg "{{.Package}}" pkg "{{.Package}}"
@ -96,8 +97,18 @@ var t = []testing.InternalTest{
{{end}} {{end}}
} }
func matchString(pat, str string) (bool, error) { var matchPat string
return true, nil 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() { func main() {