Skip to content

test: incorrect absolute test failure path reported through deferred helper func #3525

@exodustx0

Description

@exodustx0

gopls version

Build info
----------
golang.org/x/tools/gopls v0.16.1
	golang.org/x/tools/gopls@v0.16.1 h1:1hO/dCeUvjEYx3V0rVvCtOkwnpEpqS29paE+Jw4dcAc=
	github.com/BurntSushi/toml@v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=
	github.com/google/go-cmp@v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
	golang.org/x/exp/typeparams@v0.0.0-20221212164502-fae10dda9338 h1:2O2DON6y3XMJiQRAS1UWU+54aec2uopH3x7MAiqGW6Y=
	golang.org/x/mod@v0.18.0 h1:5+9lSbEzPSdWkH32vYPBwEpX8KwDbM52Ud9xBUvNlb0=
	golang.org/x/sync@v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
	golang.org/x/sys@v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
	golang.org/x/telemetry@v0.0.0-20240607193123-221703e18637 h1:3Wt8mZlbFwG8llny+t18kh7AXxyWePFycXMuVdHxnyM=
	golang.org/x/text@v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
	golang.org/x/tools@v0.22.1-0.20240628205440-9c895dd76b34 h1:Kd+Z5Pm6uwYx3T2KEkeHMHUMZxDPb/q6b1m+zEcy62c=
	golang.org/x/vuln@v1.0.4 h1:SP0mPeg2PmGCu03V+61EcQiOjmpri2XijexKdzv8Z1I=
	honnef.co/go/tools@v0.4.7 h1:9MDAWxMoSnB6QoSqiVr7P5mtkT9pOc1kSxchzPCnqJs=
	mvdan.cc/gofumpt@v0.6.0 h1:G3QvahNDmpD+Aek/bNOLrFR2XC6ZAdo62dZu65gmwGo=
	mvdan.cc/xurls/v2@v2.5.0 h1:lyBNOm8Wo71UknhUs4QTFUNNMyxy2JEIaKKo0RWOh+8=
go: go1.23.0

go env

set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Exodust\AppData\Local\go-build
set GOENV=C:\Users\Exodust\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\Exodust\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\Exodust\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.23.0
set GODEBUG=
set GOTELEMETRY=on
set GOTELEMETRYDIR=C:\Users\Exodust\AppData\Roaming\go\telemetry
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\Users\Exodust\go\src\github.com\exodustx0\testingbug\go.mod
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\Exodust\AppData\Local\Temp\go-build3098519217=/tmp/go-build -gno-record-gcc-switches

What did you do?

package bug_test

import "testing"

func TestWrongFilename(t *testing.T) {
	defer func() {
		t.Helper()
		t.Fatal("foo")
	}()
	println([]byte{}[0])
}

(Playground, doesn't fail in the Playground due to the absence of gopls test commands)

The report produced by the run test command incorrectly assumes that the test failure originated from the work directory. In this instance, the test failure originates from runtime/panic.go:115, but run test reports it as being <workdir>/panic.go:115.

What did you see happen?

Running tool: C:\Program Files\Go\bin\go.exe test -timeout 30s -coverprofile=C:\Users\Exodust\AppData\Local\Temp\vscode-goWsftAN\go-code-cover -run ^TestWrongFilename$ github.com/exodustx0/testingbug

--- FAIL: TestWrongFilename (0.00s)
    c:\Users\Exodust\go\src\github.com\exodustx0\testingbug\panic.go:115: foo
FAIL
coverage: [no statements]
FAIL	github.com/exodustx0/testingbug	0.201s
FAIL

What did you expect to see?

Running tool: C:\Program Files\Go\bin\go.exe test -timeout 30s -coverprofile=C:\Users\Exodust\AppData\Local\Temp\vscode-goWsftAN\go-code-cover -run ^TestWrongFilename$ github.com/exodustx0/testingbug

--- FAIL: TestWrongFilename (0.00s)
    c:\Program Files\Go\src\runtime\panic.go:115: foo
FAIL
coverage: [no statements]
FAIL	github.com/exodustx0/testingbug	0.201s
FAIL

Editor and settings

VSCode 1.92.2

settings.json:

{
    "gopls": {
        "formatting.gofumpt": true,
        "ui.diagnostic.staticcheck": true,
        "ui.documentation.linksInHover": "gopls"
    },
}

Logs

2024/09/04 13:11:29 Info:2024/09/04 13:11:29 Created View (#1)
        directory=C:\Users\Exodust\go\src\github.com\exodustx0\testingbug
        view_type="GoMod"
        root_dir="file:///C:/Users/Exodust/go/src/github.com/exodustx0/testingbug"
        go_version="go version go1.23.0 windows/amd64"
        build_flags=[]
        env={GOOS:windows GOARCH:amd64 GOCACHE:C:\Users\Exodust\AppData\Local\go-build GOMODCACHE:C:\Users\Exodust\go\pkg\mod GOPATH:C:\Users\Exodust\go GOPRIVATE: GOFLAGS: GO111MODULE: GOTOOLCHAIN:auto GoVersion:23 G
oVersionOutput:go version go1.23.0 windows/amd64
 ExplicitGOWORK: EffectiveGOPACKAGESDRIVER:}
        env_overlay=[]
2024/09/04 13:11:31 Info:2024/09/04 13:11:31 go/packages.Load golang/go#1
        view_id="1"
        snapshot=0
        directory=C:\Users\Exodust\go\src\github.com\exodustx0\testingbug
        query=[C:\Users\Exodust\go\src\github.com\exodustx0\testingbug\... builtin]
        packages=4
        duration=1.5106045s

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateMake it obvious when issues are closed as duplicateFrozenDueToAgego-testissues related to go test support (test output, test explorer, ...)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions