Skip to content

Commit 45a28e1

Browse files
committed
all: fix x/tools tests that fail with a go1.23.1 go.work file
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 <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent b0f44d5 commit 45a28e1

File tree

8 files changed

+32
-5
lines changed

8 files changed

+32
-5
lines changed

Diff for: cmd/godoc/godoc_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,11 @@ func TestWebIndex(t *testing.T) {
197197

198198
// Basic integration test for godoc HTTP interface.
199199
func testWeb(t *testing.T, x packagestest.Exporter, bin string, withIndex bool) {
200+
testenv.NeedsGOROOTDir(t, "api")
201+
200202
switch runtime.GOOS {
201203
case "plan9":
202204
t.Skip("skipping on plan9: fails to start up quickly enough")
203-
case "android", "ios":
204-
t.Skip("skipping on mobile: lacks GOROOT/api in test environment")
205205
}
206206

207207
// Write a fake GOROOT/GOPATH with some third party packages.

Diff for: go/ssa/builder_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,8 @@ var indirect = R[int].M
666666
// TestTypeparamTest builds SSA over compilable examples in $GOROOT/test/typeparam/*.go.
667667

668668
func TestTypeparamTest(t *testing.T) {
669+
testenv.NeedsGOROOTDir(t, "test")
670+
669671
// Tests use a fake goroot to stub out standard libraries with declarations in
670672
// testdata/src. Decreases runtime from ~80s to ~1s.
671673

Diff for: go/ssa/interp/interp_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,8 @@ func TestTestdataFiles(t *testing.T) {
340340

341341
// TestGorootTest runs the interpreter on $GOROOT/test/*.go.
342342
func TestGorootTest(t *testing.T) {
343+
testenv.NeedsGOROOTDir(t, "test")
344+
343345
goroot := makeGoroot(t)
344346
for _, input := range gorootTestTests {
345347
t.Run(input, func(t *testing.T) {
@@ -352,6 +354,8 @@ func TestGorootTest(t *testing.T) {
352354
// in $GOROOT/test/typeparam/*.go.
353355

354356
func TestTypeparamTest(t *testing.T) {
357+
testenv.NeedsGOROOTDir(t, "test")
358+
355359
if runtime.GOARCH == "wasm" {
356360
// See ssa/TestTypeparamTest.
357361
t.Skip("Consistent flakes on wasm (e.g. https://go.dev/issues/64726)")

Diff for: godoc/versions_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ package godoc
77
import (
88
"go/build"
99
"testing"
10+
11+
"golang.org/x/tools/internal/testenv"
1012
)
1113

1214
func TestParseVersionRow(t *testing.T) {
@@ -88,6 +90,8 @@ func hasTag(t string) bool {
8890
}
8991

9092
func TestAPIVersion(t *testing.T) {
93+
testenv.NeedsGOROOTDir(t, "api")
94+
9195
av, err := parsePackageAPIInfo()
9296
if err != nil {
9397
t.Fatal(err)

Diff for: internal/aliases/aliases_test.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ func TestNewAlias(t *testing.T) {
4444
}
4545

4646
for _, godebug := range []string{
47-
// The default gotypesalias value follows the x/tools/go.mod version
48-
// The go.mod is at 1.22 so the default is gotypesalias=0.
49-
"", // Use the default GODEBUG value (off).
47+
// Note: previously there was a test case for "", which asserted on the
48+
// behavior implied by the x/tools go.mod go directive. But that only works
49+
// if x/tools is the main module for the test, which isn't the case when
50+
// run with a go.work file, or from another module (golang/go#70082).
5051
"gotypesalias=0",
5152
"gotypesalias=1",
5253
} {

Diff for: internal/gcimporter/gcimporter_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ func TestImportTypeparamTests(t *testing.T) {
166166
}
167167

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

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

Diff for: internal/gcimporter/iexport_go118_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ func testExportSrc(t *testing.T, src []byte) {
9898

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

102103
testAliases(t, testIndexedImportTypeparamTests)
103104
}

Diff for: internal/testenv/testenv.go

+14
Original file line numberDiff line numberDiff line change
@@ -490,3 +490,17 @@ func NeedsGoExperiment(t testing.TB, flag string) {
490490
t.Skipf("skipping test: flag %q is not set in GOEXPERIMENT=%q", flag, goexp)
491491
}
492492
}
493+
494+
// NeedsGOROOTDir skips the test if GOROOT/dir does not exist, and GOROOT is a
495+
// released version of Go (=has a VERSION file). Some GOROOT directories are
496+
// removed by cmd/distpack.
497+
//
498+
// See also golang/go#70081.
499+
func NeedsGOROOTDir(t *testing.T, dir string) {
500+
gorootTest := filepath.Join(GOROOT(t), dir)
501+
if _, err := os.Stat(gorootTest); os.IsNotExist(err) {
502+
if _, err := os.Stat(filepath.Join(GOROOT(t), "VERSION")); err == nil {
503+
t.Skipf("skipping: GOROOT/%s not present", dir)
504+
}
505+
}
506+
}

0 commit comments

Comments
 (0)