Skip to content

Commit

Permalink
go/internal/gcimporter,cmd/compile/internal/importer: use testenv.Mus…
Browse files Browse the repository at this point in the history
…tHaveGoBuild directly

These tests previously had a “skipSpecialPlatforms” function, added in
CL 8611 to skip tests on (apparently) NaCL and iOS. The iOS builders
no longer match the condition (GOOS=ios is its own thing now), and the
NaCL port no longer exists.

The name of the function also isn't very evocative, since it doesn't
say what is “special” about the platforms to cause them to be
skipped.m

Since the check is intending to run the tests only on platforms where
gc export data is available, and to a first approximation
“gc export data is available” on exactly the platforms that can run
“go build” to produce that export data, we can use the testenv function
instead of a one-off.

Updates #38485.

Change-Id: I8f38b9604300d165147f8942e945ab762419fad7
Reviewed-on: https://go-review.googlesource.com/c/go/+/444155
Auto-Submit: Bryan Mills <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Reviewed-by: David Chase <[email protected]>
Run-TryBot: Bryan Mills <[email protected]>
  • Loading branch information
Bryan C. Mills authored and gopherbot committed Oct 19, 2022
1 parent 6b22572 commit 4a164a4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 55 deletions.
40 changes: 13 additions & 27 deletions src/cmd/compile/internal/importer/gcimporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,6 @@ func TestMain(m *testing.M) {
os.Exit(m.Run())
}

// 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) {
t.Helper()
testenv.MustHaveGoBuild(t)

// TODO(bcmills): Is this still accurate now that ios is its own GOOS?
switch platform := runtime.GOOS + "-" + runtime.GOARCH; platform {
case "darwin-arm64":
t.Skipf("no compiled packages available for import on %s", platform)
}
}

// compile runs the compiler on filename, with dirname as the working directory,
// and writes the output file to outdirname.
// compile gives the resulting package a packagepath of testdata/<filebasename>.
Expand Down Expand Up @@ -124,7 +110,7 @@ func TestImportTestdata(t *testing.T) {
t.Skipf("gc-built packages not available (compiler = %s)", runtime.Compiler)
}

skipSpecialPlatforms(t)
testenv.MustHaveGoBuild(t)

testfiles := map[string][]string{
"exports.go": {"go/ast", "go/token"},
Expand Down Expand Up @@ -159,7 +145,7 @@ func TestImportTestdata(t *testing.T) {
}

func TestVersionHandling(t *testing.T) {
skipSpecialPlatforms(t)
testenv.MustHaveGoBuild(t)

// This package only handles gc export data.
if runtime.Compiler != "gc" {
Expand Down Expand Up @@ -250,7 +236,7 @@ func TestVersionHandling(t *testing.T) {
}

func TestImportStdLib(t *testing.T) {
skipSpecialPlatforms(t)
testenv.MustHaveGoBuild(t)

// This package only handles gc export data.
if runtime.Compiler != "gc" {
Expand Down Expand Up @@ -290,7 +276,7 @@ var importedObjectTests = []struct {
}

func TestImportedTypes(t *testing.T) {
skipSpecialPlatforms(t)
testenv.MustHaveGoBuild(t)

// This package only handles gc export data.
if runtime.Compiler != "gc" {
Expand Down Expand Up @@ -373,7 +359,7 @@ func verifyInterfaceMethodRecvs(t *testing.T, named *types2.Named, level int) {
}

func TestIssue5815(t *testing.T) {
skipSpecialPlatforms(t)
testenv.MustHaveGoBuild(t)

// This package only handles gc export data.
if runtime.Compiler != "gc" {
Expand Down Expand Up @@ -402,7 +388,7 @@ func TestIssue5815(t *testing.T) {

// Smoke test to ensure that imported methods get the correct package.
func TestCorrectMethodPackage(t *testing.T) {
skipSpecialPlatforms(t)
testenv.MustHaveGoBuild(t)

// This package only handles gc export data.
if runtime.Compiler != "gc" {
Expand All @@ -424,7 +410,7 @@ func TestCorrectMethodPackage(t *testing.T) {
}

func TestIssue13566(t *testing.T) {
skipSpecialPlatforms(t)
testenv.MustHaveGoBuild(t)

// This package only handles gc export data.
if runtime.Compiler != "gc" {
Expand Down Expand Up @@ -463,7 +449,7 @@ func TestIssue13566(t *testing.T) {
}

func TestIssue13898(t *testing.T) {
skipSpecialPlatforms(t)
testenv.MustHaveGoBuild(t)

// This package only handles gc export data.
if runtime.Compiler != "gc" {
Expand Down Expand Up @@ -509,7 +495,7 @@ func TestIssue13898(t *testing.T) {
}

func TestIssue15517(t *testing.T) {
skipSpecialPlatforms(t)
testenv.MustHaveGoBuild(t)

// This package only handles gc export data.
if runtime.Compiler != "gc" {
Expand Down Expand Up @@ -548,7 +534,7 @@ func TestIssue15517(t *testing.T) {
}

func TestIssue15920(t *testing.T) {
skipSpecialPlatforms(t)
testenv.MustHaveGoBuild(t)

// This package only handles gc export data.
if runtime.Compiler != "gc" {
Expand All @@ -565,7 +551,7 @@ func TestIssue15920(t *testing.T) {
}

func TestIssue20046(t *testing.T) {
skipSpecialPlatforms(t)
testenv.MustHaveGoBuild(t)

// This package only handles gc export data.
if runtime.Compiler != "gc" {
Expand All @@ -586,7 +572,7 @@ func TestIssue20046(t *testing.T) {
}
}
func TestIssue25301(t *testing.T) {
skipSpecialPlatforms(t)
testenv.MustHaveGoBuild(t)

// This package only handles gc export data.
if runtime.Compiler != "gc" {
Expand All @@ -603,7 +589,7 @@ func TestIssue25301(t *testing.T) {
}

func TestIssue25596(t *testing.T) {
skipSpecialPlatforms(t)
testenv.MustHaveGoBuild(t)

// This package only handles gc export data.
if runtime.Compiler != "gc" {
Expand Down
43 changes: 15 additions & 28 deletions src/go/internal/gcimporter/gcimporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,6 @@ func TestMain(m *testing.M) {
os.Exit(m.Run())
}

// 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) {
t.Helper()
testenv.MustHaveGoBuild(t)

switch platform := runtime.GOOS + "-" + runtime.GOARCH; platform {
case "darwin-arm64":
t.Skipf("no compiled packages available for import on %s", platform)
}
}

// compile runs the compiler on filename, with dirname as the working directory,
// and writes the output file to outdirname.
// compile gives the resulting package a packagepath of testdata/<filebasename>.
Expand Down Expand Up @@ -133,7 +120,7 @@ func TestImportTestdata(t *testing.T) {
t.Skipf("gc-built packages not available (compiler = %s)", runtime.Compiler)
}

skipSpecialPlatforms(t)
testenv.MustHaveGoBuild(t)

testfiles := map[string][]string{
"exports.go": {"go/ast", "go/token"},
Expand Down Expand Up @@ -173,7 +160,7 @@ func TestImportTypeparamTests(t *testing.T) {
t.Skipf("gc-built packages not available (compiler = %s)", runtime.Compiler)
}

skipSpecialPlatforms(t)
testenv.MustHaveGoBuild(t)

tmpdir := mktmpdir(t)
defer os.RemoveAll(tmpdir)
Expand Down Expand Up @@ -291,7 +278,7 @@ func checkFile(t *testing.T, filename string, src []byte) *types.Package {
}

func TestVersionHandling(t *testing.T) {
skipSpecialPlatforms(t)
testenv.MustHaveGoBuild(t)

// This package only handles gc export data.
if runtime.Compiler != "gc" {
Expand Down Expand Up @@ -384,7 +371,7 @@ func TestVersionHandling(t *testing.T) {
}

func TestImportStdLib(t *testing.T) {
skipSpecialPlatforms(t)
testenv.MustHaveGoBuild(t)

// This package only handles gc export data.
if runtime.Compiler != "gc" {
Expand Down Expand Up @@ -424,7 +411,7 @@ var importedObjectTests = []struct {
}

func TestImportedTypes(t *testing.T) {
skipSpecialPlatforms(t)
testenv.MustHaveGoBuild(t)

// This package only handles gc export data.
if runtime.Compiler != "gc" {
Expand Down Expand Up @@ -500,7 +487,7 @@ func verifyInterfaceMethodRecvs(t *testing.T, named *types.Named, level int) {
}

func TestIssue5815(t *testing.T) {
skipSpecialPlatforms(t)
testenv.MustHaveGoBuild(t)

// This package only handles gc export data.
if runtime.Compiler != "gc" {
Expand Down Expand Up @@ -529,7 +516,7 @@ func TestIssue5815(t *testing.T) {

// Smoke test to ensure that imported methods get the correct package.
func TestCorrectMethodPackage(t *testing.T) {
skipSpecialPlatforms(t)
testenv.MustHaveGoBuild(t)

// This package only handles gc export data.
if runtime.Compiler != "gc" {
Expand All @@ -553,7 +540,7 @@ func TestCorrectMethodPackage(t *testing.T) {
}

func TestIssue13566(t *testing.T) {
skipSpecialPlatforms(t)
testenv.MustHaveGoBuild(t)

// This package only handles gc export data.
if runtime.Compiler != "gc" {
Expand Down Expand Up @@ -592,7 +579,7 @@ func TestIssue13566(t *testing.T) {
}

func TestTypeNamingOrder(t *testing.T) {
skipSpecialPlatforms(t)
testenv.MustHaveGoBuild(t)

// This package only handles gc export data.
if runtime.Compiler != "gc" {
Expand All @@ -616,7 +603,7 @@ func TestTypeNamingOrder(t *testing.T) {
}

func TestIssue13898(t *testing.T) {
skipSpecialPlatforms(t)
testenv.MustHaveGoBuild(t)

// This package only handles gc export data.
if runtime.Compiler != "gc" {
Expand Down Expand Up @@ -663,7 +650,7 @@ func TestIssue13898(t *testing.T) {
}

func TestIssue15517(t *testing.T) {
skipSpecialPlatforms(t)
testenv.MustHaveGoBuild(t)

// This package only handles gc export data.
if runtime.Compiler != "gc" {
Expand Down Expand Up @@ -703,7 +690,7 @@ func TestIssue15517(t *testing.T) {
}

func TestIssue15920(t *testing.T) {
skipSpecialPlatforms(t)
testenv.MustHaveGoBuild(t)

// This package only handles gc export data.
if runtime.Compiler != "gc" {
Expand All @@ -720,7 +707,7 @@ func TestIssue15920(t *testing.T) {
}

func TestIssue20046(t *testing.T) {
skipSpecialPlatforms(t)
testenv.MustHaveGoBuild(t)

// This package only handles gc export data.
if runtime.Compiler != "gc" {
Expand All @@ -741,7 +728,7 @@ func TestIssue20046(t *testing.T) {
}
}
func TestIssue25301(t *testing.T) {
skipSpecialPlatforms(t)
testenv.MustHaveGoBuild(t)

// This package only handles gc export data.
if runtime.Compiler != "gc" {
Expand All @@ -758,7 +745,7 @@ func TestIssue25301(t *testing.T) {
}

func TestIssue25596(t *testing.T) {
skipSpecialPlatforms(t)
testenv.MustHaveGoBuild(t)

// This package only handles gc export data.
if runtime.Compiler != "gc" {
Expand Down

0 comments on commit 4a164a4

Please sign in to comment.