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

The test adapter should ignore underscored packages

Open firelizzard18 opened this issue 1 year ago • 3 comments

Given the following project:

  • go.mod
  • foo
    • foo_test.go
  • _bar
    • bar_test.go

If I run go test ./..., the underscored package (_bar) is skipped. I can run those tests by running go test ./_bar so they're not completely disabled, but ... evidently does not resolve underscored packages.

However the test resolver does resolve underscored packages. I think it's OK for underscored packages to appear in the test explorer, since Go does let you build/test those packages, but they should be skipped when running all tests. Though maybe there should be a setting to control whether they're resolved at all. If they are resolved but skipped, that would need to be handled by GoTestRunner.run IIRC. This issue is reproduced by this project.

$ go list ./...
underscore-test/foo

image

image

firelizzard18 avatar Aug 02 '23 15:08 firelizzard18

@hyangah do you have an opinion on whether underscored packages should be completely ignored (excluded by the resolver) or simply skipped if they're not explicitly selected, like benchmarks?

firelizzard18 avatar Aug 02 '23 15:08 firelizzard18

Surprised to learn that go test ./_bar works. I wonder how common this type of project structure is common.

Files whose names begin with "_" or "." are ignored according to https://pkg.go.dev/cmd/go#hdr-Test_packages and many people depend on this to avoid unnecessary scanning. I am inclined to align with the go's behavior and skip _ or . prefixed directories. (testdata too).

hyangah avatar Aug 02 '23 18:08 hyangah

In my case there was some old code I wanted to continue referencing but not maintaining, so I underscored it. I discovered this issue because another developer used "Run all tests" and a test failed (and apparently the package still builds). I've done this a few other times, but in every case my assumption was that it would be totally ignored given that gopls and go build ignored it.

firelizzard18 avatar Aug 02 '23 21:08 firelizzard18