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

Open
thatguystone opened this Issue Jun 28, 2018 · 2 comments

Comments

Projects
None yet
3 participants
@thatguystone

thatguystone commented Jun 28, 2018

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 this to the Go1.12 milestone Jun 29, 2018

@ianlancetaylor

This comment has been minimized.

Contributor

ianlancetaylor commented Jun 29, 2018

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

This comment has been minimized.

Contributor

josharian commented Jun 29, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment