Skip to content

testing: with race detector on, using TB.Helper yields the wrong line number #21631

@cespare

Description

@cespare

Using go1.9 linux/amd64.

If you call testing.TB.Helper (i.e., through the interface), it prints an autogenerated line number when running with -race:

package main

import (
	"testing"
)

func TestFoo(t *testing.T) {
	f(t)
	g(t)
}

func f(tb testing.TB) {
	tb.Helper()
	tb.Error("asdf")
}

func g(t *testing.T) {
	t.Helper()
	t.Error("asdf")
}

gives

$ go test x_test.go
--- FAIL: TestFoo (0.00s)
        x_test.go:8: asdf
        x_test.go:9: asdf
FAIL
FAIL    command-line-arguments  0.001s
$ go test -race x_test.go
--- FAIL: TestFoo (0.00s)
        <autogenerated>:1: asdf
        x_test.go:9: asdf
FAIL
FAIL    command-line-arguments  0.005s

Bug pointed out on golang-nuts by @lukasmalkmus.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions