1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
// Copyright 2020 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package benchmark
import (
"testing"
)
func TestMakeBenchString(t *testing.T) {
tests := []struct {
have, want string
}{
{"foo", "BenchmarkFoo"},
{" foo ", "BenchmarkFoo"},
{"foo bar", "BenchmarkFooBar"},
}
for i, test := range tests {
if v := makeBenchString(test.have); test.want != v {
t.Errorf("test[%d] makeBenchString(%q) == %q, want %q", i, test.have, v, test.want)
}
}
}
func TestPProfFlag(t *testing.T) {
tests := []struct {
name string
want bool
}{
{"", false},
{"foo", true},
}
for i, test := range tests {
b := New(GC, test.name)
if v := b.shouldPProf(); test.want != v {
t.Errorf("test[%d] shouldPProf() == %v, want %v", i, v, test.want)
}
}
}
func TestPProfNames(t *testing.T) {
want := "foo_BenchmarkTest.cpuprof"
if v := makePProfFilename("foo", "test", "cpuprof"); v != want {
t.Errorf("makePProfFilename() == %q, want %q", v, want)
}
}
// Ensure that public APIs work with a nil Metrics object.
func TestNilBenchmarkObject(t *testing.T) {
var b *Metrics
b.Start("TEST")
b.Report(nil)
}
|