From 792c3e655cc60428ede8808000e7c30a26956da9 Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Mon, 1 Oct 2018 11:22:22 -0400 Subject: [PATCH] go/types/objectpath: fix tests for pre-go1.11 The behavior of go/types.ObjectString (or perhaps the underlying object) changed at some point. Change-Id: I77f1d13c180e1f78ddc08e80e5d38aa01f425111 Reviewed-on: https://go-review.googlesource.com/138777 Reviewed-by: Robert Griesemer --- go/types/objectpath/objectpath_test.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/go/types/objectpath/objectpath_test.go b/go/types/objectpath/objectpath_test.go index 0d67c73a..16b6123b 100644 --- a/go/types/objectpath/objectpath_test.go +++ b/go/types/objectpath/objectpath_test.go @@ -11,6 +11,7 @@ import ( "go/parser" "go/token" "go/types" + "strings" "testing" "golang.org/x/tools/go/buildutil" @@ -279,8 +280,8 @@ var Z map[string]struct{ A int } // Check the object strings match. // (We can't check that types are identical because the // objects belong to different type-checker realms.) - srcstr := types.ObjectString(srcobj, (*types.Package).Name) - binstr := types.ObjectString(binobj, (*types.Package).Name) + srcstr := objectString(srcobj) + binstr := objectString(binobj) if srcstr != binstr { t.Errorf("ObjectStrings do not match: Object(For(%q)) = %s, want %s", path, srcstr, binstr) @@ -288,3 +289,13 @@ var Z map[string]struct{ A int } } } } + +func objectString(obj types.Object) string { + s := types.ObjectString(obj, (*types.Package).Name) + + // The printing of interface methods changed in go1.11. + // This work-around makes the specific test pass with earlier versions. + s = strings.Replace(s, "func (interface).Method", "func (p.Foo).Method", -1) + + return s +}