Debian Codegraph @

gopls/internal/test/integration/workspace/vendor_test.go

raw symbols SCIP
1 // Copyright 2024 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package workspace
6
7 import (
8 "testing"
9
10 . "golang.org/x/tools/gopls/internal/test/integration"
11 )
12
13 func TestWorkspacePackagesExcludesVendor(t *testing.T) {
14 // This test verifies that packages in the vendor directory are not workspace
15 // packages. This would be an easy mistake for gopls to make, since mod
16 // vendoring excludes go.mod files, and therefore the nearest go.mod file for
17 // vendored packages is often the workspace mod file.
18 const proxy = `
19 -- other.com/[email protected]/go.mod --
20 module other.com/b
21
22 go 1.18
23
24 -- other.com/[email protected]/b.go --
25 package b
26
27 type B int
28
29 func _() {
30 var V int // unused
31 }
32 `
33 const src = `
34 -- go.mod --
35 module example.com/a
36 go 1.14
37 require other.com/b v1.0.0
38
39 -- a.go --
40 package a
41
42 import "other.com/b"
43
44 var _ b.B
45
46 `
47 WithOptions(
48 WriteGoSum("."),
49 ProxyFiles(proxy),
50 Modes(Default),
51 ).Run(t, src, func(t *testing.T, env *Env) {
52 env.RunGoCommand("mod", "vendor")
53 // Uncomment for updated go.sum contents.
54 // env.DumpGoSum(".")
55 env.OpenFile("a.go")
56 env.AfterChange(
57 NoDiagnostics(), // as b is not a workspace package
58 )
59 loc := env.FirstDefinition(env.RegexpSearch("a.go", `b\.(B)`))
60 env.OpenFile(env.Sandbox.Workdir.URIToPath(loc.URI))
61 env.AfterChange(
62 Diagnostics(env.AtRegexp("vendor/other.com/b/b.go", "V"), WithMessage("not used")),
63 )
64 })
65 }