Skip to content

Commit

Permalink
refill stack frame buffer after it's exhausted
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeauclair committed Jun 24, 2024
1 parent 4a90eff commit 28e0be5
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions assert/assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"github.com/stretchr/testify/assert/yaml"
)

const stackFrameBufferSize = 10

//go:generate sh -c "cd ../_codegen && go build && cd - && ../_codegen/_codegen -output-package=assert -template=assertion_format.go.tmpl"

// TestingT is an interface wrapper around *testing.T
Expand Down Expand Up @@ -217,8 +219,14 @@ func CallerInfo() []string {
var name string

callers := []string{}
pcs := make([]uintptr, 50)
n := runtime.Callers(1, pcs)
pcs := make([]uintptr, stackFrameBufferSize)
offset := 1
n := runtime.Callers(offset, pcs)
maybeMore := true
if n < stackFrameBufferSize {
maybeMore = false
}

if n == 0 {
return []string{}
}
Expand Down Expand Up @@ -269,8 +277,22 @@ func CallerInfo() []string {
}

if !more {
break
// 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 < stackFrameBufferSize {
maybeMore = false
}

if n == 0 {
break
}
frames = runtime.CallersFrames(pcs[:n])
}

}

return callers
Expand Down

0 comments on commit 28e0be5

Please sign in to comment.