launchpad.net/gocheck@v0.0.0-20140225173054-000000000087/benchmark_test.go (about)

     1  // These tests verify the test running logic.
     2  
     3  package gocheck_test
     4  
     5  import (
     6  	. "launchpad.net/gocheck"
     7  	"time"
     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: gocheck_test\\.go:[0-9]+: FixtureHelper\\.Test1\t0\\.001s\n" +
    25  		"PASS: gocheck_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: gocheck_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: gocheck_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: gocheck_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  }