~juju-qa/ubuntu/yakkety/juju/juju-1.25.8

« back to all changes in this revision

Viewing changes to src/gopkg.in/check.v1/benchmark_test.go

  • Committer: Nicholas Skaggs
  • Date: 2016-12-02 17:28:37 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161202172837-jkrbdlyjcxtrii2n
Initial commit of 1.25.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// These tests verify the test running logic.
 
2
 
 
3
package check_test
 
4
 
 
5
import (
 
6
        "time"
 
7
        . "gopkg.in/check.v1"
 
8
)
 
9
 
 
10
var benchmarkS = Suite(&BenchmarkS{})
 
11
 
 
12
type BenchmarkS struct{}
 
13
 
 
14
func (s *BenchmarkS) TestCountSuite(c *C) {
 
15
        suitesRun += 1
 
16
}
 
17
 
 
18
func (s *BenchmarkS) TestBasicTestTiming(c *C) {
 
19
        helper := FixtureHelper{sleepOn: "Test1", sleep: 1000000 * time.Nanosecond}
 
20
        output := String{}
 
21
        runConf := RunConf{Output: &output, Verbose: true}
 
22
        Run(&helper, &runConf)
 
23
 
 
24
        expected := "PASS: check_test\\.go:[0-9]+: FixtureHelper\\.Test1\t0\\.001s\n" +
 
25
                "PASS: check_test\\.go:[0-9]+: FixtureHelper\\.Test2\t0\\.000s\n"
 
26
        c.Assert(output.value, Matches, expected)
 
27
}
 
28
 
 
29
func (s *BenchmarkS) TestStreamTestTiming(c *C) {
 
30
        helper := FixtureHelper{sleepOn: "SetUpSuite", sleep: 1000000 * time.Nanosecond}
 
31
        output := String{}
 
32
        runConf := RunConf{Output: &output, Stream: true}
 
33
        Run(&helper, &runConf)
 
34
 
 
35
        expected := "(?s).*\nPASS: check_test\\.go:[0-9]+: FixtureHelper\\.SetUpSuite\t *0\\.001s\n.*"
 
36
        c.Assert(output.value, Matches, expected)
 
37
}
 
38
 
 
39
func (s *BenchmarkS) TestBenchmark(c *C) {
 
40
        helper := FixtureHelper{sleep: 100000}
 
41
        output := String{}
 
42
        runConf := RunConf{
 
43
                Output:        &output,
 
44
                Benchmark:     true,
 
45
                BenchmarkTime: 10000000,
 
46
                Filter:        "Benchmark1",
 
47
        }
 
48
        Run(&helper, &runConf)
 
49
        c.Check(helper.calls[0], Equals, "SetUpSuite")
 
50
        c.Check(helper.calls[1], Equals, "SetUpTest")
 
51
        c.Check(helper.calls[2], Equals, "Benchmark1")
 
52
        c.Check(helper.calls[3], Equals, "TearDownTest")
 
53
        c.Check(helper.calls[4], Equals, "SetUpTest")
 
54
        c.Check(helper.calls[5], Equals, "Benchmark1")
 
55
        c.Check(helper.calls[6], Equals, "TearDownTest")
 
56
        // ... and more.
 
57
 
 
58
        expected := "PASS: check_test\\.go:[0-9]+: FixtureHelper\\.Benchmark1\t *100\t *[12][0-9]{5} ns/op\n"
 
59
        c.Assert(output.value, Matches, expected)
 
60
}
 
61
 
 
62
func (s *BenchmarkS) TestBenchmarkBytes(c *C) {
 
63
        helper := FixtureHelper{sleep: 100000}
 
64
        output := String{}
 
65
        runConf := RunConf{
 
66
                Output:        &output,
 
67
                Benchmark:     true,
 
68
                BenchmarkTime: 10000000,
 
69
                Filter:        "Benchmark2",
 
70
        }
 
71
        Run(&helper, &runConf)
 
72
 
 
73
        expected := "PASS: check_test\\.go:[0-9]+: FixtureHelper\\.Benchmark2\t *100\t *[12][0-9]{5} ns/op\t *[4-9]\\.[0-9]{2} MB/s\n"
 
74
        c.Assert(output.value, Matches, expected)
 
75
}
 
76
 
 
77
func (s *BenchmarkS) TestBenchmarkMem(c *C) {
 
78
        helper := FixtureHelper{sleep: 100000}
 
79
        output := String{}
 
80
        runConf := RunConf{
 
81
                Output:        &output,
 
82
                Benchmark:     true,
 
83
                BenchmarkMem:  true,
 
84
                BenchmarkTime: 10000000,
 
85
                Filter:        "Benchmark3",
 
86
        }
 
87
        Run(&helper, &runConf)
 
88
 
 
89
        expected := "PASS: check_test\\.go:[0-9]+: FixtureHelper\\.Benchmark3\t *100\t *[12][0-9]{5} ns/op\t *[0-9]+ B/op\t *[1-9] allocs/op\n"
 
90
        c.Assert(output.value, Matches, expected)
 
91
}