gopls/internal/regtest: simplify regtest EditorConfig

WithEditorConfig(fake.EditorConfig{...}) seemed like unnecessary
boilerplate. Simplify the option to just 'EditorConfig'.

Change-Id: I11a3045388f8e642caff78a3f0caa13374b4713a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/255124
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Robert Findley <rfindley@google.com>
This commit is contained in:
Rob Findley 2020-09-15 22:04:47 -04:00 committed by Robert Findley
parent cbbbe6237a
commit 797bd0f00c
7 changed files with 35 additions and 38 deletions

View File

@ -9,7 +9,6 @@ import (
"fmt"
"testing"
"golang.org/x/tools/internal/lsp/fake"
"golang.org/x/tools/internal/lsp/protocol"
)
@ -56,14 +55,14 @@ func TestBenchmarkSymbols(t *testing.T) {
t.Skip("-symbol_workdir not configured")
}
opts := stressTestOptions(symbolBench.workdir)
conf := fake.EditorConfig{}
conf := EditorConfig{}
if symbolBench.matcher != "" {
conf.SymbolMatcher = &symbolBench.matcher
}
if symbolBench.style != "" {
conf.SymbolStyle = &symbolBench.style
}
opts = append(opts, WithEditorConfig(conf))
opts = append(opts, conf)
withOptions(opts...).run(t, "", func(t *testing.T, env *Env) {
// We can't Await in this test, since we have disabled hooks. Instead, run
// one symbol request to completion to ensure all necessary cache entries

View File

@ -7,7 +7,6 @@ package regtest
import (
"testing"
"golang.org/x/tools/internal/lsp/fake"
"golang.org/x/tools/internal/lsp/protocol"
"golang.org/x/tools/internal/lsp/source"
"golang.org/x/tools/internal/lsp/tests"
@ -48,13 +47,15 @@ const (
}
for _, test := range tests {
t.Run(test.label, func(t *testing.T) {
runner.Run(t, workspace, func(t *testing.T, env *Env) {
withOptions(
EditorConfig{CodeLens: test.enabled},
).run(t, workspace, func(t *testing.T, env *Env) {
env.OpenFile("lib.go")
lens := env.CodeLens("lib.go")
if gotCodeLens := len(lens) > 0; gotCodeLens != test.wantCodeLens {
t.Errorf("got codeLens: %t, want %t", gotCodeLens, test.wantCodeLens)
}
}, WithEditorConfig(fake.EditorConfig{CodeLens: test.enabled}))
})
})
}
}

View File

@ -438,8 +438,8 @@ func _() {
fmt.Println("Hello World")
}
`
editorConfig := fake.EditorConfig{Env: map[string]string{"GOPATH": ""}}
withOptions(WithEditorConfig(editorConfig)).run(t, files, func(t *testing.T, env *Env) {
editorConfig := EditorConfig{Env: map[string]string{"GOPATH": ""}}
withOptions(editorConfig).run(t, files, func(t *testing.T, env *Env) {
env.OpenFile("main.go")
env.Await(env.DiagnosticAtRegexp("main.go", "fmt"))
env.SaveBuffer("main.go")
@ -462,8 +462,8 @@ package x
var X = 0
`
editorConfig := fake.EditorConfig{Env: map[string]string{"GOFLAGS": "-tags=foo"}}
withOptions(WithEditorConfig(editorConfig)).run(t, files, func(t *testing.T, env *Env) {
editorConfig := EditorConfig{Env: map[string]string{"GOFLAGS": "-tags=foo"}}
withOptions(editorConfig).run(t, files, func(t *testing.T, env *Env) {
env.OpenFile("main.go")
env.OrganizeImports("main.go")
env.Await(EmptyDiagnostics("main.go"))
@ -556,9 +556,9 @@ hi mom
`
for _, go111module := range []string{"on", "off", ""} {
t.Run(fmt.Sprintf("GO111MODULE_%v", go111module), func(t *testing.T) {
withOptions(WithEditorConfig(fake.EditorConfig{
withOptions(EditorConfig{
Env: map[string]string{"GO111MODULE": go111module},
})).run(t, files, func(t *testing.T, env *Env) {
}).run(t, files, func(t *testing.T, env *Env) {
env.OpenFile("hello.txt")
env.Await(
OnceMet(
@ -642,7 +642,9 @@ func main() {
_ = conf.ErrHelpWanted
}
`
runner.Run(t, ardanLabs, func(t *testing.T, env *Env) {
withOptions(
WithProxyFiles(ardanLabsProxy),
).run(t, ardanLabs, func(t *testing.T, env *Env) {
// Expect a diagnostic with a suggested fix to add
// "github.com/ardanlabs/conf" to the go.mod file.
env.OpenFile("go.mod")
@ -686,7 +688,7 @@ func main() {
env.Await(
env.DiagnosticAtRegexp("main.go", `"github.com/ardanlabs/conf"`),
)
}, WithProxyFiles(ardanLabsProxy))
})
}
// Test for golang/go#38207.
@ -699,7 +701,9 @@ module mod.com
go 1.12
-- main.go --
`
runner.Run(t, emptyFile, func(t *testing.T, env *Env) {
withOptions(
WithProxyFiles(ardanLabsProxy),
).run(t, emptyFile, func(t *testing.T, env *Env) {
env.OpenFile("main.go")
env.OpenFile("go.mod")
env.EditBuffer("main.go", fake.NewEdit(0, 0, 0, 0, `package main
@ -722,7 +726,7 @@ func main() {
env.Await(
EmptyDiagnostics("main.go"),
)
}, WithProxyFiles(ardanLabsProxy))
})
}
// Test for golang/go#36960.
@ -1263,7 +1267,7 @@ func main() {
`
withOptions(
WithEditorConfig(fake.EditorConfig{EnableStaticcheck: true}),
EditorConfig{EnableStaticcheck: true},
).run(t, files, func(t *testing.T, env *Env) {
env.OpenFile("main.go")
// Staticcheck should generate a diagnostic to simplify this literal.

View File

@ -7,7 +7,6 @@ import (
"strings"
"testing"
"golang.org/x/tools/internal/lsp/fake"
"golang.org/x/tools/internal/lsp/protocol"
"golang.org/x/tools/internal/testenv"
)
@ -143,9 +142,9 @@ var _, _ = x.X, y.Y
t.Fatal(err)
}
defer os.RemoveAll(modcache)
editorConfig := fake.EditorConfig{Env: map[string]string{"GOMODCACHE": modcache}}
editorConfig := EditorConfig{Env: map[string]string{"GOMODCACHE": modcache}}
withOptions(
WithEditorConfig(editorConfig),
editorConfig,
WithProxyFiles(proxy),
).run(t, files, func(t *testing.T, env *Env) {
env.OpenFile("main.go")

View File

@ -117,11 +117,11 @@ func WithModes(modes Mode) RunOption {
})
}
// WithEditorConfig configures the editor's LSP session.
func WithEditorConfig(config fake.EditorConfig) RunOption {
return optionSetter(func(opts *runConfig) {
opts.editor = config
})
// EditorConfig is a RunOption option that configured the regtest editor.
type EditorConfig fake.EditorConfig
func (c EditorConfig) set(opts *runConfig) {
opts.editor = fake.EditorConfig(c)
}
// WithoutWorkspaceFolders prevents workspace folders from being sent as part

View File

@ -7,7 +7,6 @@ package regtest
import (
"testing"
"golang.org/x/tools/internal/lsp/fake"
"golang.org/x/tools/internal/lsp/protocol"
)
@ -193,10 +192,9 @@ func TestSymbolPos(t *testing.T) {
func checkChecks(t *testing.T, matcher string, checks map[string]*expSymbolInformation) {
t.Helper()
opts := []RunOption{
WithEditorConfig(fake.EditorConfig{SymbolMatcher: &matcher}),
}
runner.Run(t, symbolSetup, func(t *testing.T, env *Env) {
withOptions(
EditorConfig{SymbolMatcher: &matcher},
).run(t, symbolSetup, func(t *testing.T, env *Env) {
t.Run(matcher, func(t *testing.T) {
for query, exp := range checks {
t.Run(query, func(t *testing.T) {
@ -207,5 +205,5 @@ func checkChecks(t *testing.T, matcher string, checks map[string]*expSymbolInfor
})
}
})
}, opts...)
})
}

View File

@ -8,8 +8,6 @@ package regtest
import (
"testing"
"golang.org/x/tools/internal/lsp/fake"
)
func TestBadGOPATH(t *testing.T) {
@ -21,12 +19,10 @@ func _() {
fmt.Println("Hello World")
}
`
editorConfig := fake.EditorConfig{
Env: map[string]string{"GOPATH": ":/path/to/gopath"},
}
// Test the case given in
// https://github.com/fatih/vim-go/issues/2673#issuecomment-622307211.
withOptions(WithEditorConfig(editorConfig)).run(t, files, func(t *testing.T, env *Env) {
withOptions(
EditorConfig{Env: map[string]string{"GOPATH": ":/path/to/gopath"}},
).run(t, files, func(t *testing.T, env *Env) {
env.OpenFile("main.go")
env.Await(env.DiagnosticAtRegexp("main.go", "fmt"))
if err := env.Editor.OrganizeImports(env.Ctx, "main.go"); err != nil {