1 package gccgoexportdata_test
8 "golang.org/x/tools/go/gccgoexportdata"
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
15 // The testdata/{short,long}.a ELF archive files were produced by:
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
24 // The file long.a contains an archive string table.
26 // The errors.gox file (an ELF object file) comes from the toolchain's
28 func Test(t *testing.T) {
29 for _, test := range []struct {
30 filename, path, member, wantType string
32 {"testdata/errors.gox", "errors", "New", "func(text string) error"},
33 {"testdata/short.a", "short", "F", "func()"},
34 {"testdata/long.a", "long", "F", "func()"},
36 t.Logf("filename = %s", test.filename)
37 f, err := os.Open(test.filename)
43 r, err := gccgoexportdata.NewReader(f)
49 imports := make(map[string]*types.Package)
50 pkg, err := gccgoexportdata.Read(r, nil, imports, test.path)
56 // Check type of designated package member.
57 obj := pkg.Scope().Lookup(test.member)
59 t.Errorf("%s.%s not found", test.path, test.member)
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)