mirror of https://github.com/stretchr/testify.git
review feedback
parent
7f10816c93
commit
cfee2346d7
|
@ -221,75 +221,65 @@ func CallerInfo() []string {
|
||||||
callers := []string{}
|
callers := []string{}
|
||||||
pcs := make([]uintptr, stackFrameBufferSize)
|
pcs := make([]uintptr, stackFrameBufferSize)
|
||||||
offset := 1
|
offset := 1
|
||||||
n := runtime.Callers(offset, pcs)
|
|
||||||
|
|
||||||
if n == 0 {
|
|
||||||
return []string{}
|
|
||||||
}
|
|
||||||
|
|
||||||
maybeMore := n == stackFrameBufferSize
|
|
||||||
frames := runtime.CallersFrames(pcs[:n])
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
frame, more := frames.Next()
|
n := runtime.Callers(offset, pcs)
|
||||||
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
|
|
||||||
if file == "<autogenerated>" {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
f := runtime.FuncForPC(pc)
|
|
||||||
if f == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
name = f.Name()
|
|
||||||
|
|
||||||
// testing.tRunner is the standard library function that calls
|
|
||||||
// tests. Subtests are called directly by tRunner, without going through
|
|
||||||
// the Test/Benchmark/Example function that contains the t.Run calls, so
|
|
||||||
// with subtests we should break when we hit tRunner, without adding it
|
|
||||||
// to the list of callers.
|
|
||||||
if name == "testing.tRunner" {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
parts := strings.Split(file, "/")
|
|
||||||
if len(parts) > 1 {
|
|
||||||
filename := parts[len(parts)-1]
|
|
||||||
dir := parts[len(parts)-2]
|
|
||||||
if (dir != "assert" && dir != "mock" && dir != "require") || filename == "mock_test.go" {
|
|
||||||
callers = append(callers, fmt.Sprintf("%s:%d", file, line))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Drop the package
|
|
||||||
segments := strings.Split(name, ".")
|
|
||||||
name = segments[len(segments)-1]
|
|
||||||
if isTest(name, "Test") ||
|
|
||||||
isTest(name, "Benchmark") ||
|
|
||||||
isTest(name, "Example") {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
if more {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
// We know we already have less than a buffer's worth of frames
|
|
||||||
if !maybeMore {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
offset += stackFrameBufferSize
|
|
||||||
n = runtime.Callers(offset, pcs)
|
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
maybeMore = n == stackFrameBufferSize
|
frames := runtime.CallersFrames(pcs[:n])
|
||||||
|
|
||||||
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
|
||||||
|
if file == "<autogenerated>" {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
f := runtime.FuncForPC(pc)
|
||||||
|
if f == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
name = f.Name()
|
||||||
|
|
||||||
|
// testing.tRunner is the standard library function that calls
|
||||||
|
// tests. Subtests are called directly by tRunner, without going through
|
||||||
|
// the Test/Benchmark/Example function that contains the t.Run calls, so
|
||||||
|
// with subtests we should break when we hit tRunner, without adding it
|
||||||
|
// to the list of callers.
|
||||||
|
if name == "testing.tRunner" {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
parts := strings.Split(file, "/")
|
||||||
|
if len(parts) > 1 {
|
||||||
|
filename := parts[len(parts)-1]
|
||||||
|
dir := parts[len(parts)-2]
|
||||||
|
if (dir != "assert" && dir != "mock" && dir != "require") || filename == "mock_test.go" {
|
||||||
|
callers = append(callers, fmt.Sprintf("%s:%d", file, line))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Drop the package
|
||||||
|
segments := strings.Split(name, ".")
|
||||||
|
name = segments[len(segments)-1]
|
||||||
|
if isTest(name, "Test") ||
|
||||||
|
isTest(name, "Benchmark") ||
|
||||||
|
isTest(name, "Example") {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if !more {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// We know we already have less than a buffer's worth of frames
|
||||||
|
offset += stackFrameBufferSize
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue