Debian Codegraph @

go/gccgoexportdata/gccgoexportdata_test.go

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