libgo: update to Go1.10rc2
[official-gcc.git] / libgo / go / go / internal / gccgoimporter / gccgoinstallation_test.go
blob299910de284e77324fcde27e31c3b1fb303a788b
1 // Copyright 2013 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 package gccgoimporter
7 import (
8 "go/types"
9 "runtime"
10 "testing"
13 var importablePackages = [...]string{
14 "archive/tar",
15 "archive/zip",
16 "bufio",
17 "bytes",
18 "compress/bzip2",
19 "compress/flate",
20 "compress/gzip",
21 "compress/lzw",
22 "compress/zlib",
23 "container/heap",
24 "container/list",
25 "container/ring",
26 "crypto/aes",
27 "crypto/cipher",
28 "crypto/des",
29 "crypto/dsa",
30 "crypto/ecdsa",
31 "crypto/elliptic",
32 "crypto",
33 "crypto/hmac",
34 "crypto/md5",
35 "crypto/rand",
36 "crypto/rc4",
37 "crypto/rsa",
38 "crypto/sha1",
39 "crypto/sha256",
40 "crypto/sha512",
41 "crypto/subtle",
42 "crypto/tls",
43 "crypto/x509",
44 "crypto/x509/pkix",
45 "database/sql/driver",
46 "database/sql",
47 "debug/dwarf",
48 "debug/elf",
49 "debug/gosym",
50 "debug/macho",
51 "debug/pe",
52 "encoding/ascii85",
53 "encoding/asn1",
54 "encoding/base32",
55 "encoding/base64",
56 "encoding/binary",
57 "encoding/csv",
58 "encoding/gob",
59 "encoding",
60 "encoding/hex",
61 "encoding/json",
62 "encoding/pem",
63 "encoding/xml",
64 "errors",
65 "expvar",
66 "flag",
67 "fmt",
68 "go/ast",
69 "go/build",
70 "go/doc",
71 "go/format",
72 "go/parser",
73 "go/printer",
74 "go/scanner",
75 "go/token",
76 "hash/adler32",
77 "hash/crc32",
78 "hash/crc64",
79 "hash/fnv",
80 "hash",
81 "html",
82 "html/template",
83 "image/color",
84 "image/color/palette",
85 "image/draw",
86 "image/gif",
87 "image",
88 "image/jpeg",
89 "image/png",
90 "index/suffixarray",
91 "io",
92 "io/ioutil",
93 "log",
94 "log/syslog",
95 "math/big",
96 "math/cmplx",
97 "math",
98 "math/rand",
99 "mime",
100 "mime/multipart",
101 "net",
102 "net/http/cgi",
103 "net/http/cookiejar",
104 "net/http/fcgi",
105 "net/http",
106 "net/http/httptest",
107 "net/http/httputil",
108 "net/http/pprof",
109 "net/mail",
110 "net/rpc",
111 "net/rpc/jsonrpc",
112 "net/smtp",
113 "net/textproto",
114 "net/url",
115 "os/exec",
116 "os",
117 "os/signal",
118 "os/user",
119 "path/filepath",
120 "path",
121 "reflect",
122 "regexp",
123 "regexp/syntax",
124 "runtime/debug",
125 "runtime",
126 "runtime/pprof",
127 "sort",
128 "strconv",
129 "strings",
130 "sync/atomic",
131 "sync",
132 "syscall",
133 "testing",
134 "testing/iotest",
135 "testing/quick",
136 "text/scanner",
137 "text/tabwriter",
138 "text/template",
139 "text/template/parse",
140 "time",
141 "unicode",
142 "unicode/utf16",
143 "unicode/utf8",
146 func TestInstallationImporter(t *testing.T) {
147 // This test relies on gccgo being around, which it most likely will be if we
148 // were compiled with gccgo.
149 if runtime.Compiler != "gccgo" {
150 t.Skip("This test needs gccgo")
153 // Even when we have gccgo, this doesn't work while building
154 // gccgo itself.
155 t.Skip("gccgo is not necessarily available")
157 var inst GccgoInstallation
158 err := inst.InitFromDriver("gccgo")
159 if err != nil {
160 t.Fatal(err)
162 imp := inst.GetImporter(nil, nil)
164 // Ensure we don't regress the number of packages we can parse. First import
165 // all packages into the same map and then each individually.
166 pkgMap := make(map[string]*types.Package)
167 for _, pkg := range importablePackages {
168 _, err = imp(pkgMap, pkg, ".", nil)
169 if err != nil {
170 t.Error(err)
174 for _, pkg := range importablePackages {
175 _, err = imp(make(map[string]*types.Package), pkg, ".", nil)
176 if err != nil {
177 t.Error(err)
181 // Test for certain specific entities in the imported data.
182 for _, test := range [...]importerTest{
183 {pkgpath: "io", name: "Reader", want: "type Reader interface{Read(p []uint8) (n int, err error)}"},
184 {pkgpath: "io", name: "ReadWriter", want: "type ReadWriter interface{Reader; Writer}"},
185 {pkgpath: "math", name: "Pi", want: "const Pi untyped float"},
186 {pkgpath: "math", name: "Sin", want: "func Sin(x float64) float64"},
187 {pkgpath: "sort", name: "Ints", want: "func Ints(a []int)"},
188 {pkgpath: "unsafe", name: "Pointer", want: "type Pointer unsafe.Pointer"},
190 runImporterTest(t, imp, nil, &test)