2019-03-25 16:30:55 -06:00
|
|
|
// 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 cmd_test
|
|
|
|
|
|
|
|
import (
|
2019-09-18 21:51:24 -06:00
|
|
|
"fmt"
|
2019-03-25 16:30:55 -06:00
|
|
|
"os"
|
2019-04-29 12:57:27 -06:00
|
|
|
"path/filepath"
|
2019-09-18 21:51:24 -06:00
|
|
|
"regexp"
|
|
|
|
"runtime"
|
2019-03-25 16:30:55 -06:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"golang.org/x/tools/go/packages/packagestest"
|
2019-09-18 21:51:24 -06:00
|
|
|
"golang.org/x/tools/internal/lsp/cmd"
|
|
|
|
cmdtest "golang.org/x/tools/internal/lsp/cmd/test"
|
2019-04-16 13:47:48 -06:00
|
|
|
"golang.org/x/tools/internal/lsp/tests"
|
2019-08-30 10:02:01 -06:00
|
|
|
"golang.org/x/tools/internal/testenv"
|
2019-09-18 21:51:24 -06:00
|
|
|
"golang.org/x/tools/internal/tool"
|
2019-03-25 16:30:55 -06:00
|
|
|
)
|
|
|
|
|
2019-08-29 13:24:41 -06:00
|
|
|
func TestMain(m *testing.M) {
|
2019-08-30 10:02:01 -06:00
|
|
|
testenv.ExitIfSmallMachine()
|
2019-08-29 13:24:41 -06:00
|
|
|
os.Exit(m.Run())
|
|
|
|
}
|
|
|
|
|
2019-03-25 16:30:55 -06:00
|
|
|
func TestCommandLine(t *testing.T) {
|
|
|
|
packagestest.TestAll(t, testCommandLine)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testCommandLine(t *testing.T, exporter packagestest.Exporter) {
|
2019-04-16 13:47:48 -06:00
|
|
|
data := tests.Load(t, exporter, "../testdata")
|
|
|
|
defer data.Exported.Cleanup()
|
2019-10-10 18:48:16 -06:00
|
|
|
tests.Run(t, cmdtest.NewRunner(exporter, data, tests.Context(t), nil), data)
|
2019-03-25 16:30:55 -06:00
|
|
|
}
|
|
|
|
|
2019-09-18 21:51:24 -06:00
|
|
|
func TestDefinitionHelpExample(t *testing.T) {
|
|
|
|
// TODO: https://golang.org/issue/32794.
|
|
|
|
t.Skip()
|
|
|
|
if runtime.GOOS == "android" {
|
|
|
|
t.Skip("not all source files are available on android")
|
2019-03-25 16:30:55 -06:00
|
|
|
}
|
2019-09-18 21:51:24 -06:00
|
|
|
dir, err := os.Getwd()
|
2019-03-25 16:30:55 -06:00
|
|
|
if err != nil {
|
2019-09-18 21:51:24 -06:00
|
|
|
t.Errorf("could not get wd: %v", err)
|
|
|
|
return
|
2019-04-26 10:45:14 -06:00
|
|
|
}
|
2019-09-18 21:51:24 -06:00
|
|
|
thisFile := filepath.Join(dir, "definition.go")
|
|
|
|
baseArgs := []string{"query", "definition"}
|
|
|
|
expect := regexp.MustCompile(`(?s)^[\w/\\:_-]+flag[/\\]flag.go:\d+:\d+-\d+: defined here as FlagSet struct {.*}$`)
|
|
|
|
for _, query := range []string{
|
|
|
|
fmt.Sprintf("%v:%v:%v", thisFile, cmd.ExampleLine, cmd.ExampleColumn),
|
|
|
|
fmt.Sprintf("%v:#%v", thisFile, cmd.ExampleOffset)} {
|
|
|
|
args := append(baseArgs, query)
|
|
|
|
got := cmdtest.CaptureStdOut(t, func() {
|
2019-10-10 18:48:16 -06:00
|
|
|
_ = tool.Run(tests.Context(t), cmd.New("gopls-test", "", nil, nil), args)
|
2019-09-18 21:51:24 -06:00
|
|
|
})
|
|
|
|
if !expect.MatchString(got) {
|
|
|
|
t.Errorf("test with %v\nexpected:\n%s\ngot:\n%s", args, expect, got)
|
2019-04-26 10:45:14 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|