Skip to content

testing: when TB is embedded in an interface, TB.Helper yields the wrong line number #26121

@thatguystone

Description

@thatguystone

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions