Navigation Menu

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: "go test" command not working for "_test"-suffixed packages #43037

Closed
leitzler opened this issue Dec 6, 2020 · 1 comment
Closed
Labels
FrozenDueToAge 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

@leitzler
Copy link
Contributor

leitzler commented Dec 6, 2020

What version of Go are you using (go version)?

$ go version
go version devel +add45938b5 Thu Nov 19 19:35:35 2020 +0000 darwin/amd64
$ go list -m golang.org/x/tools golang.org/x/tools/gopls
golang.org/x/tools v0.0.0-20201204222352-654352759326
golang.org/x/tools/gopls v0.0.0-20201204222352-654352759326

What did you do?

Triggered the Go Test command in a package where the test file had a package name ending with _test.

$ cd (mktemp -d) && go mod init example.com/foo
$ cat > main_test.go <<EOF
package main_test

import "testing"

func TestFoo(t *testing.T) {}
EOF

What did you expect to see?

Test running, no module lookup.

What did you see instead?

Test not running, failed module lookup for package example.com/foo_test.

[Trace - 20:52:39.712 PM] Sending request 'textDocument/codeAction - (5)'.
Params: {"textDocument":{"uri":"file:///private/var/folders/j4/l2j99h6d5qd6knjlllql0bb80000gn/T/tmp.gwQi3tbY/main_t
est.go"},"range":{"start":{"line":4,"character":0},"end":{"line":4,"character":29}},"context":{"diagnostics":null,"
only":["goTest"]}}


[Trace - 20:52:39.714 PM] Received response 'textDocument/codeAction - (5)' in 2ms.
Result: [{"title":"test","kind":"goTest","disabled":{"reason":""},"edit":{},"command":{"title":"Run test(s)","comma
nd":"gopls.test","arguments":["file:///private/var/folders/j4/l2j99h6d5qd6knjlllql0bb80000gn/T/tmp.gwQi3tbY/main_te
st.go",["TestFoo"],null]}}]


[Trace - 20:52:39.715 PM] Sending request 'workspace/executeCommand - (6)'.
Params: {"command":"gopls.test","arguments":["file:///private/var/folders/j4/l2j99h6d5qd6knjlllql0bb80000gn/T/tmp.g
wQi3tbY/main_test.go",["TestFoo"],null],"workDoneToken":"govim5577006791947779410"}


[Trace - 20:52:39.717 PM] Received response 'workspace/executeCommand - (6)' in 1ms.
Result: null


[Trace - 20:52:39.717 PM] Received notification '$/progress'.
Params: {"token":"govim5577006791947779410","value":{"cancellable":true,"kind":"begin","message":"Running...","title":"Run test(s)"}}


[Trace - 20:52:39.821 PM] Received notification '$/progress'.
Params: {"token":"govim5577006791947779410","value":{"cancellable":true,"kind":"report","message":"go: finding module for package example.com/foo_test"}}


[Trace - 20:52:39.822 PM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"2020/12/06 20:52:39 go: finding module for package example.com/foo_test\n\n\toperation=\"test\"\n"}


[Trace - 20:52:39.822 PM] Received notification '$/progress'.
Params: {"token":"govim5577006791947779410","value":{"cancellable":true,"kind":"report","message":"cannot find module providing package example.com/foo_test: module lookup disabled by GOPROXY=off"}}
@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Dec 6, 2020
@gopherbot gopherbot added this to the Unreleased milestone Dec 6, 2020
@gopherbot
Copy link

Change https://golang.org/cl/275496 mentions this issue: internal/lsp: use ForTest package name when running test command

@stamblerre stamblerre modified the milestones: Unreleased, gopls/v0.6.0 Dec 6, 2020
marwan-at-work pushed a commit to marwan-at-work/tools that referenced this issue Dec 23, 2020
Executing the "go test" command did pass Package.PkgPath() as first
argument to the go invokation before. That failed when using test
packages with _test suffix.

The "go test" command now use Package.ForTest() instead.

Fixes golang/go#43037

Change-Id: Iea1a0e0c949a53770c1d3e1126a16a9c4952a53f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/275496
Trust: Pontus Leitzler <leitzler@gmail.com>
Run-TryBot: Pontus Leitzler <leitzler@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
@golang golang locked and limited conversation to collaborators Dec 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge 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

3 participants