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: when TB is embedded in an interface, TB.Helper yields the wrong line number #26121

Closed
thatguystone opened this issue Jun 28, 2018 · 3 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@thatguystone
Copy link

What version of Go are you using (go version)?

  • go1.10.3
  • tip

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GORACE=""
GOROOT="/usr/lib/go-1.10"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go-1.10/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build868942347=/tmp/go-build -gno-record-gcc-switches"

What did you do?

package wrongline

import (
	"testing"
)

type wrap struct {
	testing.TB // Also fails with *testing.T
}

func (w wrap) fail() {
	w.Helper()
	w.Error("fail")
}

type helper interface {
	testing.TB
	fail()
}

func withHelper(h helper) {
	h.Helper()
	h.fail() // Error is logged from here
}

func TestLineNumber(t *testing.T) {
	withHelper(wrap{t})
}

What did you expect to see?

--- FAIL: TestLineNumber (0.00s)
    line_test.go:27: fail
FAIL
exit status 1

What did you see instead?

--- FAIL: TestLineNumber (0.00s)
    line_test.go:23: fail
FAIL
exit status 1
@ianlancetaylor ianlancetaylor added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jun 29, 2018
@ianlancetaylor ianlancetaylor added this to the Go1.12 milestone Jun 29, 2018
@ianlancetaylor
Copy link
Contributor

There may not be any reasonable way to fix this. t.Helper just looks for its caller, but when you embed testing.TB there is a wrapper function in the call stack.

@josharian
Copy link
Contributor

There was discussion of eliding wrapper functions from runtime.Callers. I don’t have an issue number handy, though. If we decided not to do that, we could add something to the stack frame indicating that it is a wrapper and skip over it here.

@andybons andybons modified the milestones: Go1.12, Go1.13 Feb 12, 2019
@andybons andybons modified the milestones: Go1.13, Go1.14 Jul 8, 2019
@odeke-em
Copy link
Member

Thank you for reporting this issue @thatguystone and for the patience!

This issue was fixed in December 2018 for Go1.12 by @randall77's commit 69c2c56 aka CL https://go-review.googlesource.com/c/152537, running your repro on Go1.13 properly produces

$ go test
--- FAIL: TestLineNumber (0.00s)
    foo_test.go:27: fail
FAIL
exit status 1
FAIL	github.com/odeke-em/bugs/golang/26121	0.005s

@golang golang locked and limited conversation to collaborators Sep 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

6 participants