mirror of
https://github.com/golang/go
synced 2024-11-05 19:46:11 -07:00
f038785680
Due to the asynchronous and non-transactional nature of the LSP, writing regtests requires waiting for certain conditions to be met in the client editor. To this point, the only type of condition for which we supported waiting was the presence of diagnostic messages, but we can in principle wait for anything that is triggered by a server notification. This change generalizes the notion of expectations to also encompass log messages. Doing this required expanding the value returned from checking expectations to include a new "Unmeetable" verdict, to account for cases where we know that a condition will never be met (for example if it is a negative assertion). This may be useful for diagnostics as well. A test is added to demonstrate these new expectations, where the initial workspace load fails due to unfetchable dependencies. Additionally, some helper flags are added to help debug regtests without a code change, by allowing changing the test timeout, printing logs, and printing goroutine profiles. Updates golang/go#36879 Change-Id: I4cc194e10a4f181ad36a1a7abbb08ff41954b642 Reviewed-on: https://go-review.googlesource.com/c/tools/+/228399 Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
62 lines
1.8 KiB
Go
62 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"
|
|
"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")
|
|
alwaysPrintLogs = flag.Bool("regtest_print_rpc_logs", false, "whether to always print RPC logs")
|
|
regtestTimeout = flag.Duration("regtest_timeout", 60*time.Second, "default timeout for each regtest")
|
|
printGoroutinesOnFailure = flag.Bool("regtest_print_goroutines", false, "whether to print goroutine info on failure")
|
|
)
|
|
|
|
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()
|
|
|
|
runner = &Runner{
|
|
DefaultModes: NormalModes,
|
|
Timeout: *regtestTimeout,
|
|
AlwaysPrintLogs: *alwaysPrintLogs,
|
|
PrintGoroutinesOnFailure: *printGoroutinesOnFailure,
|
|
}
|
|
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.DefaultModes = NormalModes | SeparateProcess
|
|
runner.GoplsPath = goplsPath
|
|
}
|
|
|
|
code := m.Run()
|
|
runner.Close()
|
|
os.Exit(code)
|
|
}
|