1
0
mirror of https://github.com/golang/go synced 2024-10-01 10:38:33 -06:00
go/gopls/test/gopls_test.go
Ian Cottrell 6816ec868d gopls: refactor the cmd tests
This allows them to be run from the gopls module as well to test
the code with the hooks installed.

Change-Id: I3079a04ffe3bd221ccc2523e746cbed384e05e2f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/196321
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-09-23 22:12:42 +00:00

39 lines
1.0 KiB
Go

// Copyright 2019 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 gopls_test
import (
"context"
"os"
"testing"
"golang.org/x/tools/go/packages/packagestest"
"golang.org/x/tools/gopls/internal/hooks"
cmdtest "golang.org/x/tools/internal/lsp/cmd/test"
"golang.org/x/tools/internal/lsp/tests"
"golang.org/x/tools/internal/testenv"
)
func TestMain(m *testing.M) {
testenv.ExitIfSmallMachine()
os.Exit(m.Run())
}
func TestCommandLine(t *testing.T) {
packagestest.TestAll(t, testCommandLine)
}
func testCommandLine(t *testing.T, exporter packagestest.Exporter) {
const testdata = "../../internal/lsp/testdata"
if stat, err := os.Stat(testdata); err != nil || !stat.IsDir() {
t.Skip("testdata directory not present")
}
ctx := context.Background()
hooks.Install(ctx)
data := tests.Load(t, exporter, testdata)
defer data.Exported.Cleanup()
tests.Run(t, cmdtest.NewRunner(exporter, data, tests.Context(t)), data)
}