Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/tools/gopls: fails to detect tests starting with an underscore #70929

Open
mgabeler-lee-6rs opened this issue Dec 12, 2024 · 3 comments
Open
Labels
gopls/analysis Issues related to running analysis in gopls gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@mgabeler-lee-6rs
Copy link

What version of Go, VS Code & VS Code Go extension are you using?

Version Information
  • Run go version to get version of Go from the VS Code integrated terminal.
    • go1.23.4 linux/amd64
  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal.
    • golang.org/x/tools/gopls v0.17.0-pre.4
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.
    • 1.96.0 138f619c86f1199955d53b4166bef66ef252935c x64
  • Check your installed extensions to get the version of the VS Code Go extension
    • 0.43.4 (pre-release)
  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command.

Share the Go related settings you have added/edited

Run Preferences: Open Settings (JSON) command to open your settings.json file.
Share all the settings with the go. or ["go"] or gopls prefixes.

Describe the bug

The new experimental Go Companion tests infrastructure ignores tests whose name (other than the Test) prefix starts with an underscore, while go test does not.

Steps to reproduce the behavior:

  1. Create a new empty package with a test file in it
  2. Create a test named Test_foo
  3. Run go test -v ./... within that package -- observe the test is run
  4. Enable the Go Companion experimental test explorer and code lens
  5. Observe that the companion doesn't detect the test, and so the code lens is hidden, and the package (lacking any other tests) is omitted from the test explorer
  6. Change the test name to TestX_foo
  7. Observe that Go Companion sees the test now
  8. Extra fun: rename it back. Observe that at least sometimes Go Companion still sees the test with the old name as existing, and shows the code lens and the entry in the test explorer, but since it tries to run it with the old name, it doesn't work / produces no results.

The Test_foo naming pattern in my case came from "generate tests for function" helper for a non-exported method on a non-exported type, so the test name I have is Test_typeName_methodName

Spun out of a prior discussion with @firelizzard18: golang/vscode-go#1636 (comment)

This feels like it might be a bug in gopls, if the extension is just asking it to list discovered tests, but I'm not sure how to confirm that.

Screenshots or recordings

N/A

@firelizzard18
Copy link
Contributor

Honestly I didn't know Test_foo was a legal test name. I appreciate the context but TBH it doesn't matter why you're using Test_foo, if go test recognizes it but gopls doesn't, that's a bug. I just checked and Test_ without anything else is also a legal test. This indicates that gopls's test discovery does not match go test; I should probably dig around and copy-paste the code go test uses. @findleyr what's the procedure for bugs like this, should we leave the issue here or transfer it to golang/go?

@firelizzard18 firelizzard18 added gopls Issues related to the Go language server, gopls. gopls/analysis Issues related to running analysis in gopls labels Dec 12, 2024
@stevehipwell
Copy link

FWIW the Test_ prefix is something I've seen widely recommended for testing non-public functions, it's definitely one of the idioms described in Learning Go.

@findleyr
Copy link
Member

Thanks all. I will promote this to a gopls issue. We will fix in v0.18.0.

@findleyr findleyr changed the title Go Companion doesn't detect tests starting with an underscore x/tools/gopls: fails to detect tests starting with an underscore Dec 19, 2024
@findleyr findleyr transferred this issue from golang/vscode-go Dec 19, 2024
@findleyr findleyr added this to the gopls/v0.18.0 milestone Dec 19, 2024
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls/analysis Issues related to running analysis in gopls gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

5 participants