go.undefinedlabs.com/scopeagent@v0.4.2/instrumentation/gocheck/gocheck_test.go (about)

     1  package gocheck
     2  
     3  import (
     4  	"os"
     5  	"testing"
     6  
     7  	. "gopkg.in/check.v1"
     8  
     9  	"go.undefinedlabs.com/scopeagent"
    10  	"go.undefinedlabs.com/scopeagent/agent"
    11  	scopetesting "go.undefinedlabs.com/scopeagent/instrumentation/testing"
    12  )
    13  
    14  var (
    15  	failCount     = 0
    16  	fatalCount    = 0
    17  	panicCount    = 0
    18  	expectedCount = 0
    19  	errorCount    = 0
    20  )
    21  
    22  func TestMain(m *testing.M) {
    23  	scopetesting.PatchTestingLogger()
    24  	defer scopetesting.UnpatchTestingLogger()
    25  	Init()
    26  	os.Exit(scopeagent.Run(m, agent.WithGlobalPanicHandler()))
    27  }
    28  
    29  // Hook up gocheck into the "go test" runner.
    30  func TestM(t *testing.T) {
    31  	TestingT(t)
    32  }
    33  
    34  type MySuite struct{}
    35  
    36  var _ = Suite(&MySuite{})
    37  
    38  func (s *MySuite) TestPass(c *C) {
    39  	c.Log("Hello", "World")
    40  	c.Logf("Hello: %v", "World 2")
    41  }
    42  func (s *MySuite) TestSkip(c *C) {
    43  	c.Skip("My skip reason")
    44  }
    45  func (s *MySuite) TestFail(c *C) {
    46  	if failCount < 2 {
    47  		failCount++
    48  		c.Fail()
    49  	}
    50  }
    51  func (s *MySuite) TestFatal(c *C) {
    52  	if fatalCount < 2 {
    53  		fatalCount++
    54  		c.Fatal("fatal error")
    55  	}
    56  }
    57  func (s *MySuite) TestPanic(c *C) {
    58  	if panicCount < 2 {
    59  		panicCount++
    60  		panic("Custom panic")
    61  	}
    62  }
    63  func (s *MySuite) TestExpected(c *C) {
    64  	c.ExpectFailure("expected failure")
    65  	expectedCount++
    66  	if expectedCount > 2 {
    67  		c.Fail()
    68  	}
    69  }
    70  func (s *MySuite) TestError(c *C) {
    71  	if errorCount < 2 {
    72  		errorCount++
    73  		c.Error("This is an error")
    74  	}
    75  }
    76  func (s *MySuite) BenchmarkLogic(c *C) {
    77  	for i := 0; i < c.N; i++ {
    78  		c.Assert("asd", Equals, "asd")
    79  	}
    80  }