go/types, go/gcimporter: backport changes from std repo
This is a 1:1 backport of the following changes: https://go-review.googlesource.com/8611 https://go-review.googlesource.com/8621 Change-Id: I4a75d73cb99a7d104d32553f5530408c2b6d81b8 Reviewed-on: https://go-review.googlesource.com/8629 Reviewed-by: Alan Donovan <adonovan@google.com>
This commit is contained in:
parent
bf8b6a5c4c
commit
069d2f3bcb
|
@ -30,7 +30,7 @@ func init() {
|
||||||
types.DefaultImport = Import
|
types.DefaultImport = Import
|
||||||
}
|
}
|
||||||
|
|
||||||
var pkgExts = [...]string{".a", ".5", ".6", ".8"}
|
var pkgExts = [...]string{".a", ".5", ".6", ".7", ".8", ".9"}
|
||||||
|
|
||||||
// FindPkg returns the filename and unique package id for an import
|
// FindPkg returns the filename and unique package id for an import
|
||||||
// path based on package information provided by build.Import (using
|
// path based on package information provided by build.Import (using
|
||||||
|
|
|
@ -18,23 +18,27 @@ import (
|
||||||
"golang.org/x/tools/go/types"
|
"golang.org/x/tools/go/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// skipSpecialPlatforms causes the test to be skipped for platforms where
|
||||||
|
// builders (build.golang.org) don't have access to compiled packages for
|
||||||
|
// import.
|
||||||
|
func skipSpecialPlatforms(t *testing.T) {
|
||||||
|
switch platform := runtime.GOOS + "-" + runtime.GOARCH; platform {
|
||||||
|
case "nacl-amd64p32",
|
||||||
|
"nacl-386",
|
||||||
|
"darwin-arm",
|
||||||
|
"darwin-arm64":
|
||||||
|
t.Skipf("no compiled packages available for import on %s", platform)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var gcPath string // Go compiler path
|
var gcPath string // Go compiler path
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
// determine compiler
|
if char, err := build.ArchChar(runtime.GOARCH); err == nil {
|
||||||
var gc string
|
gcPath = filepath.Join(build.ToolDir, char+"g")
|
||||||
switch runtime.GOARCH {
|
|
||||||
case "386":
|
|
||||||
gc = "8g"
|
|
||||||
case "amd64":
|
|
||||||
gc = "6g"
|
|
||||||
case "arm":
|
|
||||||
gc = "5g"
|
|
||||||
default:
|
|
||||||
gcPath = "unknown-GOARCH-compiler"
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
gcPath = filepath.Join(build.ToolDir, gc)
|
gcPath = "unknown-GOARCH-compiler"
|
||||||
}
|
}
|
||||||
|
|
||||||
func compile(t *testing.T, dirname, filename string) string {
|
func compile(t *testing.T, dirname, filename string) string {
|
||||||
|
@ -97,8 +101,9 @@ func testDir(t *testing.T, dir string, endTime time.Time) (nimports int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestImport(t *testing.T) {
|
func TestImport(t *testing.T) {
|
||||||
// This package does not handle gccgo export data.
|
// This package only handles gc export data.
|
||||||
if runtime.Compiler == "gccgo" {
|
if runtime.Compiler != "gc" {
|
||||||
|
t.Skipf("gc-built packages not available (compiler = %s)", runtime.Compiler)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,10 +138,14 @@ var importedObjectTests = []struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestImportedTypes(t *testing.T) {
|
func TestImportedTypes(t *testing.T) {
|
||||||
// This package does not handle gccgo export data.
|
skipSpecialPlatforms(t)
|
||||||
if runtime.Compiler == "gccgo" {
|
|
||||||
|
// This package only handles gc export data.
|
||||||
|
if runtime.Compiler != "gc" {
|
||||||
|
t.Skipf("gc-built packages not available (compiler = %s)", runtime.Compiler)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range importedObjectTests {
|
for _, test := range importedObjectTests {
|
||||||
s := strings.Split(test.name, ".")
|
s := strings.Split(test.name, ".")
|
||||||
if len(s) != 2 {
|
if len(s) != 2 {
|
||||||
|
@ -165,8 +174,11 @@ func TestImportedTypes(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIssue5815(t *testing.T) {
|
func TestIssue5815(t *testing.T) {
|
||||||
// This package does not handle gccgo export data.
|
skipSpecialPlatforms(t)
|
||||||
if runtime.Compiler == "gccgo" {
|
|
||||||
|
// This package only handles gc export data.
|
||||||
|
if runtime.Compiler != "gc" {
|
||||||
|
t.Skipf("gc-built packages not available (compiler = %s)", runtime.Compiler)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,8 +207,11 @@ func TestIssue5815(t *testing.T) {
|
||||||
|
|
||||||
// Smoke test to ensure that imported methods get the correct package.
|
// Smoke test to ensure that imported methods get the correct package.
|
||||||
func TestCorrectMethodPackage(t *testing.T) {
|
func TestCorrectMethodPackage(t *testing.T) {
|
||||||
// This package does not handle gccgo export data.
|
skipSpecialPlatforms(t)
|
||||||
if runtime.Compiler == "gccgo" {
|
|
||||||
|
// This package only handles gc export data.
|
||||||
|
if runtime.Compiler != "gc" {
|
||||||
|
t.Skipf("gc-built packages not available (compiler = %s)", runtime.Compiler)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"go/ast"
|
"go/ast"
|
||||||
"go/parser"
|
"go/parser"
|
||||||
"go/token"
|
"go/token"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -17,6 +18,19 @@ import (
|
||||||
. "golang.org/x/tools/go/types"
|
. "golang.org/x/tools/go/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// skipSpecialPlatforms causes the test to be skipped for platforms where
|
||||||
|
// builders (build.golang.org) don't have access to compiled packages for
|
||||||
|
// import.
|
||||||
|
func skipSpecialPlatforms(t *testing.T) {
|
||||||
|
switch platform := runtime.GOOS + "-" + runtime.GOARCH; platform {
|
||||||
|
case "nacl-amd64p32",
|
||||||
|
"nacl-386",
|
||||||
|
"darwin-arm",
|
||||||
|
"darwin-arm64":
|
||||||
|
t.Skipf("no compiled packages available for import on %s", platform)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func pkgFor(path, source string, info *Info) (*Package, error) {
|
func pkgFor(path, source string, info *Info) (*Package, error) {
|
||||||
fset := token.NewFileSet()
|
fset := token.NewFileSet()
|
||||||
f, err := parser.ParseFile(fset, path, source, 0)
|
f, err := parser.ParseFile(fset, path, source, 0)
|
||||||
|
@ -284,6 +298,8 @@ func predString(tv TypeAndValue) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPredicatesInfo(t *testing.T) {
|
func TestPredicatesInfo(t *testing.T) {
|
||||||
|
skipSpecialPlatforms(t)
|
||||||
|
|
||||||
var tests = []struct {
|
var tests = []struct {
|
||||||
src string
|
src string
|
||||||
expr string
|
expr string
|
||||||
|
@ -368,6 +384,8 @@ func TestPredicatesInfo(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestScopesInfo(t *testing.T) {
|
func TestScopesInfo(t *testing.T) {
|
||||||
|
skipSpecialPlatforms(t)
|
||||||
|
|
||||||
var tests = []struct {
|
var tests = []struct {
|
||||||
src string
|
src string
|
||||||
scopes []string // list of scope descriptors of the form kind:varlist
|
scopes []string // list of scope descriptors of the form kind:varlist
|
||||||
|
|
|
@ -278,6 +278,8 @@ func checkFiles(t *testing.T, testfiles []string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCheck(t *testing.T) {
|
func TestCheck(t *testing.T) {
|
||||||
|
skipSpecialPlatforms(t)
|
||||||
|
|
||||||
// Declare builtins for testing.
|
// Declare builtins for testing.
|
||||||
DefPredeclaredTestFuncs()
|
DefPredeclaredTestFuncs()
|
||||||
|
|
||||||
|
|
|
@ -83,6 +83,8 @@ func TestEvalArith(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEvalContext(t *testing.T) {
|
func TestEvalContext(t *testing.T) {
|
||||||
|
skipSpecialPlatforms(t)
|
||||||
|
|
||||||
src := `
|
src := `
|
||||||
package p
|
package p
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
|
@ -89,6 +89,8 @@ var pkgnames = []string{
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestResolveIdents(t *testing.T) {
|
func TestResolveIdents(t *testing.T) {
|
||||||
|
skipSpecialPlatforms(t)
|
||||||
|
|
||||||
// parse package files
|
// parse package files
|
||||||
fset := token.NewFileSet()
|
fset := token.NewFileSet()
|
||||||
var files []*ast.File
|
var files []*ast.File
|
||||||
|
|
|
@ -32,6 +32,8 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestStdlib(t *testing.T) {
|
func TestStdlib(t *testing.T) {
|
||||||
|
skipSpecialPlatforms(t)
|
||||||
|
|
||||||
walkDirs(t, filepath.Join(runtime.GOROOT(), "src"))
|
walkDirs(t, filepath.Join(runtime.GOROOT(), "src"))
|
||||||
if testing.Verbose() {
|
if testing.Verbose() {
|
||||||
fmt.Println(pkgCount, "packages typechecked in", time.Since(start))
|
fmt.Println(pkgCount, "packages typechecked in", time.Since(start))
|
||||||
|
@ -116,6 +118,14 @@ func testTestDir(t *testing.T, path string, ignore ...string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStdTest(t *testing.T) {
|
func TestStdTest(t *testing.T) {
|
||||||
|
skipSpecialPlatforms(t)
|
||||||
|
|
||||||
|
// test/recover4.go is only built for Linux and Darwin.
|
||||||
|
// TODO(gri) Remove once tests consider +build tags (issue 10370).
|
||||||
|
if runtime.GOOS != "linux" || runtime.GOOS != "darwin" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
testTestDir(t, filepath.Join(runtime.GOROOT(), "test"),
|
testTestDir(t, filepath.Join(runtime.GOROOT(), "test"),
|
||||||
"cmplxdivide.go", // also needs file cmplxdivide1.go - ignore
|
"cmplxdivide.go", // also needs file cmplxdivide1.go - ignore
|
||||||
"sigchld.go", // don't work on Windows; testTestDir should consult build tags
|
"sigchld.go", // don't work on Windows; testTestDir should consult build tags
|
||||||
|
@ -123,6 +133,8 @@ func TestStdTest(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStdFixed(t *testing.T) {
|
func TestStdFixed(t *testing.T) {
|
||||||
|
skipSpecialPlatforms(t)
|
||||||
|
|
||||||
testTestDir(t, filepath.Join(runtime.GOROOT(), "test", "fixedbugs"),
|
testTestDir(t, filepath.Join(runtime.GOROOT(), "test", "fixedbugs"),
|
||||||
"bug248.go", "bug302.go", "bug369.go", // complex test instructions - ignore
|
"bug248.go", "bug302.go", "bug369.go", // complex test instructions - ignore
|
||||||
"bug459.go", // possibly incorrect test - see issue 6703 (pending spec clarification)
|
"bug459.go", // possibly incorrect test - see issue 6703 (pending spec clarification)
|
||||||
|
@ -132,6 +144,8 @@ func TestStdFixed(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStdKen(t *testing.T) {
|
func TestStdKen(t *testing.T) {
|
||||||
|
skipSpecialPlatforms(t)
|
||||||
|
|
||||||
testTestDir(t, filepath.Join(runtime.GOROOT(), "test", "ken"))
|
testTestDir(t, filepath.Join(runtime.GOROOT(), "test", "ken"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -116,6 +116,8 @@ var dependentTestTypes = []testEntry{
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTypeString(t *testing.T) {
|
func TestTypeString(t *testing.T) {
|
||||||
|
skipSpecialPlatforms(t)
|
||||||
|
|
||||||
var tests []testEntry
|
var tests []testEntry
|
||||||
tests = append(tests, independentTestTypes...)
|
tests = append(tests, independentTestTypes...)
|
||||||
tests = append(tests, dependentTestTypes...)
|
tests = append(tests, dependentTestTypes...)
|
||||||
|
|
Loading…
Reference in New Issue