Debian Codegraph @

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

raw symbols SCIP
1 // Copyright 2020 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 misc
6
7 import (
8 "testing"
9
10 . "golang.org/x/tools/gopls/internal/test/integration"
11
12 "golang.org/x/tools/gopls/internal/protocol"
13 )
14
15 const basicProxy = `
16 -- golang.org/x/[email protected]/go.mod --
17 module golang.org/x/hello
18
19 go 1.14
20 -- golang.org/x/[email protected]/hi/hi.go --
21 package hi
22
23 var Goodbye error
24 `
25
26 func TestInconsistentVendoring(t *testing.T) {
27 const pkgThatUsesVendoring = `
28 -- go.mod --
29 module mod.com
30
31 go 1.14
32
33 require golang.org/x/hello v1.2.3
34 -- vendor/modules.txt --
35 -- a/a1.go --
36 package a
37
38 import "golang.org/x/hello/hi"
39
40 func _() {
41 _ = hi.Goodbye
42 var q int // hardcode a diagnostic
43 }
44 `
45 WithOptions(
46 Modes(Default),
47 ProxyFiles(basicProxy),
48 WriteGoSum("."),
49 ).Run(t, pkgThatUsesVendoring, func(t *testing.T, env *Env) {
50 env.OpenFile("a/a1.go")
51 d := &protocol.PublishDiagnosticsParams{}
52 env.AfterChange(
53 Diagnostics(env.AtRegexp("go.mod", "module mod.com"), WithMessage("Inconsistent vendoring")),
54 ReadDiagnostics("go.mod", d),
55 )
56 env.ApplyQuickFixes("go.mod", d.Diagnostics)
57
58 env.AfterChange(
59 Diagnostics(env.AtRegexp("a/a1.go", `q int`), WithMessage("not used")),
60 )
61 })
62 }
63
64 func TestWindowsVendoring_Issue56291(t *testing.T) {
65 const src = `
66 -- go.mod --
67 module mod.com
68
69 go 1.14
70
71 require golang.org/x/hello v1.2.3
72 -- main.go --
73 package main
74
75 import "golang.org/x/hello/hi"
76
77 func main() {
78 _ = hi.Goodbye
79 }
80 `
81 WithOptions(
82 Modes(Default),
83 ProxyFiles(basicProxy),
84 WriteGoSum("."),
85 ).Run(t, src, func(t *testing.T, env *Env) {
86 env.OpenFile("main.go")
87 env.AfterChange(NoDiagnostics())
88 env.RunGoCommand("mod", "tidy")
89 env.RunGoCommand("mod", "vendor")
90 env.AfterChange(NoDiagnostics())
91 env.RegexpReplace("main.go", `import "golang.org/x/hello/hi"`, "")
92 env.AfterChange(
93 Diagnostics(env.AtRegexp("main.go", "hi.Goodbye")),
94 )
95 env.SaveBuffer("main.go")
96 env.AfterChange(NoDiagnostics())
97 })
98 }