vscode-go icon indicating copy to clipboard operation
vscode-go copied to clipboard

testExplorer: skip test files in testdata directory

Open hyangah opened this issue 4 years ago • 4 comments

From go help test:

The go tool will ignore a directory named "testdata", making it available to hold ancillary data needed by the tests.

Currently, vscode-go test provider collects tests from files under 'testdata' directories. They need to be skipped.

hyangah avatar Oct 22 '21 16:10 hyangah

CC @firelizzard18

@hyangah, this seems like it should be on deck. Please amend if not.

findleyr avatar Oct 28 '21 15:10 findleyr

It's crunch time at my day job, so my availability is limited.

GoTestResolver.resolve should be updated to skip directories named 'testdata', but with that alone, if a user opens a '_test.go' file within a 'testdata' directory, tests in that file will still be resolved. I think the best way to avoid that would be to return early from GoTestResolver.processDocument if the document's URL includes a directory named 'testdata'. I think that should cover everything.

An alternative approach would be returning early from GoTestResolver.getOrCreateItem if the URL includes 'testdata'. However, IIRC callers of getOrCreateItem do not expect it to return null. Though that is how the exclude support works, so this might be a viable alternative after merging that CL.

firelizzard18 avatar Oct 28 '21 17:10 firelizzard18

This is not an urgent issue IMO. Moved to Unplanned for now.

GoTestResolver.processDocument approach seems reasonable to me. I will label it as help-wanted. :-)

hyangah avatar Oct 29 '21 13:10 hyangah

@hyangah With #59445, do you think this should be handled by gopls or vscode-go?

firelizzard18 avatar Jul 19 '24 20:07 firelizzard18