Skip to content

Commit ab5cee5

Browse files
committed
go/internal/gccgoimporter: skip new test with aliases with old gccgo
Add the issue31540 test to the list of tests that needs to be skipped with old copies of gccgo. Along the way, add an explicit field to the importer test struct that can be used to tag the test (as opposed to having special cases by name in the test routine), so as to make it easier to remember to tag testcases correctly. Fixes #31764. Change-Id: Ib9d98fea2df8ce0b51e5a886fb2c4acd6db490ff Reviewed-on: https://go-review.googlesource.com/c/go/+/174738 Reviewed-by: Ian Lance Taylor <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 40036a9 commit ab5cee5

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/go/internal/gccgoimporter/importer_test.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
type importerTest struct {
2020
pkgpath, name, want, wantval string
2121
wantinits []string
22+
gccgoVersion int // minimum gccgo version (0 => any)
2223
}
2324

2425
func runImporterTest(t *testing.T, imp Importer, initmap map[*types.Package]InitData, test *importerTest) {
@@ -71,6 +72,8 @@ func runImporterTest(t *testing.T, imp Importer, initmap map[*types.Package]Init
7172
}
7273
}
7374

75+
// When adding tests to this list, be sure to set the 'gccgoVersion'
76+
// field if the testcases uses a "recent" Go addition (ex: aliases).
7477
var importerTests = [...]importerTest{
7578
{pkgpath: "pointer", name: "Int8Ptr", want: "type Int8Ptr *int8"},
7679
{pkgpath: "complexnums", name: "NN", want: "const NN untyped complex", wantval: "(-1 + -1i)"},
@@ -84,15 +87,15 @@ var importerTests = [...]importerTest{
8487
{pkgpath: "unicode", name: "MaxRune", want: "const MaxRune untyped rune", wantval: "1114111"},
8588
{pkgpath: "imports", wantinits: []string{"imports..import", "fmt..import"}},
8689
{pkgpath: "importsar", name: "Hello", want: "var Hello string"},
87-
{pkgpath: "aliases", name: "A14", want: "type A14 = func(int, T0) chan T2"},
88-
{pkgpath: "aliases", name: "C0", want: "type C0 struct{f1 C1; f2 C1}"},
90+
{pkgpath: "aliases", name: "A14", gccgoVersion: 7, want: "type A14 = func(int, T0) chan T2"},
91+
{pkgpath: "aliases", name: "C0", gccgoVersion: 7, want: "type C0 struct{f1 C1; f2 C1}"},
8992
{pkgpath: "escapeinfo", name: "NewT", want: "func NewT(data []byte) *T"},
90-
{pkgpath: "issue27856", name: "M", want: "type M struct{E F}"},
93+
{pkgpath: "issue27856", name: "M", gccgoVersion: 7, want: "type M struct{E F}"},
9194
{pkgpath: "v1reflect", name: "Type", want: "type Type interface{Align() int; AssignableTo(u Type) bool; Bits() int; ChanDir() ChanDir; Elem() Type; Field(i int) StructField; FieldAlign() int; FieldByIndex(index []int) StructField; FieldByName(name string) (StructField, bool); FieldByNameFunc(match func(string) bool) (StructField, bool); Implements(u Type) bool; In(i int) Type; IsVariadic() bool; Key() Type; Kind() Kind; Len() int; Method(int) Method; MethodByName(string) (Method, bool); Name() string; NumField() int; NumIn() int; NumMethod() int; NumOut() int; Out(i int) Type; PkgPath() string; Size() uintptr; String() string; common() *commonType; rawString() string; runtimeType() *runtimeType; uncommon() *uncommonType}"},
9295
{pkgpath: "nointerface", name: "I", want: "type I int"},
93-
{pkgpath: "issue29198", name: "FooServer", want: "type FooServer struct{FooServer *FooServer; user string; ctx context.Context}"},
96+
{pkgpath: "issue29198", name: "FooServer", gccgoVersion: 7, want: "type FooServer struct{FooServer *FooServer; user string; ctx context.Context}"},
9497
{pkgpath: "issue30628", name: "Apple", want: "type Apple struct{hey sync.RWMutex; x int; RQ [517]struct{Count uintptr; NumBytes uintptr; Last uintptr}}"},
95-
{pkgpath: "issue31540", name: "S", want: "type S struct{b int; map[Y]Z}"},
98+
{pkgpath: "issue31540", name: "S", gccgoVersion: 7, want: "type S struct{b int; map[Y]Z}"},
9699
}
97100

98101
func TestGoxImporter(t *testing.T) {
@@ -164,12 +167,10 @@ func TestObjImporter(t *testing.T) {
164167
arimp := GetImporter([]string{artmpdir}, arinitmap)
165168

166169
for _, test := range importerTests {
167-
// Support for type aliases was added in GCC 7.
168-
if test.pkgpath == "aliases" || test.pkgpath == "issue27856" || test.pkgpath == "issue29198" {
169-
if major < 7 {
170-
t.Logf("skipping %q: not supported before gccgo version 7", test.pkgpath)
171-
continue
172-
}
170+
if major < test.gccgoVersion {
171+
// Support for type aliases was added in GCC 7.
172+
t.Logf("skipping %q: not supported before gccgo version %d", test.pkgpath, test.gccgoVersion)
173+
continue
173174
}
174175

175176
gofile := filepath.Join("testdata", test.pkgpath+".go")

0 commit comments

Comments
 (0)