@@ -14,7 +14,8 @@ import (
14
14
"os"
15
15
"os/exec"
16
16
"path/filepath"
17
- "runtime"
17
+ "regexp"
18
+ "strconv"
18
19
"testing"
19
20
)
20
21
@@ -56,9 +57,6 @@ func runImporterTest(t *testing.T, imp Importer, initmap map[*types.Package]Init
56
57
// Check that the package's own init function has the package's priority
57
58
for _ , pkginit := range initdata .Inits {
58
59
if pkginit .InitFunc == test .wantinits [0 ] {
59
- if initdata .Priority != pkginit .Priority {
60
- t .Errorf ("%s: got self priority %d; want %d" , test .pkgpath , pkginit .Priority , initdata .Priority )
61
- }
62
60
found = true
63
61
break
64
62
}
@@ -68,27 +66,11 @@ func runImporterTest(t *testing.T, imp Importer, initmap map[*types.Package]Init
68
66
t .Errorf ("%s: could not find expected function %q" , test .pkgpath , test .wantinits [0 ])
69
67
}
70
68
71
- // Each init function in the list other than the first one is a
72
- // dependency of the function immediately before it. Check that
73
- // the init functions appear in descending priority order.
74
- priority := initdata .Priority
75
- for _ , wantdepinit := range test .wantinits [1 :] {
76
- found = false
77
- for _ , pkginit := range initdata .Inits {
78
- if pkginit .InitFunc == wantdepinit {
79
- if priority <= pkginit .Priority {
80
- t .Errorf ("%s: got dep priority %d; want less than %d" , test .pkgpath , pkginit .Priority , priority )
81
- }
82
- found = true
83
- priority = pkginit .Priority
84
- break
85
- }
86
- }
87
-
88
- if ! found {
89
- t .Errorf ("%s: could not find expected function %q" , test .pkgpath , wantdepinit )
90
- }
91
- }
69
+ // FIXME: the original version of this test was written against
70
+ // the v1 export data scheme for capturing init functions, so it
71
+ // verified the priority values. We moved away from the priority
72
+ // scheme some time ago; it is not clear how much work it would be
73
+ // to validate the new init export data.
92
74
}
93
75
}
94
76
@@ -103,17 +85,17 @@ var importerTests = [...]importerTest{
103
85
{pkgpath : "time" , name : "Nanosecond" , want : "const Nanosecond Duration" , wantval : "1" },
104
86
{pkgpath : "unicode" , name : "IsUpper" , want : "func IsUpper(r rune) bool" },
105
87
{pkgpath : "unicode" , name : "MaxRune" , want : "const MaxRune untyped rune" , wantval : "1114111" },
106
- {pkgpath : "imports" , wantinits : []string {"imports..import" , "fmt..import" , "math..import" }},
88
+ {pkgpath : "imports" , wantinits : []string {"imports..import" , "fmt..import" }},
107
89
{pkgpath : "importsar" , name : "Hello" , want : "var Hello string" },
108
90
{pkgpath : "aliases" , name : "A14" , want : "type A14 = func(int, T0) chan T2" },
109
91
{pkgpath : "aliases" , name : "C0" , want : "type C0 struct{f1 C1; f2 C1}" },
110
92
{pkgpath : "escapeinfo" , name : "NewT" , want : "func NewT(data []byte) *T" },
111
93
{pkgpath : "issue27856" , name : "M" , want : "type M struct{E F}" },
94
+ {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}" },
112
95
}
113
96
114
97
func TestGoxImporter (t * testing.T ) {
115
- testenv .MustHaveGoBuild (t )
116
-
98
+ testenv .MustHaveExec (t ) // this is to skip nacl, js
117
99
initmap := make (map [* types.Package ]InitData )
118
100
imp := GetImporter ([]string {"testdata" }, initmap )
119
101
@@ -122,15 +104,46 @@ func TestGoxImporter(t *testing.T) {
122
104
}
123
105
}
124
106
125
- func TestObjImporter (t * testing.T ) {
126
- testenv .MustHaveGoBuild (t )
107
+ // gccgoPath returns a path to gccgo if it is present (either in
108
+ // path or specified via GCCGO environment variable), or an
109
+ // empty string if no gccgo is available.
110
+ func gccgoPath () string {
111
+ gccgoname := os .Getenv ("GCCGO" )
112
+ if gccgoname == "" {
113
+ gccgoname = "gccgo"
114
+ }
115
+ if gpath , gerr := exec .LookPath (gccgoname ); gerr == nil {
116
+ return gpath
117
+ }
118
+ return ""
119
+ }
127
120
128
- // This test relies on gccgo being around, which it most likely will be if we
129
- // were compiled with gccgo.
130
- if runtime .Compiler != "gccgo" {
121
+ func TestObjImporter (t * testing.T ) {
122
+ // This test relies on gccgo being around.
123
+ gpath := gccgoPath ()
124
+ if gpath == "" {
131
125
t .Skip ("This test needs gccgo" )
132
126
}
133
127
128
+ verout , err := exec .Command (gpath , "--version" ).CombinedOutput ()
129
+ if err != nil {
130
+ t .Logf ("%s" , verout )
131
+ t .Fatal (err )
132
+ }
133
+ vers := regexp .MustCompile (`([0-9]+)\.([0-9]+)` ).FindSubmatch (verout )
134
+ if len (vers ) == 0 {
135
+ t .Fatalf ("could not find version number in %s" , verout )
136
+ }
137
+ major , err := strconv .Atoi (string (vers [1 ]))
138
+ if err != nil {
139
+ t .Fatal (err )
140
+ }
141
+ minor , err := strconv .Atoi (string (vers [2 ]))
142
+ if err != nil {
143
+ t .Fatal (err )
144
+ }
145
+ t .Logf ("gccgo version %d.%d" , major , minor )
146
+
134
147
tmpdir , err := ioutil .TempDir ("" , "" )
135
148
if err != nil {
136
149
t .Fatal (err )
@@ -146,11 +159,22 @@ func TestObjImporter(t *testing.T) {
146
159
arimp := GetImporter ([]string {artmpdir }, arinitmap )
147
160
148
161
for _ , test := range importerTests {
162
+ // Support for type aliases was added in GCC 7.
163
+ if test .pkgpath == "aliases" || test .pkgpath == "issue27856" {
164
+ if major < 7 {
165
+ t .Logf ("skipping %q: not supported before gccgo version 7" , test .pkgpath )
166
+ continue
167
+ }
168
+ }
169
+
149
170
gofile := filepath .Join ("testdata" , test .pkgpath + ".go" )
171
+ if _ , err := os .Stat (gofile ); os .IsNotExist (err ) {
172
+ continue
173
+ }
150
174
ofile := filepath .Join (tmpdir , test .pkgpath + ".o" )
151
175
afile := filepath .Join (artmpdir , "lib" + test .pkgpath + ".a" )
152
176
153
- cmd := exec .Command ("gccgo" , "-fgo-pkgpath=" + test .pkgpath , "-c" , "-o" , ofile , gofile )
177
+ cmd := exec .Command (gpath , "-fgo-pkgpath=" + test .pkgpath , "-c" , "-o" , ofile , gofile )
154
178
out , err := cmd .CombinedOutput ()
155
179
if err != nil {
156
180
t .Logf ("%s" , out )
0 commit comments