mirror of https://github.com/stretchr/testify.git
Stop querying for stack frames multiple times on CallerInfo()
parent
b074924938
commit
3ca01f4bc3
assert
|
@ -212,19 +212,23 @@ the problem actually occurred in calling code.*/
|
||||||
func CallerInfo() []string {
|
func CallerInfo() []string {
|
||||||
|
|
||||||
var pc uintptr
|
var pc uintptr
|
||||||
var ok bool
|
|
||||||
var file string
|
var file string
|
||||||
var line int
|
var line int
|
||||||
var name string
|
var name string
|
||||||
|
|
||||||
callers := []string{}
|
callers := []string{}
|
||||||
for i := 0; ; i++ {
|
pcs := []uintptr{}
|
||||||
pc, file, line, ok = runtime.Caller(i)
|
n := runtime.Callers(0, pcs)
|
||||||
if !ok {
|
if n == 0 {
|
||||||
// The breaks below failed to terminate the loop, and we ran off the
|
return []string{}
|
||||||
// end of the call stack.
|
}
|
||||||
break
|
frames := runtime.CallersFrames(pcs[:n])
|
||||||
}
|
|
||||||
|
for {
|
||||||
|
frame, more := frames.Next()
|
||||||
|
pc = frame.PC
|
||||||
|
file = frame.File
|
||||||
|
line = frame.Line
|
||||||
|
|
||||||
// This is a huge edge case, but it will panic if this is the case, see #180
|
// This is a huge edge case, but it will panic if this is the case, see #180
|
||||||
if file == "<autogenerated>" {
|
if file == "<autogenerated>" {
|
||||||
|
@ -263,6 +267,10 @@ func CallerInfo() []string {
|
||||||
isTest(name, "Example") {
|
isTest(name, "Example") {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !more {
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return callers
|
return callers
|
||||||
|
|
Loading…
Reference in New Issue