aboutsummaryrefslogtreecommitdiff
path: root/src/testing/benchmark.go
diff options
context:
space:
mode:
authorMarcel van Lohuizen <mpvl@golang.org>2016-01-29 16:57:02 +0100
committerMarcel van Lohuizen <mpvl@golang.org>2016-03-22 14:47:39 +0000
commit00a2a94c1eab027bc1ac5bbb9f30329dec14cf87 (patch)
tree91d97c16e311a62de0c3ffad2eed26bd23a63689 /src/testing/benchmark.go
parent34699bc7a81668f3a3d7b0f862e0a9f173926c66 (diff)
downloadgo-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/benchmark.go')
-rw-r--r--src/testing/benchmark.go20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/testing/benchmark.go b/src/testing/benchmark.go
index 3e85392d03..2e2e82e82e 100644
--- a/src/testing/benchmark.go
+++ b/src/testing/benchmark.go
@@ -338,6 +338,8 @@ func benchmarkName(name string, n int) string {
}
type benchContext struct {
+ match *matcher
+
maxLen int // The largest recorded benchmark name.
extLen int // Maximum extension length.
}
@@ -361,16 +363,12 @@ func runBenchmarksInternal(matchString func(pat, str string) (bool, error), benc
}
}
ctx := &benchContext{
+ match: newMatcher(matchString, *matchBenchmarks, "-test.bench"),
extLen: len(benchmarkName("", maxprocs)),
}
var bs []InternalBenchmark
for _, Benchmark := range benchmarks {
- matched, err := matchString(*matchBenchmarks, Benchmark.Name)
- if err != nil {
- fmt.Fprintf(os.Stderr, "testing: invalid regexp for -test.bench: %s\n", err)
- os.Exit(1)
- }
- if matched {
+ if _, matched := ctx.match.fullName(nil, Benchmark.Name); matched {
bs = append(bs, Benchmark)
benchName := benchmarkName(Benchmark.Name, maxprocs)
if l := len(benchName) + ctx.extLen + 1; l > ctx.maxLen {
@@ -443,13 +441,17 @@ func (b *B) runBench(name string, f func(b *B)) bool {
benchmarkLock.Unlock()
defer benchmarkLock.Lock()
- if b.level > 0 {
- name = b.name + "/" + name
+ benchName, ok := b.name, true
+ if b.context != nil {
+ benchName, ok = b.context.match.fullName(&b.common, name)
+ }
+ if !ok {
+ return true
}
sub := &B{
common: common{
signal: make(chan bool),
- name: name,
+ name: benchName,
parent: &b.common,
level: b.level + 1,
},