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:
Robert Griesemer 2015-04-08 11:11:27 -07:00
parent bf8b6a5c4c
commit 069d2f3bcb
8 changed files with 76 additions and 21 deletions

View File

@ -30,7 +30,7 @@ func init() {
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
// path based on package information provided by build.Import (using

View File

@ -18,23 +18,27 @@ import (
"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
func init() {
// determine compiler
var gc string
switch runtime.GOARCH {
case "386":
gc = "8g"
case "amd64":
gc = "6g"
case "arm":
gc = "5g"
default:
gcPath = "unknown-GOARCH-compiler"
if char, err := build.ArchChar(runtime.GOARCH); err == nil {
gcPath = filepath.Join(build.ToolDir, char+"g")
return
}
gcPath = filepath.Join(build.ToolDir, gc)
gcPath = "unknown-GOARCH-compiler"
}
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) {
// This package does not handle gccgo export data.
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
}
@ -133,10 +138,14 @@ var importedObjectTests = []struct {
}
func TestImportedTypes(t *testing.T) {
// This package does not handle gccgo export data.
if runtime.Compiler == "gccgo" {
skipSpecialPlatforms(t)
// This package only handles gc export data.
if runtime.Compiler != "gc" {
t.Skipf("gc-built packages not available (compiler = %s)", runtime.Compiler)
return
}
for _, test := range importedObjectTests {
s := strings.Split(test.name, ".")
if len(s) != 2 {
@ -165,8 +174,11 @@ func TestImportedTypes(t *testing.T) {
}
func TestIssue5815(t *testing.T) {
// This package does not handle gccgo export data.
if runtime.Compiler == "gccgo" {
skipSpecialPlatforms(t)
// This package only handles gc export data.
if runtime.Compiler != "gc" {
t.Skipf("gc-built packages not available (compiler = %s)", runtime.Compiler)
return
}
@ -195,8 +207,11 @@ func TestIssue5815(t *testing.T) {
// Smoke test to ensure that imported methods get the correct package.
func TestCorrectMethodPackage(t *testing.T) {
// This package does not handle gccgo export data.
if runtime.Compiler == "gccgo" {
skipSpecialPlatforms(t)
// This package only handles gc export data.
if runtime.Compiler != "gc" {
t.Skipf("gc-built packages not available (compiler = %s)", runtime.Compiler)
return
}

View File

@ -10,6 +10,7 @@ import (
"go/ast"
"go/parser"
"go/token"
"runtime"
"strings"
"testing"
@ -17,6 +18,19 @@ import (
. "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) {
fset := token.NewFileSet()
f, err := parser.ParseFile(fset, path, source, 0)
@ -284,6 +298,8 @@ func predString(tv TypeAndValue) string {
}
func TestPredicatesInfo(t *testing.T) {
skipSpecialPlatforms(t)
var tests = []struct {
src string
expr string
@ -368,6 +384,8 @@ func TestPredicatesInfo(t *testing.T) {
}
func TestScopesInfo(t *testing.T) {
skipSpecialPlatforms(t)
var tests = []struct {
src string
scopes []string // list of scope descriptors of the form kind:varlist

View File

@ -278,6 +278,8 @@ func checkFiles(t *testing.T, testfiles []string) {
}
func TestCheck(t *testing.T) {
skipSpecialPlatforms(t)
// Declare builtins for testing.
DefPredeclaredTestFuncs()

View File

@ -83,6 +83,8 @@ func TestEvalArith(t *testing.T) {
}
func TestEvalContext(t *testing.T) {
skipSpecialPlatforms(t)
src := `
package p
import "fmt"

View File

@ -89,6 +89,8 @@ var pkgnames = []string{
}
func TestResolveIdents(t *testing.T) {
skipSpecialPlatforms(t)
// parse package files
fset := token.NewFileSet()
var files []*ast.File

View File

@ -32,6 +32,8 @@ var (
)
func TestStdlib(t *testing.T) {
skipSpecialPlatforms(t)
walkDirs(t, filepath.Join(runtime.GOROOT(), "src"))
if testing.Verbose() {
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) {
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"),
"cmplxdivide.go", // also needs file cmplxdivide1.go - ignore
"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) {
skipSpecialPlatforms(t)
testTestDir(t, filepath.Join(runtime.GOROOT(), "test", "fixedbugs"),
"bug248.go", "bug302.go", "bug369.go", // complex test instructions - ignore
"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) {
skipSpecialPlatforms(t)
testTestDir(t, filepath.Join(runtime.GOROOT(), "test", "ken"))
}

View File

@ -116,6 +116,8 @@ var dependentTestTypes = []testEntry{
}
func TestTypeString(t *testing.T) {
skipSpecialPlatforms(t)
var tests []testEntry
tests = append(tests, independentTestTypes...)
tests = append(tests, dependentTestTypes...)