Skip to content

Commit 6002d6e

Browse files
committed
gopls/internal/regtest/misc: test Implementations + vendor
This change adds a test for golang/go#56169, whose cause and fix were the same as for golang/go#55995, which was fixed in CL 454315. Updates golang/go#55995 Fixes golang/go#56169 Change-Id: I6d2cf964be77606de3e945c2e5ecdee82892ee99 Reviewed-on: https://go-review.googlesource.com/c/tools/+/454637 Reviewed-by: Robert Findley <rfindley@google.com> Run-TryBot: Alan Donovan <adonovan@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> gopls-CI: kokoro <noreply+kokoro@google.com>
1 parent f540ee6 commit 6002d6e

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed

gopls/internal/regtest/misc/definition_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ func TestGoToCrashingDefinition_Issue49223(t *testing.T) {
292292
// TestVendoringInvalidatesMetadata ensures that gopls uses the
293293
// correct metadata even after an external 'go mod vendor' command
294294
// causes packages to move; see issue #55995.
295+
// See also TestImplementationsInVendor, which tests the same fix.
295296
func TestVendoringInvalidatesMetadata(t *testing.T) {
296297
testenv.NeedsGo1Point(t, 14)
297298
const proxy = `

gopls/internal/regtest/misc/references_test.go

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ package misc
66

77
import (
88
"fmt"
9+
"os"
910
"sort"
1011
"strings"
1112
"testing"
1213

1314
"github.com/google/go-cmp/cmp"
1415
"golang.org/x/tools/gopls/internal/lsp/protocol"
1516
. "golang.org/x/tools/gopls/internal/lsp/regtest"
17+
"golang.org/x/tools/internal/testenv"
1618
)
1719

1820
func TestStdlibReferences(t *testing.T) {
@@ -288,3 +290,88 @@ func _() {
288290
}
289291
})
290292
}
293+
294+
// This is a regression test for Issue #56169, in which interface
295+
// implementations in vendored modules were not found. The actual fix
296+
// was the same as for #55995; see TestVendoringInvalidatesMetadata.
297+
func TestImplementationsInVendor(t *testing.T) {
298+
testenv.NeedsGo1Point(t, 14)
299+
const proxy = `
300+
-- other.com/b@v1.0.0/go.mod --
301+
module other.com/b
302+
go 1.14
303+
304+
-- other.com/b@v1.0.0/b.go --
305+
package b
306+
type B int
307+
func (B) F() {}
308+
`
309+
const src = `
310+
-- go.mod --
311+
module example.com/a
312+
go 1.14
313+
require other.com/b v1.0.0
314+
315+
-- go.sum --
316+
other.com/b v1.0.0 h1:9WyCKS+BLAMRQM0CegP6zqP2beP+ShTbPaARpNY31II=
317+
other.com/b v1.0.0/go.mod h1:TgHQFucl04oGT+vrUm/liAzukYHNxCwKNkQZEyn3m9g=
318+
319+
-- a.go --
320+
package a
321+
import "other.com/b"
322+
type I interface { F() }
323+
var _ b.B
324+
325+
`
326+
WithOptions(
327+
ProxyFiles(proxy),
328+
Modes(Default), // fails in 'experimental' mode
329+
).Run(t, src, func(t *testing.T, env *Env) {
330+
// Enable to debug go.sum mismatch, which may appear as
331+
// "module lookup disabled by GOPROXY=off", confusingly.
332+
if false {
333+
env.DumpGoSum(".")
334+
}
335+
336+
checkVendor := func(locs []protocol.Location, wantVendor bool) {
337+
if len(locs) != 1 {
338+
t.Errorf("got %d locations, want 1", len(locs))
339+
} else if strings.Contains(string(locs[0].URI), "/vendor/") != wantVendor {
340+
t.Errorf("got location %s, wantVendor=%t", locs[0], wantVendor)
341+
}
342+
}
343+
344+
env.OpenFile("a.go")
345+
refPos := env.RegexpSearch("a.go", "I") // find "I" reference
346+
347+
// Initially, a.I has one implementation b.B in
348+
// the module cache, not the vendor tree.
349+
checkVendor(env.Implementations("a.go", refPos), false)
350+
351+
// Run 'go mod vendor' outside the editor.
352+
if err := env.Sandbox.RunGoCommand(env.Ctx, ".", "mod", []string{"vendor"}, true); err != nil {
353+
t.Fatalf("go mod vendor: %v", err)
354+
}
355+
356+
// Synchronize changes to watched files.
357+
env.Await(env.DoneWithChangeWatchedFiles())
358+
359+
// Now, b.B is found in the vendor tree.
360+
checkVendor(env.Implementations("a.go", refPos), true)
361+
362+
// Delete the vendor tree.
363+
if err := os.RemoveAll(env.Sandbox.Workdir.AbsPath("vendor")); err != nil {
364+
t.Fatal(err)
365+
}
366+
// Notify the server of the deletion.
367+
if err := env.Sandbox.Workdir.CheckForFileChanges(env.Ctx); err != nil {
368+
t.Fatal(err)
369+
}
370+
371+
// Synchronize again.
372+
env.Await(env.DoneWithChangeWatchedFiles())
373+
374+
// b.B is once again defined in the module cache.
375+
checkVendor(env.Implementations("a.go", refPos), false)
376+
})
377+
}

0 commit comments

Comments
 (0)