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 / gccgoexportdata / gccgoexportdata_test.go
1 package gccgoexportdata_test
2
3 import (
4         "go/types"
5         "os"
6         "testing"
7
8         "golang.org/x/tools/go/gccgoexportdata"
9 )
10
11 // Test ensures this package can read gccgo export data from the
12 // .go_export from a standalone ELF file or such a file in an archive
13 // library.
14 //
15 // The testdata/{short,long}.a ELF archive files were produced by:
16 //
17 //   $ echo 'package foo; func F()' > foo.go
18 //   $ gccgo -c -fgo-pkgpath blah foo.go
19 //   $ objcopy -j .go_export foo.o foo.gox
20 //   $ ar q short.a foo.gox
21 //   $ objcopy -j .go_export foo.o name-longer-than-16-bytes.gox
22 //   $ ar q long.a name-longer-than-16-bytes.gox
23 //
24 // The file long.a contains an archive string table.
25 //
26 // The errors.gox file (an ELF object file) comes from the toolchain's
27 // standard library.
28 func Test(t *testing.T) {
29         for _, test := range []struct {
30                 filename, path, member, wantType string
31         }{
32                 {"testdata/errors.gox", "errors", "New", "func(text string) error"},
33                 {"testdata/short.a", "short", "F", "func()"},
34                 {"testdata/long.a", "long", "F", "func()"},
35         } {
36                 t.Logf("filename = %s", test.filename)
37                 f, err := os.Open(test.filename)
38                 if err != nil {
39                         t.Error(err)
40                         continue
41                 }
42                 defer f.Close()
43                 r, err := gccgoexportdata.NewReader(f)
44                 if err != nil {
45                         t.Error(err)
46                         continue
47                 }
48
49                 imports := make(map[string]*types.Package)
50                 pkg, err := gccgoexportdata.Read(r, nil, imports, test.path)
51                 if err != nil {
52                         t.Error(err)
53                         continue
54                 }
55
56                 // Check type of designated package member.
57                 obj := pkg.Scope().Lookup(test.member)
58                 if obj == nil {
59                         t.Errorf("%s.%s not found", test.path, test.member)
60                         continue
61                 }
62                 if obj.Type().String() != test.wantType {
63                         t.Errorf("%s.%s.Type = %s, want %s",
64                                 test.path, test.member, obj.Type(), test.wantType)
65                 }
66         }
67 }