1
2
3
4
5
6
7
8 package gccgoimporter
9
10 import (
11 "go/types"
12 "runtime"
13 "testing"
14 )
15
16
17
18
19
20
21 var importablePackages = [...]string{
22 "archive/tar",
23 "archive/zip",
24 "bufio",
25 "bytes",
26 "compress/bzip2",
27 "compress/flate",
28 "compress/gzip",
29 "compress/lzw",
30 "compress/zlib",
31 "container/heap",
32 "container/list",
33 "container/ring",
34 "crypto/aes",
35 "crypto/cipher",
36 "crypto/des",
37 "crypto/dsa",
38 "crypto/ecdsa",
39 "crypto/elliptic",
40 "crypto",
41 "crypto/hmac",
42 "crypto/md5",
43 "crypto/rand",
44 "crypto/rc4",
45 "crypto/rsa",
46 "crypto/sha1",
47 "crypto/sha256",
48 "crypto/sha512",
49 "crypto/subtle",
50 "crypto/tls",
51 "crypto/x509",
52 "crypto/x509/pkix",
53 "database/sql/driver",
54 "database/sql",
55 "debug/dwarf",
56 "debug/elf",
57 "debug/gosym",
58 "debug/macho",
59 "debug/pe",
60 "encoding/ascii85",
61 "encoding/asn1",
62 "encoding/base32",
63 "encoding/base64",
64 "encoding/binary",
65 "encoding/csv",
66 "encoding/gob",
67
68 "encoding/hex",
69 "encoding/json",
70 "encoding/pem",
71 "encoding/xml",
72 "errors",
73 "expvar",
74 "flag",
75 "fmt",
76 "go/ast",
77 "go/build",
78 "go/doc",
79
80 "go/parser",
81 "go/printer",
82 "go/scanner",
83 "go/token",
84 "hash/adler32",
85 "hash/crc32",
86 "hash/crc64",
87 "hash/fnv",
88 "hash",
89 "html",
90 "html/template",
91 "image/color",
92
93 "image/draw",
94 "image/gif",
95 "image",
96 "image/jpeg",
97 "image/png",
98 "index/suffixarray",
99 "io",
100 "io/ioutil",
101 "log",
102 "log/syslog",
103 "math/big",
104 "math/cmplx",
105 "math",
106 "math/rand",
107 "mime",
108 "mime/multipart",
109 "net",
110 "net/http/cgi",
111
112 "net/http/fcgi",
113 "net/http",
114 "net/http/httptest",
115 "net/http/httputil",
116 "net/http/pprof",
117 "net/mail",
118 "net/rpc",
119 "net/rpc/jsonrpc",
120 "net/smtp",
121 "net/textproto",
122 "net/url",
123 "os/exec",
124 "os",
125 "os/signal",
126 "os/user",
127 "path/filepath",
128 "path",
129 "reflect",
130 "regexp",
131 "regexp/syntax",
132 "runtime/debug",
133 "runtime",
134 "runtime/pprof",
135 "sort",
136 "strconv",
137 "strings",
138 "sync/atomic",
139 "sync",
140 "syscall",
141 "testing",
142 "testing/iotest",
143 "testing/quick",
144 "text/scanner",
145 "text/tabwriter",
146 "text/template",
147 "text/template/parse",
148 "time",
149 "unicode",
150 "unicode/utf16",
151 "unicode/utf8",
152 }
153
154 func TestInstallationImporter(t *testing.T) {
155
156 gpath := gccgoPath()
157 if gpath == "" {
158 t.Skip("This test needs gccgo")
159 }
160 if runtime.GOOS == "aix" {
161
162
163
164 t.Skip("no support yet for debug/xcoff")
165 }
166
167 var inst GccgoInstallation
168 err := inst.InitFromDriver(gpath)
169 if err != nil {
170 t.Fatal(err)
171 }
172 imp := inst.GetImporter(nil, nil)
173
174
175
176 pkgMap := make(map[string]*types.Package)
177 for _, pkg := range importablePackages {
178 _, err = imp(pkgMap, pkg, ".", nil)
179 if err != nil {
180 t.Error(err)
181 }
182 }
183
184 for _, pkg := range importablePackages {
185 _, err = imp(make(map[string]*types.Package), pkg, ".", nil)
186 if err != nil {
187 t.Error(err)
188 }
189 }
190
191
192 for _, test := range [...]importerTest{
193 {pkgpath: "io", name: "Reader", want: "type Reader interface{Read(p []byte) (n int, err error)}"},
194 {pkgpath: "io", name: "ReadWriter", want: "type ReadWriter interface{Reader; Writer}"},
195 {pkgpath: "math", name: "Pi", want: "const Pi untyped float"},
196 {pkgpath: "math", name: "Sin", want: "func Sin(x float64) float64"},
197 {pkgpath: "sort", name: "Search", want: "func Search(n int, f func(int) bool) int"},
198 {pkgpath: "unsafe", name: "Pointer", want: "type Pointer"},
199 } {
200 runImporterTest(t, imp, nil, &test)
201 }
202 }
203
View as plain text