.gitignore added
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / golang.org / x / tools / gopls@v0.6.9 / internal / regtest / misc / vendor_test.go
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/regtest"
11
12         "golang.org/x/tools/internal/lsp/protocol"
13         "golang.org/x/tools/internal/testenv"
14 )
15
16 const basicProxy = `
17 -- golang.org/x/hello@v1.2.3/go.mod --
18 module golang.org/x/hello
19
20 go 1.14
21 -- golang.org/x/hello@v1.2.3/hi/hi.go --
22 package hi
23
24 var Goodbye error
25 `
26
27 func TestInconsistentVendoring(t *testing.T) {
28         testenv.NeedsGo1Point(t, 14)
29
30         const pkgThatUsesVendoring = `
31 -- go.mod --
32 module mod.com
33
34 go 1.14
35
36 require golang.org/x/hello v1.2.3
37 -- go.sum --
38 golang.org/x/hello v1.2.3 h1:EcMp5gSkIhaTkPXp8/3+VH+IFqTpk3ZbpOhqk0Ncmho=
39 golang.org/x/hello v1.2.3/go.mod h1:WW7ER2MRNXWA6c8/4bDIek4Hc/+DofTrMaQQitGXcco=
40 -- vendor/modules.txt --
41 -- a/a1.go --
42 package a
43
44 import "golang.org/x/hello/hi"
45
46 func _() {
47         _ = hi.Goodbye
48         var q int // hardcode a diagnostic
49 }
50 `
51         WithOptions(
52                 Modes(Singleton),
53                 ProxyFiles(basicProxy),
54         ).Run(t, pkgThatUsesVendoring, func(t *testing.T, env *Env) {
55                 env.OpenFile("a/a1.go")
56                 d := &protocol.PublishDiagnosticsParams{}
57                 env.Await(
58                         OnceMet(
59                                 env.DiagnosticAtRegexpWithMessage("go.mod", "module mod.com", "Inconsistent vendoring"),
60                                 ReadDiagnostics("go.mod", d),
61                         ),
62                 )
63                 env.ApplyQuickFixes("go.mod", d.Diagnostics)
64
65                 env.Await(
66                         env.DiagnosticAtRegexpWithMessage("a/a1.go", `q int`, "not used"),
67                 )
68         })
69 }