Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / golang.org / x / tools@v0.0.0-20201105173854-bc9fc8d8c4bc / go / internal / gccgoimporter / gccgoinstallation_test.go
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.
4
5 // Except for this comment, this file is a verbatim copy of the file
6 // with the same name in $GOROOT/src/go/internal/gccgoimporter.
7
8 package gccgoimporter
9
10 import (
11         "go/types"
12         "testing"
13 )
14
15 // importablePackages is a list of packages that we verify that we can
16 // import. This should be all standard library packages in all relevant
17 // versions of gccgo. Note that since gccgo follows a different release
18 // cycle, and since different systems have different versions installed,
19 // we can't use the last-two-versions rule of the gc toolchain.
20 var importablePackages = [...]string{
21         "archive/tar",
22         "archive/zip",
23         "bufio",
24         "bytes",
25         "compress/bzip2",
26         "compress/flate",
27         "compress/gzip",
28         "compress/lzw",
29         "compress/zlib",
30         "container/heap",
31         "container/list",
32         "container/ring",
33         "crypto/aes",
34         "crypto/cipher",
35         "crypto/des",
36         "crypto/dsa",
37         "crypto/ecdsa",
38         "crypto/elliptic",
39         "crypto",
40         "crypto/hmac",
41         "crypto/md5",
42         "crypto/rand",
43         "crypto/rc4",
44         "crypto/rsa",
45         "crypto/sha1",
46         "crypto/sha256",
47         "crypto/sha512",
48         "crypto/subtle",
49         "crypto/tls",
50         "crypto/x509",
51         "crypto/x509/pkix",
52         "database/sql/driver",
53         "database/sql",
54         "debug/dwarf",
55         "debug/elf",
56         "debug/gosym",
57         "debug/macho",
58         "debug/pe",
59         "encoding/ascii85",
60         "encoding/asn1",
61         "encoding/base32",
62         "encoding/base64",
63         "encoding/binary",
64         "encoding/csv",
65         "encoding/gob",
66         // "encoding", // Added in GCC 4.9.
67         "encoding/hex",
68         "encoding/json",
69         "encoding/pem",
70         "encoding/xml",
71         "errors",
72         "expvar",
73         "flag",
74         "fmt",
75         "go/ast",
76         "go/build",
77         "go/doc",
78         // "go/format", // Added in GCC 4.8.
79         "go/parser",
80         "go/printer",
81         "go/scanner",
82         "go/token",
83         "hash/adler32",
84         "hash/crc32",
85         "hash/crc64",
86         "hash/fnv",
87         "hash",
88         "html",
89         "html/template",
90         "image/color",
91         // "image/color/palette", // Added in GCC 4.9.
92         "image/draw",
93         "image/gif",
94         "image",
95         "image/jpeg",
96         "image/png",
97         "index/suffixarray",
98         "io",
99         "io/ioutil",
100         "log",
101         "log/syslog",
102         "math/big",
103         "math/cmplx",
104         "math",
105         "math/rand",
106         "mime",
107         "mime/multipart",
108         "net",
109         "net/http/cgi",
110         // "net/http/cookiejar", // Added in GCC 4.8.
111         "net/http/fcgi",
112         "net/http",
113         "net/http/httptest",
114         "net/http/httputil",
115         "net/http/pprof",
116         "net/mail",
117         "net/rpc",
118         "net/rpc/jsonrpc",
119         "net/smtp",
120         "net/textproto",
121         "net/url",
122         "os/exec",
123         "os",
124         "os/signal",
125         "os/user",
126         "path/filepath",
127         "path",
128         "reflect",
129         "regexp",
130         "regexp/syntax",
131         "runtime/debug",
132         "runtime",
133         "runtime/pprof",
134         "sort",
135         "strconv",
136         "strings",
137         "sync/atomic",
138         "sync",
139         "syscall",
140         "testing",
141         "testing/iotest",
142         "testing/quick",
143         "text/scanner",
144         "text/tabwriter",
145         "text/template",
146         "text/template/parse",
147         "time",
148         "unicode",
149         "unicode/utf16",
150         "unicode/utf8",
151 }
152
153 func TestInstallationImporter(t *testing.T) {
154         // This test relies on gccgo being around.
155         gpath := gccgoPath()
156         if gpath == "" {
157                 t.Skip("This test needs gccgo")
158         }
159
160         var inst GccgoInstallation
161         err := inst.InitFromDriver(gpath)
162         if err != nil {
163                 t.Fatal(err)
164         }
165         imp := inst.GetImporter(nil, nil)
166
167         // Ensure we don't regress the number of packages we can parse. First import
168         // all packages into the same map and then each individually.
169         pkgMap := make(map[string]*types.Package)
170         for _, pkg := range importablePackages {
171                 _, err = imp(pkgMap, pkg, ".", nil)
172                 if err != nil {
173                         t.Error(err)
174                 }
175         }
176
177         for _, pkg := range importablePackages {
178                 _, err = imp(make(map[string]*types.Package), pkg, ".", nil)
179                 if err != nil {
180                         t.Error(err)
181                 }
182         }
183
184         // Test for certain specific entities in the imported data.
185         for _, test := range [...]importerTest{
186                 {pkgpath: "io", name: "Reader", want: "type Reader interface{Read(p []byte) (n int, err error)}"},
187                 {pkgpath: "io", name: "ReadWriter", want: "type ReadWriter interface{Reader; Writer}"},
188                 {pkgpath: "math", name: "Pi", want: "const Pi untyped float"},
189                 {pkgpath: "math", name: "Sin", want: "func Sin(x float64) float64"},
190                 {pkgpath: "sort", name: "Ints", want: "func Ints(a []int)"},
191                 {pkgpath: "unsafe", name: "Pointer", want: "type Pointer"},
192         } {
193                 runImporterTest(t, imp, nil, &test)
194         }
195 }