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 <gri@golang.org>
This commit is contained in:
Alan Donovan 2018-10-01 11:22:22 -04:00
parent b3c0be4c97
commit 792c3e655c
1 changed files with 13 additions and 2 deletions

View File

@ -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
}