1
0
mirror of https://github.com/golang/go synced 2024-10-01 07:28:35 -06:00
go/internal/lsp/regtest/definition_test.go
Rob Findley afe1c6fc1b internal/lsp/regtest: remove calls to t.Parallel()
Originally I decided to use t.Parallel() in hopes of uncovering new
bugs. That may have worked... but manifested as rare flakes that are
difficult to diagnose (golang.org/issues/37318).

Since this level of parallelism is extremely unlikely in normal gopls
workloads, I'm going to remove the t.Parallel() calls in hopes of
eliminating this flakiness. I'd rather be able to continue running these
tests.

Also, don't run in the 'Shared' execution mode by default: normal gopls
execution is either as a sidecar (the Singleton execution mode), or as a
daemon (the Forwarded execution mode).

Un-skip the TestGoToStdlibDefinition test, as hopefully it will no
longer flake.

Updates golang/go#37318.

Change-Id: Id73ee3c8702ab4ab1d039baa038fbce879e38df8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/221379
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-02-27 18:46:34 +00:00

83 lines
1.8 KiB
Go

// Copyright 2020 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package regtest
import (
"context"
"path"
"testing"
"golang.org/x/tools/internal/lsp/fake"
)
const internalDefinition = `
-- go.mod --
module mod
go 1.12
-- main.go --
package main
import "fmt"
func main() {
fmt.Println(message)
}
-- const.go --
package main
const message = "Hello World."
`
func TestGoToInternalDefinition(t *testing.T) {
runner.Run(t, internalDefinition, func(ctx context.Context, t *testing.T, env *Env) {
env.OpenFile("main.go")
name, pos := env.GoToDefinition("main.go", fake.Pos{Line: 5, Column: 13})
if want := "const.go"; name != want {
t.Errorf("GoToDefinition: got file %q, want %q", name, want)
}
if want := (fake.Pos{Line: 2, Column: 6}); pos != want {
t.Errorf("GoToDefinition: got position %v, want %v", pos, want)
}
})
}
const stdlibDefinition = `
-- go.mod --
module mod
go 1.12
-- main.go --
package main
import (
"fmt"
"time"
)
func main() {
fmt.Println(time.Now())
}`
func TestGoToStdlibDefinition(t *testing.T) {
runner.Run(t, stdlibDefinition, func(ctx context.Context, t *testing.T, env *Env) {
env.OpenFile("main.go")
name, pos := env.GoToDefinition("main.go", fake.Pos{Line: 8, Column: 19})
if got, want := path.Base(name), "time.go"; got != want {
t.Errorf("GoToDefinition: got file %q, want %q", name, want)
}
// Test that we can jump to definition from outside our workspace.
// See golang.org/issues/37045.
newName, newPos := env.GoToDefinition(name, pos)
if newName != name {
t.Errorf("GoToDefinition is not idempotent: got %q, want %q", newName, name)
}
if newPos != pos {
t.Errorf("GoToDefinition is not idempotent: got %v, want %v", newPos, pos)
}
})
}