Skip to content

Commit 792c3e6

Browse files
committed
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 <[email protected]>
1 parent b3c0be4 commit 792c3e6

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

go/types/objectpath/objectpath_test.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"go/parser"
1212
"go/token"
1313
"go/types"
14+
"strings"
1415
"testing"
1516

1617
"golang.org/x/tools/go/buildutil"
@@ -279,12 +280,22 @@ var Z map[string]struct{ A int }
279280
// Check the object strings match.
280281
// (We can't check that types are identical because the
281282
// objects belong to different type-checker realms.)
282-
srcstr := types.ObjectString(srcobj, (*types.Package).Name)
283-
binstr := types.ObjectString(binobj, (*types.Package).Name)
283+
srcstr := objectString(srcobj)
284+
binstr := objectString(binobj)
284285
if srcstr != binstr {
285286
t.Errorf("ObjectStrings do not match: Object(For(%q)) = %s, want %s",
286287
path, srcstr, binstr)
287288
continue
288289
}
289290
}
290291
}
292+
293+
func objectString(obj types.Object) string {
294+
s := types.ObjectString(obj, (*types.Package).Name)
295+
296+
// The printing of interface methods changed in go1.11.
297+
// This work-around makes the specific test pass with earlier versions.
298+
s = strings.Replace(s, "func (interface).Method", "func (p.Foo).Method", -1)
299+
300+
return s
301+
}

0 commit comments

Comments
 (0)