Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testing: iterators break t.Helper() #72794

Open
mrwonko opened this issue Mar 11, 2025 · 2 comments
Open

testing: iterators break t.Helper() #72794

mrwonko opened this issue Mar 11, 2025 · 2 comments
Labels
NeedsFix The path to resolution is known, but the work has not been done.

Comments

@mrwonko
Copy link

mrwonko commented Mar 11, 2025

Go version

go version go1.24.1 darwin/amd64

Output of go env in your module/workspace:

AR='ar'
CC='cc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='c++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/Users/willi/Library/Caches/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/Users/willi/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/m7/j4gfn87j6tbbjqkjkllgjvg40000gn/T/go-build3215631796=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOHOSTARCH='amd64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMOD='/Users/willi/<redacted>/go.mod'
GOMODCACHE='/Users/willi/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/willi/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/Cellar/go/1.24.1/libexec'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/willi/Library/Application Support/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/Cellar/go/1.24.1/libexec/pkg/tool/darwin_amd64'
GOVCS=''
GOVERSION='go1.24.1'
GOWORK='/Users/willi/<redacted>/go.work'
PKG_CONFIG='pkg-config'

What did you do?

package repro

import (
	"strings"
	"testing"
)

func TestHelper(t *testing.T) {
	helper(t)
}

func helper(t *testing.T) {
	t.Helper()
	// t.Fatal("this correctly displays repro_test.go:9 as its origin")
	for range strings.SplitSeq("a,b,c", ",") {
		t.Fatal("this incorrectly shows repro_test.go:16 (this line) as its origin, ignoring t.Helper()")
	}
}

What did you see happen?

repro_test.go:16: this incorrectly shows repro_test.go:16 (this line) as its origin, ignoring t.Helper()

What did you expect to see?

repro_test.go:9: this incorrectly shows repro_test.go:16 (this line) as its origin, ignoring t.Helper()

@mrwonko
Copy link
Author

mrwonko commented Mar 11, 2025

Note that if I add a t.Helper() inside of the loop body, the error message points to iter.go:61 instead (but the path is wrong due to a separate issue)

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/656775 mentions this issue: testing: recognize helper functions that use range-over-function

@seankhliao seankhliao added the NeedsFix The path to resolution is known, but the work has not been done. label Mar 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

3 participants