Skip to content

Failing test will point to non-existing file if the t.Error() ocured in a different dir #3853

@h9jiang

Description

@h9jiang

This is a follow up issue from feedback collected from GopherCon.

 /example/ tree
.
├── example_test.go // the test function will call a helper function from foo/internal.go 
├── example.go
├── foo
│   └── internal.go // foo/internal.go will call t.Error()
└── internal.go // but this is the file get opened

-- example_test.go --
package example

import (
	"helloworld/example/foo"
	"testing"
)

func TestFoo(t *testing.T) {
	foo.TestHelper(t)
}

-- foo/internal.go --
func TestHelper(t *testing.T) {
	t.Errorf("asdas internal")
}

-- internal.go --
package example

// asdasd
// asdasd
// asdasd
// asdasd
// asdasd
// asdasd
// asdasd
// asdasd
// asdasd

Run the test from test explorer, and click the failing test case in test explorer. VSCode-Go will open the example/internal.go instead of the real failure at example/foo/internal.go.

Image

It more confusing if the file example/internal.go does not exist. VSCode will say "file not found".

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions