From fd4b8cf416db8b0dfc768bb21dcb0e690205291d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Mon, 16 Jun 2025 16:26:48 +0200 Subject: [PATCH] assert.CallerInfo: cleanup Move the stackFrameBufferSize const which was in package scope but used only by CallerInfo, into CallerInfo body. --- assert/assertions.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/assert/assertions.go b/assert/assertions.go index 5e9cb6e5d..de8de0cb6 100644 --- a/assert/assertions.go +++ b/assert/assertions.go @@ -24,8 +24,6 @@ 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 @@ -217,8 +215,10 @@ func CallerInfo() []string { var line int var name string - callers := []string{} + const stackFrameBufferSize = 10 pcs := make([]uintptr, stackFrameBufferSize) + + callers := []string{} offset := 1 for { @@ -273,13 +273,14 @@ func CallerInfo() []string { isTest(name, "Example") { break } + if !more { break } } - // We know we already have less than a buffer's worth of frames - offset += stackFrameBufferSize + // Next batch + offset += cap(pcs) } return callers