1
0
mirror of https://github.com/golang/go synced 2024-11-18 20:24:41 -07:00
go/internal/lsp/regtest/reg_test.go
Rob Findley fefc8d1877 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>
2020-02-25 19:00:36 +00:00

54 lines
1.4 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"
"flag"
"fmt"
"os"
"testing"
"time"
"golang.org/x/tools/internal/lsp/cmd"
"golang.org/x/tools/internal/lsp/lsprpc"
"golang.org/x/tools/internal/tool"
)
var (
runSubprocessTests = flag.Bool("enable_gopls_subprocess_tests", false, "run regtests against a gopls subprocess")
goplsBinaryPath = flag.String("gopls_test_binary", "", "path to the gopls binary for use as a remote, for use with the -gopls_subprocess_testmode flag")
)
var runner *Runner
func TestMain(m *testing.M) {
flag.Parse()
if os.Getenv("_GOPLS_TEST_BINARY_RUN_AS_GOPLS") == "true" {
tool.Main(context.Background(), cmd.New("gopls", "", nil, nil), os.Args[1:])
os.Exit(0)
}
resetExitFuncs := lsprpc.OverrideExitFuncsForTest()
defer resetExitFuncs()
const testTimeout = 60 * time.Second
if *runSubprocessTests {
goplsPath := *goplsBinaryPath
if goplsPath == "" {
var err error
goplsPath, err = os.Executable()
if err != nil {
panic(fmt.Sprintf("finding test binary path: %v", err))
}
}
runner = NewTestRunner(NormalModes|SeparateProcess, testTimeout, goplsPath)
} else {
runner = NewTestRunner(NormalModes, testTimeout, "")
}
code := m.Run()
runner.Close()
os.Exit(code)
}