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 (
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"golang.org/x/tools/go/packages/packagestest"
|
2019-04-16 13:47:48 -06:00
|
|
|
"golang.org/x/tools/internal/lsp/cmd"
|
|
|
|
"golang.org/x/tools/internal/lsp/tests"
|
2019-03-25 16:30:55 -06:00
|
|
|
)
|
|
|
|
|
2019-04-16 13:47:48 -06:00
|
|
|
var isRace = false
|
|
|
|
|
|
|
|
type runner struct {
|
|
|
|
data *tests.Data
|
|
|
|
app *cmd.Application
|
|
|
|
}
|
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-03-25 16:30:55 -06:00
|
|
|
|
2019-04-16 13:47:48 -06:00
|
|
|
r := &runner{
|
|
|
|
data: data,
|
|
|
|
app: &cmd.Application{
|
|
|
|
Config: *data.Exported.Config,
|
2019-03-25 16:30:55 -06:00
|
|
|
},
|
|
|
|
}
|
2019-04-16 13:47:48 -06:00
|
|
|
tests.Run(t, r, data)
|
2019-03-25 16:30:55 -06:00
|
|
|
}
|
|
|
|
|
2019-04-28 21:19:54 -06:00
|
|
|
func (r *runner) Completion(t *testing.T, data tests.Completions, snippets tests.CompletionSnippets, items tests.CompletionItems) {
|
2019-04-16 13:47:48 -06:00
|
|
|
//TODO: add command line completions tests when it works
|
2019-03-25 16:30:55 -06:00
|
|
|
}
|
|
|
|
|
2019-04-16 13:47:48 -06:00
|
|
|
func (r *runner) Highlight(t *testing.T, data tests.Highlights) {
|
|
|
|
//TODO: add command line highlight tests when it works
|
2019-03-25 16:30:55 -06:00
|
|
|
}
|
2019-04-16 13:47:48 -06:00
|
|
|
func (r *runner) Symbol(t *testing.T, data tests.Symbols) {
|
|
|
|
//TODO: add command line symbol tests when it works
|
2019-03-25 16:30:55 -06:00
|
|
|
}
|
|
|
|
|
2019-04-16 13:47:48 -06:00
|
|
|
func (r *runner) Signature(t *testing.T, data tests.Signatures) {
|
|
|
|
//TODO: add command line signature tests when it works
|
2019-03-25 16:30:55 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func captureStdOut(t testing.TB, f func()) string {
|
|
|
|
r, out, err := os.Pipe()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
old := os.Stdout
|
|
|
|
defer func() {
|
|
|
|
os.Stdout = old
|
|
|
|
out.Close()
|
|
|
|
r.Close()
|
|
|
|
}()
|
|
|
|
os.Stdout = out
|
|
|
|
f()
|
|
|
|
out.Close()
|
|
|
|
data, err := ioutil.ReadAll(r)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2019-04-07 21:08:47 -06:00
|
|
|
return string(data)
|
2019-03-25 16:30:55 -06:00
|
|
|
}
|