2020-02-06 17:50:37 -07:00
|
|
|
// 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 (
|
2020-02-10 09:34:13 -07:00
|
|
|
"context"
|
|
|
|
"flag"
|
2020-02-09 12:44:03 -07:00
|
|
|
"fmt"
|
2020-02-06 17:50:37 -07:00
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
"time"
|
2020-02-09 12:44:03 -07:00
|
|
|
|
2020-02-10 09:34:13 -07:00
|
|
|
"golang.org/x/tools/internal/lsp/cmd"
|
|
|
|
"golang.org/x/tools/internal/tool"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2020-04-15 15:14:53 -06:00
|
|
|
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")
|
2020-02-06 17:50:37 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
var runner *Runner
|
|
|
|
|
|
|
|
func TestMain(m *testing.M) {
|
2020-02-10 09:34:13 -07:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2020-04-15 15:14:53 -06:00
|
|
|
runner = &Runner{
|
|
|
|
DefaultModes: NormalModes,
|
|
|
|
Timeout: *regtestTimeout,
|
|
|
|
AlwaysPrintLogs: *alwaysPrintLogs,
|
|
|
|
PrintGoroutinesOnFailure: *printGoroutinesOnFailure,
|
|
|
|
}
|
2020-02-10 09:34:13 -07:00
|
|
|
if *runSubprocessTests {
|
|
|
|
goplsPath := *goplsBinaryPath
|
|
|
|
if goplsPath == "" {
|
|
|
|
var err error
|
2020-02-25 09:00:37 -07:00
|
|
|
goplsPath, err = os.Executable()
|
2020-02-10 09:34:13 -07:00
|
|
|
if err != nil {
|
|
|
|
panic(fmt.Sprintf("finding test binary path: %v", err))
|
|
|
|
}
|
|
|
|
}
|
2020-04-15 15:14:53 -06:00
|
|
|
runner.DefaultModes = NormalModes | SeparateProcess
|
|
|
|
runner.GoplsPath = goplsPath
|
2020-02-10 09:34:13 -07:00
|
|
|
}
|
2020-04-15 15:14:53 -06:00
|
|
|
|
2020-02-10 09:34:13 -07:00
|
|
|
code := m.Run()
|
|
|
|
runner.Close()
|
|
|
|
os.Exit(code)
|
|
|
|
}
|