mirror of https://github.com/golang/go.git
go/internal/gcimporter: fix test for Go 1.18 any
In Go 1.18 context uses any, not interface{}.
Fix the test in a way that should work for both older and newer versions.
For golang/go#49884.
Change-Id: Ib8690876c6a9364b98f9c7ba739b953a8d7565d4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/369955
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
parent
feb39d0cd7
commit
d3358c1fb7
|
|
@ -10,6 +10,7 @@ package gcimporter
|
|||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"go/build"
|
||||
"go/constant"
|
||||
"go/types"
|
||||
"io/ioutil"
|
||||
|
|
@ -255,7 +256,7 @@ var importedObjectTests = []struct {
|
|||
{"go/internal/gcimporter.FindPkg", "func FindPkg(path string, srcDir string) (filename string, id string)"},
|
||||
|
||||
// interfaces
|
||||
{"context.Context", "type Context interface{Deadline() (deadline time.Time, ok bool); Done() <-chan struct{}; Err() error; Value(key interface{}) interface{}}"},
|
||||
{"context.Context", "type Context interface{Deadline() (deadline time.Time, ok bool); Done() <-chan struct{}; Err() error; Value(key any) any}"},
|
||||
{"crypto.Decrypter", "type Decrypter interface{Decrypt(rand io.Reader, msg []byte, opts DecrypterOpts) (plaintext []byte, err error); Public() PublicKey}"},
|
||||
{"encoding.BinaryMarshaler", "type BinaryMarshaler interface{MarshalBinary() (data []byte, err error)}"},
|
||||
{"io.Reader", "type Reader interface{Read(p []byte) (n int, err error)}"},
|
||||
|
|
@ -264,6 +265,18 @@ var importedObjectTests = []struct {
|
|||
{"go/types.Type", "type Type interface{String() string; Underlying() Type}"},
|
||||
}
|
||||
|
||||
// TODO(rsc): Delete this init func after x/tools no longer needs to test successfully with Go 1.17.
|
||||
func init() {
|
||||
if build.Default.ReleaseTags[len(build.Default.ReleaseTags)-1] <= "go1.17" {
|
||||
for i := range importedObjectTests {
|
||||
if importedObjectTests[i].name == "context.Context" {
|
||||
// Expand any to interface{}.
|
||||
importedObjectTests[i].want = "type Context interface{Deadline() (deadline time.Time, ok bool); Done() <-chan struct{}; Err() error; Value(key interface{}) interface{}}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestImportedTypes(t *testing.T) {
|
||||
testenv.NeedsGo1Point(t, 11)
|
||||
// This package only handles gc export data.
|
||||
|
|
@ -275,6 +288,12 @@ func TestImportedTypes(t *testing.T) {
|
|||
continue // error reported elsewhere
|
||||
}
|
||||
got := types.ObjectString(obj, types.RelativeTo(obj.Pkg()))
|
||||
|
||||
// TODO(rsc): Delete this block once go.dev/cl/368254 lands.
|
||||
if got != test.want && test.want == strings.ReplaceAll(got, "interface{}", "any") {
|
||||
got = test.want
|
||||
}
|
||||
|
||||
if got != test.want {
|
||||
t.Errorf("%s: got %q; want %q", test.name, got, test.want)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue