Skip to content

Commit

Permalink
all: fix x/tools tests that fail with a go1.23.1 go.work file
Browse files Browse the repository at this point in the history
Delete or selectively skip tests that made either of the following
assumptions:
- The default GODEBUG is that of Go 1.22 (not true given a go.work
  file).
- GOROOT is a development version of Go (not true if GOROOT is prepared
  by cmd/distpack).

Fixes golang/go#70081
Fixes golang/go#70082

Change-Id: I47dfb225427f75e3be833eed3ba677ff454935f1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/622896
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
  • Loading branch information
findleyr committed Oct 28, 2024
1 parent b0f44d5 commit 45a28e1
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 5 deletions.
4 changes: 2 additions & 2 deletions cmd/godoc/godoc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,11 @@ func TestWebIndex(t *testing.T) {

// Basic integration test for godoc HTTP interface.
func testWeb(t *testing.T, x packagestest.Exporter, bin string, withIndex bool) {
testenv.NeedsGOROOTDir(t, "api")

switch runtime.GOOS {
case "plan9":
t.Skip("skipping on plan9: fails to start up quickly enough")
case "android", "ios":
t.Skip("skipping on mobile: lacks GOROOT/api in test environment")
}

// Write a fake GOROOT/GOPATH with some third party packages.
Expand Down
2 changes: 2 additions & 0 deletions go/ssa/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,8 @@ var indirect = R[int].M
// TestTypeparamTest builds SSA over compilable examples in $GOROOT/test/typeparam/*.go.

func TestTypeparamTest(t *testing.T) {
testenv.NeedsGOROOTDir(t, "test")

// Tests use a fake goroot to stub out standard libraries with declarations in
// testdata/src. Decreases runtime from ~80s to ~1s.

Expand Down
4 changes: 4 additions & 0 deletions go/ssa/interp/interp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@ func TestTestdataFiles(t *testing.T) {

// TestGorootTest runs the interpreter on $GOROOT/test/*.go.
func TestGorootTest(t *testing.T) {
testenv.NeedsGOROOTDir(t, "test")

goroot := makeGoroot(t)
for _, input := range gorootTestTests {
t.Run(input, func(t *testing.T) {
Expand All @@ -352,6 +354,8 @@ func TestGorootTest(t *testing.T) {
// in $GOROOT/test/typeparam/*.go.

func TestTypeparamTest(t *testing.T) {
testenv.NeedsGOROOTDir(t, "test")

if runtime.GOARCH == "wasm" {
// See ssa/TestTypeparamTest.
t.Skip("Consistent flakes on wasm (e.g. https://go.dev/issues/64726)")
Expand Down
4 changes: 4 additions & 0 deletions godoc/versions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ package godoc
import (
"go/build"
"testing"

"golang.org/x/tools/internal/testenv"
)

func TestParseVersionRow(t *testing.T) {
Expand Down Expand Up @@ -88,6 +90,8 @@ func hasTag(t string) bool {
}

func TestAPIVersion(t *testing.T) {
testenv.NeedsGOROOTDir(t, "api")

av, err := parsePackageAPIInfo()
if err != nil {
t.Fatal(err)
Expand Down
7 changes: 4 additions & 3 deletions internal/aliases/aliases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ func TestNewAlias(t *testing.T) {
}

for _, godebug := range []string{
// The default gotypesalias value follows the x/tools/go.mod version
// The go.mod is at 1.22 so the default is gotypesalias=0.
"", // Use the default GODEBUG value (off).
// Note: previously there was a test case for "", which asserted on the
// behavior implied by the x/tools go.mod go directive. But that only works
// if x/tools is the main module for the test, which isn't the case when
// run with a go.work file, or from another module (golang/go#70082).
"gotypesalias=0",
"gotypesalias=1",
} {
Expand Down
1 change: 1 addition & 0 deletions internal/gcimporter/gcimporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ func TestImportTypeparamTests(t *testing.T) {
}

testenv.NeedsGoBuild(t) // to find stdlib export data in the build cache
testenv.NeedsGOROOTDir(t, "test")

// This package only handles gc export data.
if runtime.Compiler != "gc" {
Expand Down
1 change: 1 addition & 0 deletions internal/gcimporter/iexport_go118_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func testExportSrc(t *testing.T, src []byte) {

func TestIndexedImportTypeparamTests(t *testing.T) {
testenv.NeedsGoBuild(t) // to find stdlib export data in the build cache
testenv.NeedsGOROOTDir(t, "test")

testAliases(t, testIndexedImportTypeparamTests)
}
Expand Down
14 changes: 14 additions & 0 deletions internal/testenv/testenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,3 +490,17 @@ func NeedsGoExperiment(t testing.TB, flag string) {
t.Skipf("skipping test: flag %q is not set in GOEXPERIMENT=%q", flag, goexp)
}
}

// NeedsGOROOTDir skips the test if GOROOT/dir does not exist, and GOROOT is a
// released version of Go (=has a VERSION file). Some GOROOT directories are
// removed by cmd/distpack.
//
// See also golang/go#70081.
func NeedsGOROOTDir(t *testing.T, dir string) {
gorootTest := filepath.Join(GOROOT(t), dir)
if _, err := os.Stat(gorootTest); os.IsNotExist(err) {
if _, err := os.Stat(filepath.Join(GOROOT(t), "VERSION")); err == nil {
t.Skipf("skipping: GOROOT/%s not present", dir)
}
}
}

0 comments on commit 45a28e1

Please sign in to comment.