diff options
| author | Marcel van Lohuizen <mpvl@golang.org> | 2016-01-29 16:57:02 +0100 |
|---|---|---|
| committer | Marcel van Lohuizen <mpvl@golang.org> | 2016-03-22 14:47:39 +0000 |
| commit | 00a2a94c1eab027bc1ac5bbb9f30329dec14cf87 (patch) | |
| tree | 91d97c16e311a62de0c3ffad2eed26bd23a63689 /src/testing/testing.go | |
| parent | 34699bc7a81668f3a3d7b0f862e0a9f173926c66 (diff) | |
| download | go-00a2a94c1eab027bc1ac5bbb9f30329dec14cf87.tar.xz | |
testing: added name matcher and sanitizer
The matcher is responsible for sanitizing and uniquing the
test and benchmark names and thus needs to be included before the
API can be exposed.
Matching currently uses the regexp to only match the top-level
tests/benchmarks.
Support for subtest matching is for another CL.
Change-Id: I7c8464068faef7ebc179b03a7fe3d01122cc4f0b
Reviewed-on: https://go-review.googlesource.com/18897
Reviewed-by: Russ Cox <rsc@golang.org>
Run-TryBot: Marcel van Lohuizen <mpvl@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/testing/testing.go')
| -rw-r--r-- | src/testing/testing.go | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/src/testing/testing.go b/src/testing/testing.go index 03a7fbfddd..5c6f16e41a 100644 --- a/src/testing/testing.go +++ b/src/testing/testing.go @@ -551,9 +551,9 @@ func tRunner(t *T, fn func(t *T)) { // run runs f as a subtest of t called name. It reports whether f succeeded. // Run will block until all its parallel subtests have completed. func (t *T) run(name string, f func(t *T)) bool { - testName := name - if t.level > 0 { - testName = t.name + "/" + name + testName, ok := t.context.match.fullName(&t.common, name) + if !ok { + return true } t = &T{ common: common{ @@ -583,6 +583,8 @@ func (t *T) run(name string, f func(t *T)) bool { // testContext holds all fields that are common to all tests. This includes // synchronization primitives to run at most *parallel tests. type testContext struct { + match *matcher + mu sync.Mutex // Channel used to signal tests that are ready to be run in parallel. @@ -599,8 +601,9 @@ type testContext struct { maxParallel int } -func newTestContext(maxParallel int) *testContext { +func newTestContext(maxParallel int, m *matcher) *testContext { return &testContext{ + match: m, startParallel: make(chan bool), maxParallel: maxParallel, running: 1, // Set the count to 1 for the main (sequential) test. @@ -707,7 +710,7 @@ func RunTests(matchString func(pat, str string) (bool, error), tests []InternalT } for _, procs := range cpuList { runtime.GOMAXPROCS(procs) - ctx := newTestContext(*parallel) + ctx := newTestContext(*parallel, newMatcher(matchString, *match, "-test.run")) t := &T{ common: common{ signal: make(chan bool), @@ -718,15 +721,6 @@ func RunTests(matchString func(pat, str string) (bool, error), tests []InternalT } tRunner(t, func(t *T) { for _, test := range tests { - // TODO: a version of this will be the Run method. - matched, err := matchString(*match, test.Name) - if err != nil { - fmt.Fprintf(os.Stderr, "testing: invalid regexp for -test.run: %s\n", err) - os.Exit(1) - } - if !matched { - continue - } t.run(test.Name, test.F) } // Run catching the signal rather than the tRunner as a separate |
