Skip to content

Commit

Permalink
gopls/internal/test/integration: add a test for an inner go.work file
Browse files Browse the repository at this point in the history
Add a test to verify that gopls now does the right thing in the scenario
described by golang/go#63917, where the users has a go.work file inside
a Go module. Gopls now behaves consistently with the go command.

Fixes golang/go#63917

Change-Id: I0c9d251477e7403b4f2b75f0333e991a98c82ba4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/562015
Reviewed-by: Hyang-Ah Hana Kim <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
  • Loading branch information
findleyr committed Feb 6, 2024
1 parent aee2e76 commit 08bd728
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions gopls/internal/test/integration/workspace/workspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,51 @@ use (
})
}

func TestInnerGoWork(t *testing.T) {
// This test checks that gopls honors a go.work file defined
// inside a go module (golang/go#63917).
const workspace = `
-- go.mod --
module a.com
require b.com v1.2.3
-- a/go.work --
go 1.18
use (
..
../b
)
-- a/a.go --
package a
import "b.com/b"
var _ = b.B
-- b/go.mod --
module b.com/b
-- b/b.go --
package b
const B = 0
`
WithOptions(
// This doesn't work if we open the outer module. I'm not sure it should,
// since the go.work file does not apply to the entire module, just a
// subdirectory.
WorkspaceFolders("a"),
).Run(t, workspace, func(t *testing.T, env *Env) {
env.OpenFile("a/a.go")
loc := env.GoToDefinition(env.RegexpSearch("a/a.go", "b.(B)"))
got := env.Sandbox.Workdir.URIToPath(loc.URI)
want := "b/b.go"
if got != want {
t.Errorf("Definition(b.B): got %q, want %q", got, want)
}
})
}

func TestNonWorkspaceFileCreation(t *testing.T) {
const files = `
-- work/go.mod --
Expand Down

0 comments on commit 08bd728

Please sign in to comment.