Skip to content

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

Closed

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.

Activity

  1. changed the title [-]testing: with race detector on, calling TB.Helper shows the wrong line number[/-] [+]testing: with race detector on, using TB.Helper yields the wrong line number[/+] on Aug 25, 2017
  2. added this to the Go1.10 milestone on Aug 25, 2017
  3. odeke-em commented on Aug 27, 2017

    @odeke-em
    Member

    /cc @josharian @mdempsky @griesemer and all of the compiler squad

  4. agnivade commented on Oct 12, 2017

    @agnivade
    Contributor

    This is now fixed in latest master. Not sure which commit though 😕 I just tried on the latest master and it worked.

  5. cespare commented on Oct 31, 2017

    @cespare
    ContributorAuthor

    A bisect pointed, unsurprisingly, at e972095.

    Thanks @aclements!

  6. locked and limited conversation to collaborators on Oct 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions