@@ -11,7 +11,6 @@ import (
11
11
"os"
12
12
"os/exec"
13
13
"path/filepath"
14
- "runtime"
15
14
"testing"
16
15
)
17
16
@@ -53,9 +52,6 @@ func runImporterTest(t *testing.T, imp Importer, initmap map[*types.Package]Init
53
52
// Check that the package's own init function has the package's priority
54
53
for _ , pkginit := range initdata .Inits {
55
54
if pkginit .InitFunc == test .wantinits [0 ] {
56
- if initdata .Priority != pkginit .Priority {
57
- t .Errorf ("%s: got self priority %d; want %d" , test .pkgpath , pkginit .Priority , initdata .Priority )
58
- }
59
55
found = true
60
56
break
61
57
}
@@ -65,27 +61,11 @@ func runImporterTest(t *testing.T, imp Importer, initmap map[*types.Package]Init
65
61
t .Errorf ("%s: could not find expected function %q" , test .pkgpath , test .wantinits [0 ])
66
62
}
67
63
68
- // Each init function in the list other than the first one is a
69
- // dependency of the function immediately before it. Check that
70
- // the init functions appear in descending priority order.
71
- priority := initdata .Priority
72
- for _ , wantdepinit := range test .wantinits [1 :] {
73
- found = false
74
- for _ , pkginit := range initdata .Inits {
75
- if pkginit .InitFunc == wantdepinit {
76
- if priority <= pkginit .Priority {
77
- t .Errorf ("%s: got dep priority %d; want less than %d" , test .pkgpath , pkginit .Priority , priority )
78
- }
79
- found = true
80
- priority = pkginit .Priority
81
- break
82
- }
83
- }
84
-
85
- if ! found {
86
- t .Errorf ("%s: could not find expected function %q" , test .pkgpath , wantdepinit )
87
- }
88
- }
64
+ // FIXME: the original version of this test was written against
65
+ // the v1 export data scheme for capturing init functions, so it
66
+ // verified the priority values. We moved away from the priority
67
+ // scheme some time ago; it is not clear how much work it would be
68
+ // to validate the new init export data.
89
69
}
90
70
}
91
71
@@ -100,7 +80,7 @@ var importerTests = [...]importerTest{
100
80
{pkgpath : "time" , name : "Nanosecond" , want : "const Nanosecond Duration" , wantval : "1" },
101
81
{pkgpath : "unicode" , name : "IsUpper" , want : "func IsUpper(r rune) bool" },
102
82
{pkgpath : "unicode" , name : "MaxRune" , want : "const MaxRune untyped rune" , wantval : "1114111" },
103
- {pkgpath : "imports" , wantinits : []string {"imports..import" , "fmt..import" , "math..import" }},
83
+ {pkgpath : "imports" , wantinits : []string {"imports..import" , "fmt..import" }},
104
84
{pkgpath : "importsar" , name : "Hello" , want : "var Hello string" },
105
85
{pkgpath : "aliases" , name : "A14" , want : "type A14 = func(int, T0) chan T2" },
106
86
{pkgpath : "aliases" , name : "C0" , want : "type C0 struct{f1 C1; f2 C1}" },
@@ -109,8 +89,7 @@ var importerTests = [...]importerTest{
109
89
}
110
90
111
91
func TestGoxImporter (t * testing.T ) {
112
- testenv .MustHaveGoBuild (t )
113
-
92
+ testenv .MustHaveExec (t ) // this is to skip nacl, js
114
93
initmap := make (map [* types.Package ]InitData )
115
94
imp := GetImporter ([]string {"testdata" }, initmap )
116
95
@@ -119,12 +98,24 @@ func TestGoxImporter(t *testing.T) {
119
98
}
120
99
}
121
100
122
- func TestObjImporter (t * testing.T ) {
123
- testenv .MustHaveGoBuild (t )
101
+ // gccgoPath returns a path to gccgo if it is present (either in
102
+ // path or specified via GCCGO environment variable), or an
103
+ // empty string if no gccgo is available.
104
+ func gccgoPath () string {
105
+ gccgoname := os .Getenv ("GCCGO" )
106
+ if gccgoname == "" {
107
+ gccgoname = "gccgo"
108
+ }
109
+ if gpath , gerr := exec .LookPath (gccgoname ); gerr == nil {
110
+ return gpath
111
+ }
112
+ return ""
113
+ }
124
114
125
- // This test relies on gccgo being around, which it most likely will be if we
126
- // were compiled with gccgo.
127
- if runtime .Compiler != "gccgo" {
115
+ func TestObjImporter (t * testing.T ) {
116
+ // This test relies on gccgo being around.
117
+ gpath := gccgoPath ()
118
+ if gpath == "" {
128
119
t .Skip ("This test needs gccgo" )
129
120
}
130
121
@@ -144,10 +135,13 @@ func TestObjImporter(t *testing.T) {
144
135
145
136
for _ , test := range importerTests {
146
137
gofile := filepath .Join ("testdata" , test .pkgpath + ".go" )
138
+ if _ , err := os .Stat (gofile ); os .IsNotExist (err ) {
139
+ continue
140
+ }
147
141
ofile := filepath .Join (tmpdir , test .pkgpath + ".o" )
148
142
afile := filepath .Join (artmpdir , "lib" + test .pkgpath + ".a" )
149
143
150
- cmd := exec .Command ("gccgo" , "-fgo-pkgpath=" + test .pkgpath , "-c" , "-o" , ofile , gofile )
144
+ cmd := exec .Command (gpath , "-fgo-pkgpath=" + test .pkgpath , "-c" , "-o" , ofile , gofile )
151
145
out , err := cmd .CombinedOutput ()
152
146
if err != nil {
153
147
t .Logf ("%s" , out )
0 commit comments