mirror of
https://github.com/golang/go
synced 2024-11-19 02:24:41 -07:00
1486df0b25
There's no need to do this more than once per view. Change-Id: I3160adc602764204155dd0e506fd554aeb55d639 Reviewed-on: https://go-review.googlesource.com/c/tools/+/215321 Run-TryBot: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Heschi Kreinick <heschi@google.com>
62 lines
1.7 KiB
Go
62 lines
1.7 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 cmd_test
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"regexp"
|
|
"runtime"
|
|
"testing"
|
|
|
|
"golang.org/x/tools/go/packages/packagestest"
|
|
"golang.org/x/tools/internal/lsp/cmd"
|
|
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) {
|
|
data := tests.Load(t, exporter, "../testdata")
|
|
defer data.Exported.Cleanup()
|
|
tests.Run(t, cmdtest.NewRunner(exporter, data, tests.Context(t), nil), data)
|
|
}
|
|
|
|
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")
|
|
}
|
|
dir, err := os.Getwd()
|
|
if err != nil {
|
|
t.Errorf("could not get wd: %v", err)
|
|
return
|
|
}
|
|
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)
|
|
r := cmdtest.NewRunner(nil, nil, tests.Context(t), nil)
|
|
got, _ := r.NormalizeGoplsCmd(t, args...)
|
|
if !expect.MatchString(got) {
|
|
t.Errorf("test with %v\nexpected:\n%s\ngot:\n%s", args, expect, got)
|
|
}
|
|
}
|
|
}
|