mirror of https://github.com/golang/go.git
gopls/internal/regtest: add an InitialWorkspaceLoad expectation
The pattern of awaiting initial workspace load has become very common in regtests. Factor out an expectation variable for this, to clean up. Change-Id: I2fe0ad94e2584e447baa57b23d4fdf9f8550772e Reviewed-on: https://go-review.googlesource.com/c/tools/+/255123 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:
parent
bf5c620a10
commit
cbbbe6237a
|
|
@ -9,7 +9,6 @@ import (
|
|||
"fmt"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/tools/internal/lsp"
|
||||
"golang.org/x/tools/internal/lsp/fake"
|
||||
"golang.org/x/tools/internal/lsp/protocol"
|
||||
)
|
||||
|
|
@ -32,9 +31,7 @@ func TestBenchmarkIWL(t *testing.T) {
|
|||
b := testing.Benchmark(func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
withOptions(opts...).run(t, "", func(t *testing.T, env *Env) {
|
||||
env.Await(
|
||||
CompletedWork(lsp.DiagnosticWorkTitle(lsp.FromInitialWorkspaceLoad), 1),
|
||||
)
|
||||
env.Await(InitialWorkspaceLoad)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
|
@ -125,9 +122,7 @@ func TestBenchmarkCompletion(t *testing.T) {
|
|||
// it first (and therefore need hooks).
|
||||
opts = append(opts, SkipHooks(false))
|
||||
withOptions(opts...).run(t, "", func(t *testing.T, env *Env) {
|
||||
env.Await(
|
||||
CompletedWork(lsp.DiagnosticWorkTitle(lsp.FromInitialWorkspaceLoad), 1),
|
||||
)
|
||||
env.Await(InitialWorkspaceLoad)
|
||||
env.OpenFile(completionBench.fileName)
|
||||
params := &protocol.CompletionParams{}
|
||||
params.Context.TriggerCharacter = "s"
|
||||
|
|
|
|||
|
|
@ -26,9 +26,7 @@ package a
|
|||
const ThisVariable = 7
|
||||
`
|
||||
run(t, files, func(t *testing.T, env *Env) {
|
||||
env.Await(
|
||||
CompletedWork(lsp.DiagnosticWorkTitle(lsp.FromInitialWorkspaceLoad), 1),
|
||||
)
|
||||
env.Await(InitialWorkspaceLoad)
|
||||
env.OpenFile("a/a.go")
|
||||
env.Await(
|
||||
CompletedWork(lsp.DiagnosticWorkTitle(lsp.FromDidOpen), 1),
|
||||
|
|
|
|||
|
|
@ -847,7 +847,7 @@ func TestCreateOnlyXTest(t *testing.T) {
|
|||
-- foo/bar_test.go --
|
||||
`
|
||||
run(t, mod, func(t *testing.T, env *Env) {
|
||||
env.Await(CompletedWork(lsp.DiagnosticWorkTitle(lsp.FromInitialWorkspaceLoad), 1))
|
||||
env.Await(InitialWorkspaceLoad)
|
||||
env.OpenFile("foo/bar_test.go")
|
||||
env.EditBuffer("foo/bar_test.go", fake.NewEdit(0, 0, 0, 0, `package foo
|
||||
`))
|
||||
|
|
@ -876,7 +876,7 @@ package foo
|
|||
package foo_
|
||||
`
|
||||
run(t, mod, func(t *testing.T, env *Env) {
|
||||
env.Await(CompletedWork(lsp.DiagnosticWorkTitle(lsp.FromInitialWorkspaceLoad), 1))
|
||||
env.Await(InitialWorkspaceLoad)
|
||||
env.OpenFile("foo/bar_test.go")
|
||||
env.RegexpReplace("foo/bar_test.go", "package foo_", "package foo_test")
|
||||
env.SaveBuffer("foo/bar_test.go")
|
||||
|
|
@ -1101,9 +1101,7 @@ func Foo() {
|
|||
runner.Run(t, basic, func(t *testing.T, env *Env) {
|
||||
testenv.NeedsGo1Point(t, 15)
|
||||
|
||||
env.Await(
|
||||
CompletedWork(lsp.DiagnosticWorkTitle(lsp.FromInitialWorkspaceLoad), 1),
|
||||
)
|
||||
env.Await(InitialWorkspaceLoad)
|
||||
env.WriteWorkspaceFile("foo/foo_test.go", `package main
|
||||
|
||||
func main() {
|
||||
|
|
@ -1132,9 +1130,7 @@ package main
|
|||
func main() {}
|
||||
`
|
||||
runner.Run(t, basic, func(t *testing.T, env *Env) {
|
||||
env.Await(
|
||||
CompletedWork(lsp.DiagnosticWorkTitle(lsp.FromInitialWorkspaceLoad), 1),
|
||||
)
|
||||
env.Await(InitialWorkspaceLoad)
|
||||
env.Editor.OpenFileWithContent(env.Ctx, "foo.go", `package main`)
|
||||
env.Await(
|
||||
CompletedWork(lsp.DiagnosticWorkTitle(lsp.FromDidOpen), 1),
|
||||
|
|
@ -1293,7 +1289,7 @@ func main() {}
|
|||
log.SetFlags(log.Lshortfile)
|
||||
env.OpenFile("main.go")
|
||||
env.OpenFile("other.go")
|
||||
env.Await(CompletedWork(lsp.DiagnosticWorkTitle(lsp.FromInitialWorkspaceLoad), 1))
|
||||
env.Await(InitialWorkspaceLoad)
|
||||
x := env.DiagnosticsFor("main.go")
|
||||
if x == nil {
|
||||
t.Fatalf("expected 1 diagnostic, got none")
|
||||
|
|
@ -1342,9 +1338,7 @@ func _() {
|
|||
}
|
||||
`
|
||||
run(t, files, func(t *testing.T, env *Env) {
|
||||
env.Await(
|
||||
CompletedWork(lsp.DiagnosticWorkTitle(lsp.FromInitialWorkspaceLoad), 1),
|
||||
)
|
||||
env.Await(InitialWorkspaceLoad)
|
||||
env.OpenFile("a/a.go")
|
||||
env.Await(
|
||||
env.DiagnosticAtRegexp("a/a.go", "x"),
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import (
|
|||
"regexp"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/tools/internal/lsp"
|
||||
"golang.org/x/tools/internal/lsp/protocol"
|
||||
)
|
||||
|
||||
|
|
@ -23,6 +24,12 @@ type Expectation interface {
|
|||
Description() string
|
||||
}
|
||||
|
||||
var (
|
||||
// InitialWorkspaceLoad is an expectation that the workspace initial load has
|
||||
// completed. It is verified via workdone reporting.
|
||||
InitialWorkspaceLoad = CompletedWork(lsp.DiagnosticWorkTitle(lsp.FromInitialWorkspaceLoad), 1)
|
||||
)
|
||||
|
||||
// A Verdict is the result of checking an expectation against the current
|
||||
// editor state.
|
||||
type Verdict int
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ package regtest
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"golang.org/x/tools/internal/lsp"
|
||||
"golang.org/x/tools/internal/lsp/protocol"
|
||||
"golang.org/x/tools/internal/lsp/tests"
|
||||
)
|
||||
|
|
@ -29,9 +28,7 @@ func Foo() {
|
|||
}
|
||||
`
|
||||
runner.Run(t, basic, func(t *testing.T, env *Env) {
|
||||
env.Await(
|
||||
CompletedWork(lsp.DiagnosticWorkTitle(lsp.FromInitialWorkspaceLoad), 1),
|
||||
)
|
||||
env.Await(InitialWorkspaceLoad)
|
||||
env.OpenFile("main.go")
|
||||
if err := env.Editor.RefactorRewrite(env.Ctx, "main.go", &protocol.Range{
|
||||
Start: protocol.Position{
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/tools/internal/lsp"
|
||||
"golang.org/x/tools/internal/lsp/fake"
|
||||
"golang.org/x/tools/internal/lsp/protocol"
|
||||
"golang.org/x/tools/internal/testenv"
|
||||
|
|
@ -191,9 +190,7 @@ func TestA(t *testing.T) {
|
|||
}
|
||||
`
|
||||
run(t, pkg, func(t *testing.T, env *Env) {
|
||||
env.Await(
|
||||
CompletedWork(lsp.DiagnosticWorkTitle(lsp.FromInitialWorkspaceLoad), 1),
|
||||
)
|
||||
env.Await(InitialWorkspaceLoad)
|
||||
env.OpenFile("a/a.go")
|
||||
metBy := env.Await(
|
||||
env.DiagnosticAtRegexp("a/a.go", "os.Stat"),
|
||||
|
|
|
|||
|
|
@ -235,7 +235,7 @@ go 1.12
|
|||
`
|
||||
runner.Run(t, mod, func(t *testing.T, env *Env) {
|
||||
env.Await(
|
||||
CompletedWork(lsp.DiagnosticWorkTitle(lsp.FromInitialWorkspaceLoad), 1),
|
||||
InitialWorkspaceLoad,
|
||||
env.DiagnosticAtRegexp("go.mod", "require"),
|
||||
)
|
||||
env.Sandbox.RunGoCommand(env.Ctx, "", "mod", []string{"tidy"})
|
||||
|
|
@ -354,9 +354,7 @@ func main() {
|
|||
// Start from a bad state/bad IWL, and confirm that we recover.
|
||||
t.Run("bad", func(t *testing.T) {
|
||||
runner.Run(t, unknown, func(t *testing.T, env *Env) {
|
||||
env.Await(
|
||||
CompletedWork(lsp.DiagnosticWorkTitle(lsp.FromInitialWorkspaceLoad), 1),
|
||||
)
|
||||
env.Await(InitialWorkspaceLoad)
|
||||
env.OpenFile("go.mod")
|
||||
env.Await(
|
||||
env.DiagnosticAtRegexp("go.mod", "example.com v1.2.2"),
|
||||
|
|
|
|||
|
|
@ -309,9 +309,7 @@ func _() {
|
|||
// Add the new method before the implementation. Expect diagnostics.
|
||||
t.Run("method before implementation", func(t *testing.T) {
|
||||
runner.Run(t, pkg, func(t *testing.T, env *Env) {
|
||||
env.Await(
|
||||
CompletedWork(lsp.DiagnosticWorkTitle(lsp.FromInitialWorkspaceLoad), 1),
|
||||
)
|
||||
env.Await(InitialWorkspaceLoad)
|
||||
env.WriteWorkspaceFile("b/b.go", newMethod)
|
||||
env.Await(
|
||||
OnceMet(
|
||||
|
|
@ -328,9 +326,7 @@ func _() {
|
|||
// Add the new implementation before the new method. Expect no diagnostics.
|
||||
t.Run("implementation before method", func(t *testing.T) {
|
||||
runner.Run(t, pkg, func(t *testing.T, env *Env) {
|
||||
env.Await(
|
||||
CompletedWork(lsp.DiagnosticWorkTitle(lsp.FromInitialWorkspaceLoad), 1),
|
||||
)
|
||||
env.Await(InitialWorkspaceLoad)
|
||||
env.WriteWorkspaceFile("a/a.go", implementation)
|
||||
env.Await(
|
||||
OnceMet(
|
||||
|
|
@ -347,9 +343,7 @@ func _() {
|
|||
// Add both simultaneously. Expect no diagnostics.
|
||||
t.Run("implementation and method simultaneously", func(t *testing.T) {
|
||||
runner.Run(t, pkg, func(t *testing.T, env *Env) {
|
||||
env.Await(
|
||||
CompletedWork(lsp.DiagnosticWorkTitle(lsp.FromInitialWorkspaceLoad), 1),
|
||||
)
|
||||
env.Await(InitialWorkspaceLoad)
|
||||
env.WriteWorkspaceFiles(map[string]string{
|
||||
"a/a.go": implementation,
|
||||
"b/b.go": newMethod,
|
||||
|
|
@ -479,9 +473,7 @@ package a
|
|||
func _() {}
|
||||
`
|
||||
runner.Run(t, pkg, func(t *testing.T, env *Env) {
|
||||
env.Await(
|
||||
CompletedWork(lsp.DiagnosticWorkTitle(lsp.FromInitialWorkspaceLoad), 1),
|
||||
)
|
||||
env.Await(InitialWorkspaceLoad)
|
||||
env.ChangeFilesOnDisk([]fake.FileEvent{
|
||||
{
|
||||
Path: "a/a3.go",
|
||||
|
|
@ -568,9 +560,7 @@ func main() {
|
|||
}
|
||||
`
|
||||
withOptions(WithProxyFiles(proxy)).run(t, mod, func(t *testing.T, env *Env) {
|
||||
env.Await(
|
||||
CompletedWork(lsp.DiagnosticWorkTitle(lsp.FromInitialWorkspaceLoad), 1),
|
||||
)
|
||||
env.Await(InitialWorkspaceLoad)
|
||||
env.WriteWorkspaceFiles(map[string]string{
|
||||
"go.mod": `module mod.com
|
||||
|
||||
|
|
@ -618,7 +608,7 @@ func main() {
|
|||
env.OpenFile("foo/main.go")
|
||||
env.Await(
|
||||
OnceMet(
|
||||
CompletedWork(lsp.DiagnosticWorkTitle(lsp.FromInitialWorkspaceLoad), 1),
|
||||
InitialWorkspaceLoad,
|
||||
env.DiagnosticAtRegexp("foo/main.go", `"blah"`),
|
||||
),
|
||||
)
|
||||
|
|
@ -661,9 +651,7 @@ func TestBob(t *testing.T) {
|
|||
}
|
||||
`
|
||||
run(t, files, func(t *testing.T, env *Env) {
|
||||
env.Await(
|
||||
CompletedWork(lsp.DiagnosticWorkTitle(lsp.FromInitialWorkspaceLoad), 1),
|
||||
)
|
||||
env.Await(InitialWorkspaceLoad)
|
||||
// Add a new symbol to the package under test and use it in the test
|
||||
// variant. Expect no diagnostics.
|
||||
env.WriteWorkspaceFiles(map[string]string{
|
||||
|
|
|
|||
|
|
@ -139,9 +139,7 @@ func TestClearAnalysisDiagnostics(t *testing.T) {
|
|||
// replace target is added to the go.mod.
|
||||
func TestWatchReplaceTargets(t *testing.T) {
|
||||
withOptions(WithProxyFiles(workspaceProxy), WithRootPath("pkg")).run(t, workspaceModule, func(t *testing.T, env *Env) {
|
||||
env.Await(
|
||||
CompletedWork(lsp.DiagnosticWorkTitle(lsp.FromInitialWorkspaceLoad), 1),
|
||||
)
|
||||
env.Await(InitialWorkspaceLoad)
|
||||
// Add a replace directive and expect the files that gopls is watching
|
||||
// to change.
|
||||
dir := env.Sandbox.Workdir.URI("goodbye").SpanURI().Filename()
|
||||
|
|
@ -199,9 +197,7 @@ func Hello() int {
|
|||
withOptions(
|
||||
WithProxyFiles(workspaceModuleProxy),
|
||||
).run(t, multiModule, func(t *testing.T, env *Env) {
|
||||
env.Await(
|
||||
CompletedWork(lsp.DiagnosticWorkTitle(lsp.FromInitialWorkspaceLoad), 1),
|
||||
)
|
||||
env.Await(InitialWorkspaceLoad)
|
||||
env.Await(
|
||||
env.DiagnosticAtRegexp("moda/a/a.go", "x"),
|
||||
env.DiagnosticAtRegexp("modb/b/b.go", "x"),
|
||||
|
|
|
|||
Loading…
Reference in New Issue