mirror of
https://github.com/golang/go
synced 2024-11-18 23:14:43 -07:00
4471d52094
With this change (finally, after a lot of detours) if you run the lsp tests with `-race -pipe` then you can reliably reproduce the race in golang/go#30091 Change-Id: Ibd9fda5e07409a15d1bc8d14cb46fde41155aa6e Reviewed-on: https://go-review.googlesource.com/c/tools/+/169999 Run-TryBot: Ian Cottrell <iancottrell@google.com> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
83 lines
2.1 KiB
Go
83 lines
2.1 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"
|
|
"strings"
|
|
"testing"
|
|
|
|
"golang.org/x/tools/go/packages/packagestest"
|
|
"golang.org/x/tools/internal/lsp/cmd"
|
|
"golang.org/x/tools/internal/lsp/source"
|
|
"golang.org/x/tools/internal/span"
|
|
"golang.org/x/tools/internal/tool"
|
|
)
|
|
|
|
type diagnostics map[string][]source.Diagnostic
|
|
|
|
func (l diagnostics) collect(spn span.Span, msgSource, msg string) {
|
|
fname, err := spn.URI().Filename()
|
|
if err != nil {
|
|
return
|
|
}
|
|
//TODO: diagnostics with range
|
|
spn = span.New(spn.URI(), spn.Start(), span.Point{})
|
|
l[fname] = append(l[fname], source.Diagnostic{
|
|
Span: spn,
|
|
Message: msg,
|
|
Source: msgSource,
|
|
Severity: source.SeverityError,
|
|
})
|
|
}
|
|
|
|
func (l diagnostics) test(t *testing.T, e *packagestest.Exported) {
|
|
count := 0
|
|
for fname, want := range l {
|
|
if len(want) == 1 && want[0].Message == "" {
|
|
continue
|
|
}
|
|
args := []string{}
|
|
if *internalPipe {
|
|
args = append(args, "-remote=internal")
|
|
}
|
|
args = append(args, "check", fname)
|
|
app := &cmd.Application{}
|
|
app.Config = *e.Config
|
|
out := captureStdOut(t, func() {
|
|
tool.Main(context.Background(), app, args)
|
|
})
|
|
// parse got into a collection of reports
|
|
got := map[string]struct{}{}
|
|
for _, l := range strings.Split(out, "\n") {
|
|
// 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 {
|
|
expect := fmt.Sprintf("%v: %v", diag.Span, 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)
|
|
}
|
|
count += len(want)
|
|
}
|
|
if count != expectedDiagnosticsCount {
|
|
t.Errorf("got %v diagnostics expected %v", count, expectedDiagnosticsCount)
|
|
}
|
|
}
|