Skip to content

testing: Helper line number has changed in 1.16 #44887

@ianlancetaylor

Description

@ianlancetaylor

This is the test program.

package main_test

import (
	"testing"
)

func TestHelper(t *testing.T) {
	helperA(t)
}

func helperA(t *testing.T) {
	t.Helper()

	t.Run("subtest", func(t *testing.T) {
		t.Helper()
		t.Fatal("fatal error message")
	})
}

When run using go test foo_test.go with Go 1.14 or Go 1.15, this program prints

--- FAIL: TestHelper (0.00s)
    --- FAIL: TestHelper/subtest (0.00s)
        foo_test.go:8: fatal error message
FAIL
FAIL	command-line-arguments	0.009s
FAIL

When run with Go 1.16 it prints

--- FAIL: TestHelper (0.00s)
    --- FAIL: TestHelper/subtest (0.00s)
        foo_test.go:14: fatal error message
FAIL
FAIL	command-line-arguments	0.007s
FAIL

The line number has changed from 8 to 14. Line number 14 is in a function that called t.Helper, so line 8 seems correct and line 14 seems wrong.

This appears to be due to https://golang.org/cl/231717. If I revert that CL, I see line number 8.

CC @bboreham

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.release-blocker

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions