Skip to content

Commit 8ecf757

Browse files
adonovangopherbot
authored andcommitted
internal/gcimporter: remove test of unsupported "goroot" iimport
This CL eliminates the "goroot" flavor of TestIExportDataTypeParameterizedAliases, leaving just the "tools" flavor, and simplifies accordingly. The logic of the goroot version assumed that importer.Default() could read what gcexportdata.Write would write... except that that comments correctly stated the assumption was false. Updates golang/go#68898 Change-Id: Ifded4ed2cc2103de32ac869731176a49877d10e0 Reviewed-on: https://go-review.googlesource.com/c/tools/+/620036 Auto-Submit: Alan Donovan <adonovan@google.com> Reviewed-by: Robert Findley <rfindley@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
1 parent 7310c72 commit 8ecf757

File tree

1 file changed

+30
-70
lines changed

1 file changed

+30
-70
lines changed

internal/gcimporter/iexport_test.go

+30-70
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@ import (
1111
"fmt"
1212
"go/ast"
1313
"go/constant"
14-
"go/importer"
1514
"go/parser"
1615
"go/token"
1716
"go/types"
1817
"math/big"
19-
"os"
2018
"path/filepath"
2119
"reflect"
2220
"strings"
@@ -461,76 +459,38 @@ type Chained = C[Named] // B[Named, A[Named]] = B[Named, *Named] = []*Named
461459
t.Fatal(err)
462460
}
463461

464-
testcases := map[string]func(t *testing.T) *types.Package{
465-
// Read the result of IExportData through x/tools/internal/gcimporter.IImportData.
466-
"tools": func(t *testing.T) *types.Package {
467-
// export
468-
exportdata, err := iexport(fset1, gcimporter.IExportVersion, pkg1)
469-
if err != nil {
470-
t.Fatal(err)
471-
}
462+
// Read the result of IExportData through x/tools/internal/gcimporter.IImportData.
463+
// export
464+
exportdata, err := iexport(fset1, gcimporter.IExportVersion, pkg1)
465+
if err != nil {
466+
t.Fatal(err)
467+
}
472468

473-
// import
474-
imports := make(map[string]*types.Package)
475-
fset2 := token.NewFileSet()
476-
_, pkg2, err := gcimporter.IImportData(fset2, imports, exportdata, pkg1.Path())
477-
if err != nil {
478-
t.Fatalf("IImportData(%s): %v", pkg1.Path(), err)
479-
}
480-
return pkg2
481-
},
482-
// Read the result of IExportData through $GOROOT/src/internal/gcimporter.IImportData.
483-
//
484-
// This test fakes creating an old go object file in indexed format.
485-
// This means that it can be loaded by go/importer or go/types.
486-
// This step is not supported, but it does give test coverage for stdlib.
487-
"goroot": func(t *testing.T) *types.Package {
488-
testenv.NeedsGo1Point(t, 24) // requires >= 1.24 go/importer.
489-
490-
// Write indexed export data file contents.
491-
//
492-
// TODO(taking): Slightly unclear to what extent this step should be supported by go/importer.
493-
var buf bytes.Buffer
494-
buf.WriteString("go object \n$$B\n") // object file header
495-
if err := gcexportdata.Write(&buf, fset1, pkg1); err != nil {
496-
t.Fatal(err)
497-
}
469+
// import
470+
imports := make(map[string]*types.Package)
471+
fset2 := token.NewFileSet()
472+
_, pkg2, err := gcimporter.IImportData(fset2, imports, exportdata, pkg1.Path())
473+
if err != nil {
474+
t.Fatalf("IImportData(%s): %v", pkg1.Path(), err)
475+
}
498476

499-
// Write export data to temporary file
500-
out := t.TempDir()
501-
name := filepath.Join(out, "pkg.out")
502-
if err := os.WriteFile(name+".a", buf.Bytes(), 0644); err != nil {
503-
t.Fatal(err)
504-
}
505-
pkg2, err := importer.Default().Import(name)
506-
if err != nil {
507-
t.Fatal(err)
508-
}
509-
return pkg2
510-
},
511-
}
512-
513-
for name, importer := range testcases {
514-
t.Run(name, func(t *testing.T) {
515-
pkg := importer(t)
516-
for name, want := range map[string]string{
517-
"A": "type pkg.A[T any] = *T",
518-
"B": "type pkg.B[R any, S *R] = []S",
519-
"C": "type pkg.C[U any] = pkg.B[U, pkg.A[U]]",
520-
"Named": "type pkg.Named int",
521-
"Chained": "type pkg.Chained = pkg.C[pkg.Named]",
522-
} {
523-
obj := pkg.Scope().Lookup(name)
524-
if obj == nil {
525-
t.Errorf("failed to find %q in package %s", name, pkg)
526-
continue
527-
}
477+
pkg := pkg2
478+
for name, want := range map[string]string{
479+
"A": "type pkg.A[T any] = *T",
480+
"B": "type pkg.B[R any, S *R] = []S",
481+
"C": "type pkg.C[U any] = pkg.B[U, pkg.A[U]]",
482+
"Named": "type pkg.Named int",
483+
"Chained": "type pkg.Chained = pkg.C[pkg.Named]",
484+
} {
485+
obj := pkg.Scope().Lookup(name)
486+
if obj == nil {
487+
t.Errorf("failed to find %q in package %s", name, pkg)
488+
continue
489+
}
528490

529-
got := strings.ReplaceAll(obj.String(), pkg.Path(), "pkg")
530-
if got != want {
531-
t.Errorf("(%q).String()=%q. wanted %q", name, got, want)
532-
}
533-
}
534-
})
491+
got := strings.ReplaceAll(obj.String(), pkg.Path(), "pkg")
492+
if got != want {
493+
t.Errorf("(%q).String()=%q. wanted %q", name, got, want)
494+
}
535495
}
536496
}

0 commit comments

Comments
 (0)