1
0
mirror of https://github.com/golang/go synced 2024-10-01 12:28:37 -06:00
go/internal/lsp/cmd/test/implementation.go
Rebecca Stambler a9a43c4726 internal/lsp: store workspace package IDs with package paths
A test variant for a package can only be reloaded by running go/packages
on the non-test variants import path with the -test flag. We need to
cache this import path in order to be able to reload a test package
on-demand.

Also, always ignore test main packages by detecting them in the
metadata.

Fixes golang/go#36473

Change-Id: I6e5a61c8e73689212303ae09fa3aed4a2ee8762a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/213660
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-01-09 22:04:34 +00:00

38 lines
973 B
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 cmdtest
import (
"fmt"
"sort"
"testing"
"golang.org/x/tools/internal/span"
)
func (r *runner) Implementation(t *testing.T, spn span.Span, imps []span.Span) {
var itemStrings []string
for _, i := range imps {
itemStrings = append(itemStrings, fmt.Sprint(i))
}
sort.Strings(itemStrings)
var expect string
for _, i := range itemStrings {
expect += i + "\n"
}
expect = r.Normalize(expect)
uri := spn.URI()
filename := uri.Filename()
target := filename + fmt.Sprintf(":%v:%v", spn.Start().Line(), spn.Start().Column())
got, stderr := r.NormalizeGoplsCmd(t, "implementation", target)
if stderr != "" {
t.Errorf("implementation failed for %s: %s", target, stderr)
} else if expect != got {
t.Errorf("implementation failed for %s expected:\n%s\ngot:\n%s", target, expect, got)
}
}