1// These tests verify the test running logic. 2 3package check_test 4 5import ( 6 "time" 7 . "gopkg.in/check.v1" 8) 9 10var benchmarkS = Suite(&BenchmarkS{}) 11 12type BenchmarkS struct{} 13 14func (s *BenchmarkS) TestCountSuite(c *C) { 15 suitesRun += 1 16} 17 18func (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\\.0[0-9]+s\n" + 25 "PASS: check_test\\.go:[0-9]+: FixtureHelper\\.Test2\t0\\.0[0-9]+s\n" 26 c.Assert(output.value, Matches, expected) 27} 28 29func (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-9]+\\.[0-9]+s\n.*" 36 c.Assert(output.value, Matches, expected) 37} 38 39func (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\\s+[0-9]+\t\\s+[0-9]+ ns/op\n" 59 c.Assert(output.value, Matches, expected) 60} 61 62func (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\\s+[0-9]+\t\\s+[0-9]+ ns/op\t\\s+ *[1-9]\\.[0-9]{2} MB/s\n" 74 c.Assert(output.value, Matches, expected) 75} 76 77func (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\\s+ [0-9]+\t\\s+ *[0-9]+ ns/op\t\\s+ [0-9]+ B/op\t\\s+ [1-9]+ allocs/op\n" 90 c.Assert(output.value, Matches, expected) 91} 92