2019-02-08 14:16:57 -07: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 (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
2019-04-16 13:47:48 -06:00
|
|
|
"golang.org/x/tools/internal/lsp/tests"
|
2019-02-08 14:16:57 -07:00
|
|
|
"golang.org/x/tools/internal/span"
|
|
|
|
"golang.org/x/tools/internal/tool"
|
|
|
|
)
|
|
|
|
|
2019-04-16 13:47:48 -06:00
|
|
|
func (r *runner) Diagnostics(t *testing.T, data tests.Diagnostics) {
|
|
|
|
for uri, want := range data {
|
2019-02-08 14:16:57 -07:00
|
|
|
if len(want) == 1 && want[0].Message == "" {
|
|
|
|
continue
|
|
|
|
}
|
2019-06-06 11:51:00 -06:00
|
|
|
fname := uri.Filename()
|
2019-05-07 11:54:07 -06:00
|
|
|
args := []string{"-remote=internal", "check", fname}
|
2019-02-08 14:16:57 -07:00
|
|
|
out := captureStdOut(t, func() {
|
2019-07-10 19:11:23 -06:00
|
|
|
tool.Main(r.ctx, r.app, args)
|
2019-02-08 14:16:57 -07:00
|
|
|
})
|
|
|
|
// parse got into a collection of reports
|
|
|
|
got := map[string]struct{}{}
|
|
|
|
for _, l := range strings.Split(out, "\n") {
|
2019-04-16 13:47:48 -06:00
|
|
|
if len(l) == 0 {
|
|
|
|
continue
|
|
|
|
}
|
2019-02-08 14:16:57 -07:00
|
|
|
// parse and reprint to normalize the span
|
|
|
|
bits := strings.SplitN(l, ": ", 2)
|
|
|
|
if len(bits) == 2 {
|
|
|
|
spn := span.Parse(strings.TrimSpace(bits[0]))
|
|
|
|
spn = span.New(spn.URI(), spn.Start(), span.Point{})
|
|
|
|
l = fmt.Sprintf("%s: %s", spn, strings.TrimSpace(bits[1]))
|
|
|
|
}
|
|
|
|
got[l] = struct{}{}
|
|
|
|
}
|
|
|
|
for _, diag := range want {
|
2019-04-16 13:47:48 -06:00
|
|
|
spn := span.New(diag.Span.URI(), diag.Span.Start(), diag.Span.Start())
|
|
|
|
expect := fmt.Sprintf("%v: %v", spn, diag.Message)
|
2019-02-08 14:16:57 -07:00
|
|
|
_, found := got[expect]
|
|
|
|
if !found {
|
|
|
|
t.Errorf("missing diagnostic %q", expect)
|
|
|
|
} else {
|
|
|
|
delete(got, expect)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for extra, _ := range got {
|
|
|
|
t.Errorf("extra diagnostic %q", extra)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|