mirror of
https://github.com/golang/go
synced 2024-11-18 20:04:52 -07:00
7f54bd5c70
Change-Id: I0a3e8a2837cdeefb3dbbe7b86ed75a32b321797e Reviewed-on: https://go-review.googlesource.com/c/tools/+/172778 Run-TryBot: Ian Cottrell <iancottrell@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
66 lines
1.7 KiB
Go
66 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 (
|
|
"context"
|
|
"fmt"
|
|
"runtime"
|
|
"strings"
|
|
"testing"
|
|
|
|
"golang.org/x/tools/internal/lsp/tests"
|
|
"golang.org/x/tools/internal/span"
|
|
"golang.org/x/tools/internal/tool"
|
|
)
|
|
|
|
func (r *runner) Diagnostics(t *testing.T, data tests.Diagnostics) {
|
|
if runtime.GOOS != "linux" || isRace {
|
|
t.Skip("currently uses too much memory, see issue #31611")
|
|
}
|
|
for uri, want := range data {
|
|
if len(want) == 1 && want[0].Message == "" {
|
|
continue
|
|
}
|
|
fname, err := uri.Filename()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
args := []string{"-remote=internal"}
|
|
args = append(args, "check", fname)
|
|
out := captureStdOut(t, func() {
|
|
tool.Main(context.Background(), r.app, args)
|
|
})
|
|
// parse got into a collection of reports
|
|
got := map[string]struct{}{}
|
|
for _, l := range strings.Split(out, "\n") {
|
|
if len(l) == 0 {
|
|
continue
|
|
}
|
|
// 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 {
|
|
spn := span.New(diag.Span.URI(), diag.Span.Start(), diag.Span.Start())
|
|
expect := fmt.Sprintf("%v: %v", spn, diag.Message)
|
|
_, 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)
|
|
}
|
|
}
|
|
}
|