aboutsummaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorRob Findley <rfindley@google.com>2020-02-25 11:00:37 -0500
committerRobert Findley <rfindley@google.com>2020-02-25 19:00:36 +0000
commitfefc8d187781328d218f957bacb7632909acab8f (patch)
tree34636ed07f8c6b4e7bbad1048c5c89a3aa41c4a2 /internal
parent042d10a1500495f27e8639a7b0f82fd39341f2c0 (diff)
downloadgolang-x-tools-fefc8d187781328d218f957bacb7632909acab8f.tar.gz
internal/lsp/regtest: clean-up and more error handling
Fix various things related to regtest execution: + Check the error from OpenFile in fake.Editor.GoToDefinition. + Add an error-checked wrapper to env for CloseBuffer. + Use env wrappers in TestDiagnosticClearingOnClose. + Use os.Executable to get the test binary path. + Add a -listen.timeout to the remote gopls process, so that it is cleaned up. Updates golang/go#36879 Change-Id: I056ff50bdb611a78ad78e4f5e2a94a4f155cc9de Reviewed-on: https://go-review.googlesource.com/c/tools/+/220902 Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Diffstat (limited to 'internal')
-rw-r--r--internal/lsp/fake/editor.go4
-rw-r--r--internal/lsp/regtest/diagnostics_test.go5
-rw-r--r--internal/lsp/regtest/env.go10
-rw-r--r--internal/lsp/regtest/reg_test.go18
4 files changed, 15 insertions, 22 deletions
diff --git a/internal/lsp/fake/editor.go b/internal/lsp/fake/editor.go
index 4ef7c8f23..5cb0a5702 100644
--- a/internal/lsp/fake/editor.go
+++ b/internal/lsp/fake/editor.go
@@ -348,7 +348,9 @@ func (e *Editor) GoToDefinition(ctx context.Context, path string, pos Pos) (stri
}
newPath := e.ws.URIToPath(resp[0].URI)
newPos := fromProtocolPosition(resp[0].Range.Start)
- e.OpenFile(ctx, newPath)
+ if err := e.OpenFile(ctx, newPath); err != nil {
+ return "", Pos{}, fmt.Errorf("OpenFile: %v", err)
+ }
return newPath, newPos, nil
}
diff --git a/internal/lsp/regtest/diagnostics_test.go b/internal/lsp/regtest/diagnostics_test.go
index cbf4a0ed1..1006b5e42 100644
--- a/internal/lsp/regtest/diagnostics_test.go
+++ b/internal/lsp/regtest/diagnostics_test.go
@@ -93,12 +93,11 @@ func TestDiagnosticClearingOnDelete(t *testing.T) {
func TestDiagnosticClearingOnClose(t *testing.T) {
t.Parallel()
runner.Run(t, badPackage, func(ctx context.Context, t *testing.T, env *Env) {
- env.E.CreateBuffer(env.ctx, "c.go", `package consts
+ env.CreateBuffer("c.go", `package consts
const a = 3`)
env.Await(DiagnosticAt("a.go", 2, 6), DiagnosticAt("b.go", 2, 6), DiagnosticAt("c.go", 2, 6))
- env.E.CloseBuffer(env.ctx, "c.go")
-
+ env.CloseBuffer("c.go")
env.Await(DiagnosticAt("a.go", 2, 6), DiagnosticAt("b.go", 2, 6), EmptyDiagnostics("c.go"))
})
}
diff --git a/internal/lsp/regtest/env.go b/internal/lsp/regtest/env.go
index 305e770ea..034deaaba 100644
--- a/internal/lsp/regtest/env.go
+++ b/internal/lsp/regtest/env.go
@@ -110,7 +110,7 @@ func (r *Runner) getRemoteSocket(t *testing.T) string {
t.Fatalf("creating tempdir: %v", err)
}
socket := filepath.Join(r.socketDir, daemonFile)
- args := []string{"serve", "-listen", "unix;" + socket}
+ args := []string{"serve", "-listen", "unix;" + socket, "-listen.timeout", "10s"}
cmd := exec.Command(r.goplsPath, args...)
cmd.Env = append(os.Environ(), runTestAsGoplsEnvvar+"=true")
var stderr bytes.Buffer
@@ -298,6 +298,14 @@ func (e *Env) CreateBuffer(name string, content string) {
}
}
+// CloseBuffer closes an editor buffer, calling t.Fatal on any error.
+func (e *Env) CloseBuffer(name string) {
+ e.t.Helper()
+ if err := e.E.CloseBuffer(e.ctx, name); err != nil {
+ e.t.Fatal(err)
+ }
+}
+
// EditBuffer applies edits to an editor buffer, calling t.Fatal on any error.
func (e *Env) EditBuffer(name string, edits ...fake.Edit) {
e.t.Helper()
diff --git a/internal/lsp/regtest/reg_test.go b/internal/lsp/regtest/reg_test.go
index 2c57119f8..9246ccb1b 100644
--- a/internal/lsp/regtest/reg_test.go
+++ b/internal/lsp/regtest/reg_test.go
@@ -9,7 +9,6 @@ import (
"flag"
"fmt"
"os"
- "path/filepath"
"testing"
"time"
@@ -39,7 +38,7 @@ func TestMain(m *testing.M) {
goplsPath := *goplsBinaryPath
if goplsPath == "" {
var err error
- goplsPath, err = testBinaryPath()
+ goplsPath, err = os.Executable()
if err != nil {
panic(fmt.Sprintf("finding test binary path: %v", err))
}
@@ -52,18 +51,3 @@ func TestMain(m *testing.M) {
runner.Close()
os.Exit(code)
}
-
-func testBinaryPath() (string, error) {
- pth := os.Args[0]
- if !filepath.IsAbs(pth) {
- cwd, err := os.Getwd()
- if err == nil {
- return "", fmt.Errorf("os.Getwd: %v", err)
- }
- pth = filepath.Join(cwd, pth)
- }
- if _, err := os.Stat(pth); err != nil {
- return "", fmt.Errorf("os.Stat: %v", err)
- }
- return pth, nil
-}