github.com/nikandfor/errors@v0.8.0/errors_location_test.go (about)

     1  package errors
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/nikandfor/loc"
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func TestDepthCaller(t *testing.T) {
    11  	assert.Equal(t, "errors_location_test.go:11", NewDepth(0, "msg").(Callerer).Caller().String())
    12  	assert.Equal(t, "errors_location_test.go:12", NewCaller(loc.Caller(0), "msg").(Callerer).Caller().String())
    13  
    14  	err := New("inner")
    15  
    16  	assert.Equal(t, "errors_location_test.go:16", WrapDepth(err, 0, "msg").(Callerer).Caller().String())
    17  	assert.Equal(t, "errors_location_test.go:17", WrapCaller(err, loc.Caller(0), "msg").(Callerer).Caller().String())
    18  }
    19  
    20  func TestStackCallers(t *testing.T) {
    21  	testStackCallers(t)
    22  }
    23  
    24  func testStackCallers(t *testing.T) {
    25  	assert.Equal(t, "errors_location_test.go:25", NewStack(0, 2, "msg").(Callerer).Caller().String())
    26  	assert.Equal(t, "errors_location_test.go:26", NewCallers(loc.Callers(0, 2), "msg").(Callerer).Caller().String())
    27  
    28  	err := New("inner")
    29  
    30  	assert.Equal(t, "errors_location_test.go:30", WrapStack(err, 0, 2, "msg").(Callerer).Caller().String())
    31  	assert.Equal(t, "errors_location_test.go:31", WrapCallers(err, loc.Callers(0, 2), "msg").(Callerer).Caller().String())
    32  
    33  	assert.Equal(t, PC(0), NewCallers(PCs{}, "msg").(Callerer).Caller())
    34  	assert.Equal(t, "errors_location_test.go:34", NewStack(0, 1, "msg").(Callerer).Caller().String())
    35  	assert.Equal(t, "errors_location_test.go:35", NewStack(0, 1, "msg").(Callerser).Callers().String())
    36  }