From c65208ee29128450a4a024e3b7710f3a8d14028d Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Thu, 7 Jun 2018 21:33:18 -0700 Subject: [PATCH] go/...: make most tests pass with gccgo There is one non-test change: have FakeContext change the compiler to "gc", as callers expect to be accessing a gc-style GOROOT. The go/pointer, go/ssa, and go/ssa/interp tests still fail with gccgo. Change-Id: I850c9618401f6b9e63d7ca7196f91931b03f1524 Reviewed-on: https://go-review.googlesource.com/117395 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- go/buildutil/allpackages_test.go | 5 +++++ go/buildutil/fakecontext.go | 1 + go/buildutil/util_test.go | 4 ++++ go/gcexportdata/example_test.go | 1 + go/internal/gccgoimporter/gccgoinstallation_test.go | 8 ++------ go/internal/gccgoimporter/importer_test.go | 11 +++++++++++ go/internal/gcimporter/bexport_test.go | 3 +++ go/loader/loader_test.go | 9 +++++++++ 8 files changed, 36 insertions(+), 6 deletions(-) diff --git a/go/buildutil/allpackages_test.go b/go/buildutil/allpackages_test.go index 0440ff2402..1815512b92 100644 --- a/go/buildutil/allpackages_test.go +++ b/go/buildutil/allpackages_test.go @@ -10,6 +10,7 @@ package buildutil_test import ( "go/build" + "runtime" "sort" "strings" "testing" @@ -18,6 +19,10 @@ import ( ) func TestAllPackages(t *testing.T) { + if runtime.Compiler == "gccgo" { + t.Skip("gccgo has no standard packages") + } + all := buildutil.AllPackages(&build.Default) set := make(map[string]bool) diff --git a/go/buildutil/fakecontext.go b/go/buildutil/fakecontext.go index 24cbcbea2b..8b7f066739 100644 --- a/go/buildutil/fakecontext.go +++ b/go/buildutil/fakecontext.go @@ -41,6 +41,7 @@ func FakeContext(pkgs map[string]map[string]string) *build.Context { ctxt := build.Default // copy ctxt.GOROOT = "/go" ctxt.GOPATH = "" + ctxt.Compiler = "gc" ctxt.IsDir = func(dir string) bool { dir = clean(dir) if dir == "" { diff --git a/go/buildutil/util_test.go b/go/buildutil/util_test.go index f7c26dd3c8..c72d59d50a 100644 --- a/go/buildutil/util_test.go +++ b/go/buildutil/util_test.go @@ -15,6 +15,10 @@ import ( ) func TestContainingPackage(t *testing.T) { + if runtime.Compiler == "gccgo" { + t.Skip("gccgo has no GOROOT") + } + // unvirtualized: goroot := runtime.GOROOT() gopath := gopathContainingTools(t) diff --git a/go/gcexportdata/example_test.go b/go/gcexportdata/example_test.go index 4ad73abcb4..b67d55f963 100644 --- a/go/gcexportdata/example_test.go +++ b/go/gcexportdata/example_test.go @@ -3,6 +3,7 @@ // license that can be found in the LICENSE file. // +build go1.7 +// +build gc package gcexportdata_test diff --git a/go/internal/gccgoimporter/gccgoinstallation_test.go b/go/internal/gccgoimporter/gccgoinstallation_test.go index fb1fa6d4b1..ca8c2419fb 100644 --- a/go/internal/gccgoimporter/gccgoinstallation_test.go +++ b/go/internal/gccgoimporter/gccgoinstallation_test.go @@ -64,8 +64,6 @@ var importablePackages = [...]string{ "encoding/pem", "encoding/xml", "errors", - "exp/proxy", - "exp/terminal", "expvar", "flag", "fmt", @@ -116,8 +114,6 @@ var importablePackages = [...]string{ "net/smtp", "net/textproto", "net/url", - "old/regexp", - "old/template", "os/exec", "os", "os/signal", @@ -183,12 +179,12 @@ func TestInstallationImporter(t *testing.T) { // Test for certain specific entities in the imported data. for _, test := range [...]importerTest{ - {pkgpath: "io", name: "Reader", want: "type Reader interface{Read(p []uint8) (n int, err error)}"}, + {pkgpath: "io", name: "Reader", want: "type Reader interface{Read(p []byte) (n int, err error)}"}, {pkgpath: "io", name: "ReadWriter", want: "type ReadWriter interface{Reader; Writer}"}, {pkgpath: "math", name: "Pi", want: "const Pi untyped float"}, {pkgpath: "math", name: "Sin", want: "func Sin(x float64) float64"}, {pkgpath: "sort", name: "Ints", want: "func Ints(a []int)"}, - {pkgpath: "unsafe", name: "Pointer", want: "type Pointer unsafe.Pointer"}, + {pkgpath: "unsafe", name: "Pointer", want: "type Pointer"}, } { runImporterTest(t, imp, nil, &test) } diff --git a/go/internal/gccgoimporter/importer_test.go b/go/internal/gccgoimporter/importer_test.go index 2c6f1cb4f7..02c100a6b8 100644 --- a/go/internal/gccgoimporter/importer_test.go +++ b/go/internal/gccgoimporter/importer_test.go @@ -144,6 +144,13 @@ func TestObjImporter(t *testing.T) { for _, test := range importerTests { gofile := filepath.Join("testdata", test.pkgpath+".go") + + if _, err := os.Stat(gofile); err != nil { + // There is a .gox file but no .go file, + // so there is nothing to compile. + continue + } + ofile := filepath.Join(tmpdir, test.pkgpath+".o") afile := filepath.Join(artmpdir, "lib"+test.pkgpath+".a") @@ -154,6 +161,10 @@ func TestObjImporter(t *testing.T) { t.Fatalf("gccgo %s failed: %s", gofile, err) } + // The expected initializations are version dependent, + // so don't check for them. + test.wantinits = nil + runImporterTest(t, imp, initmap, &test) cmd = exec.Command("ar", "cr", afile, ofile) diff --git a/go/internal/gcimporter/bexport_test.go b/go/internal/gcimporter/bexport_test.go index dac9ca29ca..e78b78db06 100644 --- a/go/internal/gcimporter/bexport_test.go +++ b/go/internal/gcimporter/bexport_test.go @@ -23,6 +23,9 @@ import ( ) func TestBExportData_stdlib(t *testing.T) { + if runtime.Compiler == "gccgo" { + t.Skip("gccgo standard library is inaccessible") + } if runtime.GOOS == "android" { t.Skipf("incomplete std lib on %s", runtime.GOOS) } diff --git a/go/loader/loader_test.go b/go/loader/loader_test.go index 02630eb298..dab9b22546 100644 --- a/go/loader/loader_test.go +++ b/go/loader/loader_test.go @@ -15,6 +15,7 @@ import ( "go/types" "path/filepath" "reflect" + "runtime" "sort" "strings" "sync" @@ -127,6 +128,10 @@ func TestLoad_MissingInitialPackage(t *testing.T) { } func TestLoad_MissingInitialPackage_AllowErrors(t *testing.T) { + if runtime.Compiler == "gccgo" { + t.Skip("gccgo has no standard library test files") + } + var conf loader.Config conf.AllowErrors = true conf.Import("nosuchpkg") @@ -251,6 +256,10 @@ func TestLoad_FromSource_Success(t *testing.T) { } func TestLoad_FromImports_Success(t *testing.T) { + if runtime.Compiler == "gccgo" { + t.Skip("gccgo has no standard library test files") + } + var conf loader.Config conf.ImportWithTests("fmt") conf.ImportWithTests("errors")