Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions gomock/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package gomock
import (
"fmt"
"reflect"
"runtime"
"strconv"
"strings"
)
Expand Down Expand Up @@ -300,6 +301,22 @@ func (c *Call) After(preReq *Call) *Call {
return c
}

// WithStack add call stack to origin
func (c *Call) WithStack(lvl int) *Call {
if lvl < 1 {
return c
}
strb := &strings.Builder{}
for i := lvl; i > 0; i-- {
if _, file, line, ok := runtime.Caller(i); ok {
strb.WriteString(fmt.Sprintf("\n%s:%d", file, line))
}
}
strb.WriteString("\n")
c.origin = strb.String()
return c
}

// Returns true if the minimum number of calls have been made.
func (c *Call) satisfied() bool {
return c.numCalls >= c.minCalls
Expand Down