| 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 without |
| 7 | // the import of "testenv". |
| 8 | |
| 9 | package gccgoimporterscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/ |
| 10 | |
| 11 | import ( |
| 12 | "go/typesscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/" |
| 13 | "osscip-go gomod github.com/golang/go/src go1.25.0 os/" |
| 14 | "os/execscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/" |
| 15 | "path/filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/" |
| 16 | "regexpscip-go gomod github.com/golang/go/src go1.25.0 regexp/" |
| 17 | "runtimescip-go gomod github.com/golang/go/src go1.25.0 runtime/" |
| 18 | "strconvscip-go gomod github.com/golang/go/src go1.25.0 strconv/" |
| 19 | "testingscip-go gomod github.com/golang/go/src go1.25.0 testing/" |
| 20 | ) |
| 21 | |
| 22 | type importerTestscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest# struct { |
| 23 | pkgpathscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#pkgpath., namescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#name., wantscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#want., wantvalscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#wantval. string |
| 24 | wantinitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#wantinits. []string |
| 25 | gccgoVersionscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#gccgoVersion. int // minimum gccgo version (0 => any) |
| 26 | } |
| 27 | |
| 28 | func runImporterTestscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/runImporterTest().(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#, imp Importerscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/Importer#, initmap map[*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#]InitDatascip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/InitData#, test *importerTestscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#) { |
| 29 | pkg, err := imp(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#), test.pkgpathscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#pkgpath., ".", nil) |
| 30 | if err != nil { |
| 31 | t.Errorscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Error().(err) |
| 32 | return |
| 33 | } |
| 34 | |
| 35 | if test.namescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#name. != "" { |
| 36 | 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.namescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#name.) |
| 37 | if obj == nil { |
| 38 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("%s: object not found", test.namescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#name.) |
| 39 | return |
| 40 | } |
| 41 | |
| 42 | got := typesscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/.ObjectStringscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/ObjectString().(obj, typesscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/.RelativeToscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/RelativeTo().(pkg)) |
| 43 | if got != test.wantscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#want. { |
| 44 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("%s: got %q; want %q", test.namescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#name., got, test.wantscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#want.) |
| 45 | } |
| 46 | |
| 47 | if test.wantvalscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#wantval. != "" { |
| 48 | gotval := obj.(*typesscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/.Constscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Const#).Valscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Const#Val().().Stringscip-go gomod github.com/golang/go/src go1.25.0 `go/constant`/Value#String().() |
| 49 | if gotval != test.wantvalscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#wantval. { |
| 50 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("%s: got val %q; want val %q", test.namescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#name., gotval, test.wantvalscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#wantval.) |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | if len(test.wantinitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#wantinits.) > 0 { |
| 56 | initdata := initmap[pkg] |
| 57 | found := false |
| 58 | // Check that the package's own init function has the package's priority |
| 59 | for _, pkginit := range initdata.Initsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/InitData#Inits. { |
| 60 | if pkginit.InitFuncscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/PackageInit#InitFunc. == test.wantinitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#wantinits.[0] { |
| 61 | found = true |
| 62 | break |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | if !found { |
| 67 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("%s: could not find expected function %q", test.pkgpathscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#pkgpath., test.wantinitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#wantinits.[0]) |
| 68 | } |
| 69 | |
| 70 | // FIXME: the original version of this test was written against |
| 71 | // the v1 export data scheme for capturing init functions, so it |
| 72 | // verified the priority values. We moved away from the priority |
| 73 | // scheme some time ago; it is not clear how much work it would be |
| 74 | // to validate the new init export data. |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | // When adding tests to this list, be sure to set the 'gccgoVersion' |
| 79 | // field if the testcases uses a "recent" Go addition (ex: aliases). |
| 80 | var importerTestsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTests. = [...]importerTestscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#{ |
| 81 | {pkgpathscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#pkgpath.: "pointer", namescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#name.: "Int8Ptr", wantscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#want.: "type Int8Ptr *int8"}, |
| 82 | {pkgpathscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#pkgpath.: "complexnums", namescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#name.: "NN", wantscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#want.: "const NN untyped complex", wantvalscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#wantval.: "(-1 + -1i)"}, |
| 83 | {pkgpathscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#pkgpath.: "complexnums", namescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#name.: "NP", wantscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#want.: "const NP untyped complex", wantvalscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#wantval.: "(-1 + 1i)"}, |
| 84 | {pkgpathscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#pkgpath.: "complexnums", namescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#name.: "PN", wantscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#want.: "const PN untyped complex", wantvalscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#wantval.: "(1 + -1i)"}, |
| 85 | {pkgpathscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#pkgpath.: "complexnums", namescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#name.: "PP", wantscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#want.: "const PP untyped complex", wantvalscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#wantval.: "(1 + 1i)"}, |
| 86 | {pkgpathscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#pkgpath.: "conversions", namescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#name.: "Bits", wantscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#want.: "const Bits Units", wantvalscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#wantval.: `"bits"`}, |
| 87 | {pkgpathscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#pkgpath.: "time", namescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#name.: "Duration", wantscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#want.: "type Duration int64"}, |
| 88 | {pkgpathscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#pkgpath.: "time", namescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#name.: "Nanosecond", wantscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#want.: "const Nanosecond Duration", wantvalscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#wantval.: "1"}, |
| 89 | {pkgpathscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#pkgpath.: "unicode", namescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#name.: "IsUpper", wantscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#want.: "func IsUpper(r rune) bool"}, |
| 90 | {pkgpathscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#pkgpath.: "unicode", namescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#name.: "MaxRune", wantscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#want.: "const MaxRune untyped rune", wantvalscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#wantval.: "1114111"}, |
| 91 | {pkgpathscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#pkgpath.: "imports", wantinitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#wantinits.: []string{"imports..import", "fmt..import"}}, |
| 92 | {pkgpathscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#pkgpath.: "importsar", namescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#name.: "Hello", wantscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#want.: "var Hello string"}, |
| 93 | {pkgpathscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#pkgpath.: "aliases", namescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#name.: "A14", gccgoVersionscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#gccgoVersion.: 7, wantscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#want.: "type A14 = func(int, T0) chan T2"}, |
| 94 | {pkgpathscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#pkgpath.: "aliases", namescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#name.: "C0", gccgoVersionscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#gccgoVersion.: 7, wantscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#want.: "type C0 struct{f1 C1; f2 C1}"}, |
| 95 | {pkgpathscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#pkgpath.: "escapeinfo", namescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#name.: "NewT", wantscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#want.: "func NewT(data []byte) *T"}, |
| 96 | {pkgpathscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#pkgpath.: "issue27856", namescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#name.: "M", gccgoVersionscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#gccgoVersion.: 7, wantscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#want.: "type M struct{E F}"}, |
| 97 | {pkgpathscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#pkgpath.: "v1reflect", namescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#name.: "Type", wantscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#want.: "type Type interface{Align() int; AssignableTo(u Type) bool; Bits() int; ChanDir() ChanDir; Elem() Type; Field(i int) StructField; FieldAlign() int; FieldByIndex(index []int) StructField; FieldByName(name string) (StructField, bool); FieldByNameFunc(match func(string) bool) (StructField, bool); Implements(u Type) bool; In(i int) Type; IsVariadic() bool; Key() Type; Kind() Kind; Len() int; Method(int) Method; MethodByName(string) (Method, bool); Name() string; NumField() int; NumIn() int; NumMethod() int; NumOut() int; Out(i int) Type; PkgPath() string; Size() uintptr; String() string; common() *commonType; rawString() string; runtimeType() *runtimeType; uncommon() *uncommonType}"}, |
| 98 | {pkgpathscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#pkgpath.: "nointerface", namescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#name.: "I", wantscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#want.: "type I int"}, |
| 99 | {pkgpathscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#pkgpath.: "issue29198", namescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#name.: "FooServer", gccgoVersionscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#gccgoVersion.: 7, wantscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#want.: "type FooServer struct{FooServer *FooServer; user string; ctx context.Context}"}, |
| 100 | {pkgpathscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#pkgpath.: "issue30628", namescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#name.: "Apple", wantscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#want.: "type Apple struct{hey sync.RWMutex; x int; RQ [517]struct{Count uintptr; NumBytes uintptr; Last uintptr}}"}, |
| 101 | {pkgpathscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#pkgpath.: "issue31540", namescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#name.: "S", gccgoVersionscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#gccgoVersion.: 7, wantscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#want.: "type S struct{b int; map[Y]Z}"}, |
| 102 | {pkgpathscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#pkgpath.: "issue34182", namescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#name.: "T1", wantscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#want.: "type T1 struct{f *T2}"}, |
| 103 | {pkgpathscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#pkgpath.: "notinheap", namescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#name.: "S", wantscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#want.: "type S struct{}"}, |
| 104 | } |
| 105 | |
| 106 | func TestGoxImporterscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/TestGoxImporter().(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#) { |
| 107 | testenvscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/testenv..MustHaveExecscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/testenv:MustHaveExec.(t) // this is to skip nacl, js |
| 108 | initmap := make(map[*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#]InitDatascip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/InitData#) |
| 109 | imp := GetImporterscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/GetImporter().([]string{"testdata"}, initmap) |
| 110 | |
| 111 | for _, test := range importerTestsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTests. { |
| 112 | runImporterTestscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/runImporterTest().(t, imp, initmap, &test) |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | // gccgoPath returns a path to gccgo if it is present (either in |
| 117 | // path or specified via GCCGO environment variable), or an |
| 118 | // empty string if no gccgo is available. |
| 119 | func gccgoPathscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/gccgoPath().() string { |
| 120 | gccgoname := osscip-go gomod github.com/golang/go/src go1.25.0 os/.Getenvscip-go gomod github.com/golang/go/src go1.25.0 os/Getenv().("GCCGO") |
| 121 | if gccgoname == "" { |
| 122 | gccgoname = "gccgo" |
| 123 | } |
| 124 | if gpath, gerr := execscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/.LookPathscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/LookPath().(gccgoname); gerr == nil { |
| 125 | return gpath |
| 126 | } |
| 127 | return "" |
| 128 | } |
| 129 | |
| 130 | func TestObjImporterscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/TestObjImporter().(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#) { |
| 131 | // This test relies on gccgo being around. |
| 132 | gpath := gccgoPathscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/gccgoPath().() |
| 133 | if gpath == "" { |
| 134 | t.Skipscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Skip().("This test needs gccgo") |
| 135 | } |
| 136 | if runtimescip-go gomod github.com/golang/go/src go1.25.0 runtime/.GOOSscip-go gomod github.com/golang/go/src go1.25.0 runtime/GOOS. == "aix" { |
| 137 | // We don't yet have a debug/xcoff package for reading |
| 138 | // object files on AIX. Remove this skip if/when issue #29038 |
| 139 | // is implemented (see also issue #49445). |
| 140 | t.Skipscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Skip().("no support yet for debug/xcoff") |
| 141 | } |
| 142 | |
| 143 | verout, err := execscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/.Commandscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/Command().(gpath, "--version").Outputscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/Cmd#Output().() |
| 144 | if err != nil { |
| 145 | t.Logfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Logf().("%s", verout) |
| 146 | if exit, ok := err.(*execscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/.ExitErrorscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/ExitError#); ok && len(exit.Stderrscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/ExitError#Stderr.) > 0 { |
| 147 | t.Logfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Logf().("stderr:\n%s", exit.Stderrscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/ExitError#Stderr.) |
| 148 | } |
| 149 | t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().(err) |
| 150 | } |
| 151 | vers := regexpscip-go gomod github.com/golang/go/src go1.25.0 regexp/.MustCompilescip-go gomod github.com/golang/go/src go1.25.0 regexp/MustCompile().(`([0-9]+)\.([0-9]+)`).FindSubmatchscip-go gomod github.com/golang/go/src go1.25.0 regexp/Regexp#FindSubmatch().(verout) |
| 152 | if len(vers) == 0 { |
| 153 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("could not find version number in %s", verout) |
| 154 | } |
| 155 | major, err := strconvscip-go gomod github.com/golang/go/src go1.25.0 strconv/.Atoiscip-go gomod github.com/golang/go/src go1.25.0 strconv/Atoi().(string(vers[1])) |
| 156 | if err != nil { |
| 157 | t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().(err) |
| 158 | } |
| 159 | minor, err := strconvscip-go gomod github.com/golang/go/src go1.25.0 strconv/.Atoiscip-go gomod github.com/golang/go/src go1.25.0 strconv/Atoi().(string(vers[2])) |
| 160 | if err != nil { |
| 161 | t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().(err) |
| 162 | } |
| 163 | t.Logfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Logf().("gccgo version %d.%d", major, minor) |
| 164 | |
| 165 | tmpdir := t.TempDirscip-go gomod github.com/golang/go/src go1.25.0 testing/common#TempDir().() |
| 166 | initmap := make(map[*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#]InitDatascip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/InitData#) |
| 167 | imp := GetImporterscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/GetImporter().([]string{tmpdir}, initmap) |
| 168 | |
| 169 | artmpdir := t.TempDirscip-go gomod github.com/golang/go/src go1.25.0 testing/common#TempDir().() |
| 170 | arinitmap := make(map[*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#]InitDatascip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/InitData#) |
| 171 | arimp := GetImporterscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/GetImporter().([]string{artmpdir}, arinitmap) |
| 172 | |
| 173 | for _, test := range importerTestsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTests. { |
| 174 | if major < test.gccgoVersionscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#gccgoVersion. { |
| 175 | // Support for type aliases was added in GCC 7. |
| 176 | t.Logfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Logf().("skipping %q: not supported before gccgo version %d", test.pkgpathscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#pkgpath., test.gccgoVersionscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#gccgoVersion.) |
| 177 | continue |
| 178 | } |
| 179 | |
| 180 | gofile := filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Join().("testdata", test.pkgpathscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#pkgpath.+".go") |
| 181 | if _, err := osscip-go gomod github.com/golang/go/src go1.25.0 os/.Statscip-go gomod github.com/golang/go/src go1.25.0 os/Stat().(gofile); osscip-go gomod github.com/golang/go/src go1.25.0 os/.IsNotExistscip-go gomod github.com/golang/go/src go1.25.0 os/IsNotExist().(err) { |
| 182 | continue |
| 183 | } |
| 184 | ofile := filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Join().(tmpdir, test.pkgpathscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#pkgpath.+".o") |
| 185 | afile := filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Join().(artmpdir, "lib"+test.pkgpathscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#pkgpath.+".a") |
| 186 | |
| 187 | cmd := execscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/.Commandscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/Command().(gpath, "-fgo-pkgpath="+test.pkgpathscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/importerTest#pkgpath., "-c", "-o", ofile, gofile) |
| 188 | if out, err := cmd.CombinedOutputscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/Cmd#CombinedOutput().(); err != nil { |
| 189 | t.Logfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Logf().("%s", out) |
| 190 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("gccgo %s failed: %s", gofile, err) |
| 191 | } |
| 192 | |
| 193 | runImporterTestscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/runImporterTest().(t, imp, initmap, &test) |
| 194 | |
| 195 | cmd = execscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/.Commandscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/Command().("ar", "cr", afile, ofile) |
| 196 | if out, err := cmd.CombinedOutputscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/Cmd#CombinedOutput().(); err != nil { |
| 197 | t.Logfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Logf().("%s", out) |
| 198 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("ar cr %s %s failed: %s", afile, ofile, err) |
| 199 | } |
| 200 | |
| 201 | runImporterTestscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/runImporterTest().(t, arimp, arinitmap, &test) |
| 202 | |
| 203 | if err = osscip-go gomod github.com/golang/go/src go1.25.0 os/.Removescip-go gomod github.com/golang/go/src go1.25.0 os/Remove().(ofile); err != nil { |
| 204 | t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().(err) |
| 205 | } |
| 206 | if err = osscip-go gomod github.com/golang/go/src go1.25.0 os/.Removescip-go gomod github.com/golang/go/src go1.25.0 os/Remove().(afile); err != nil { |
| 207 | t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().(err) |
| 208 | } |
| 209 | } |
| 210 | } |