Skip to content

Commit 0e10ed9

Browse files
committed
internal/golangorgx: drop testenv APIs we won't need
These helpers are closely tied to testing x/tools itself or hard-code details about the Go project's CI machines. None of those are relevant to the CUE repository. Note that we leave the helpers which check if `go build` can be run and check GOEXPERIMENT as those might still be useful to us. Signed-off-by: Daniel Martí <[email protected]> Change-Id: I48178f8155641eff9a84f68b39235c16c19f334e Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1214192 Unity-Result: CUE porcuepine <[email protected]> Reviewed-by: Matthew Sackman <[email protected]> TryBot-Result: CUEcueckoo <[email protected]>
1 parent d3ae2ca commit 0e10ed9

File tree

3 files changed

+0
-202
lines changed

3 files changed

+0
-202
lines changed

internal/golangorgx/gopls/test/integration/regtest.go

-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ func Main(m *testing.M, hook func(*settings.Options)) {
122122
fmt.Printf("skipping all tests: exec not supported on %s/%s\n", runtime.GOOS, runtime.GOARCH)
123123
os.Exit(0)
124124
}
125-
testenv.ExitIfSmallMachine()
126125

127126
// Disable GOPACKAGESDRIVER, as it can cause spurious test failures.
128127
os.Setenv("GOPACKAGESDRIVER", "off")

internal/golangorgx/gopls/test/integration/runner.go

-29
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,6 @@ func (r *Runner) Run(t *testing.T, files string, test TestFunc, opts ...RunOptio
137137
// TODO(rfindley): this function has gotten overly complicated, and warrants
138138
// refactoring.
139139
t.Helper()
140-
checkBuilder(t)
141-
testenv.NeedsGoPackages(t)
142140

143141
tests := []struct {
144142
name string
@@ -265,33 +263,6 @@ func (r *Runner) Run(t *testing.T, files string, test TestFunc, opts ...RunOptio
265263
}
266264
}
267265

268-
// longBuilders maps builders that are skipped when -short is set to a
269-
// (possibly empty) justification.
270-
var longBuilders = map[string]string{
271-
"openbsd-amd64-64": "golang.org/issues/42789",
272-
"openbsd-386-64": "golang.org/issues/42789",
273-
"openbsd-386-68": "golang.org/issues/42789",
274-
"openbsd-amd64-68": "golang.org/issues/42789",
275-
"darwin-amd64-10_12": "",
276-
"freebsd-amd64-race": "",
277-
"illumos-amd64": "",
278-
"netbsd-arm-bsiegert": "",
279-
"solaris-amd64-oraclerel": "",
280-
"windows-arm-zx2c4": "",
281-
}
282-
283-
func checkBuilder(t *testing.T) {
284-
t.Helper()
285-
builder := os.Getenv("GO_BUILDER_NAME")
286-
if reason, ok := longBuilders[builder]; ok && testing.Short() {
287-
if reason != "" {
288-
t.Skipf("Skipping %s with -short due to %s", builder, reason)
289-
} else {
290-
t.Skipf("Skipping %s with -short", builder)
291-
}
292-
}
293-
}
294-
295266
type loggingFramer struct {
296267
mu sync.Mutex
297268
buf *safeBuffer

internal/golangorgx/tools/testenv/testenv.go

-172
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ import (
1919
"sync"
2020
"testing"
2121
"time"
22-
23-
"golang.org/x/mod/modfile"
2422
)
2523

2624
// packageMainIsDevel reports whether the module containing package main
@@ -204,47 +202,6 @@ func NeedsTool(t testing.TB, tool string) {
204202
}
205203
}
206204

207-
// NeedsGoPackages skips t if the go/packages driver (or 'go' tool) implied by
208-
// the current process environment is not present in the path.
209-
func NeedsGoPackages(t testing.TB) {
210-
t.Helper()
211-
212-
tool := os.Getenv("GOPACKAGESDRIVER")
213-
switch tool {
214-
case "off":
215-
// "off" forces go/packages to use the go command.
216-
tool = "go"
217-
case "":
218-
if _, err := exec.LookPath("gopackagesdriver"); err == nil {
219-
tool = "gopackagesdriver"
220-
} else {
221-
tool = "go"
222-
}
223-
}
224-
225-
NeedsTool(t, tool)
226-
}
227-
228-
// NeedsGoPackagesEnv skips t if the go/packages driver (or 'go' tool) implied
229-
// by env is not present in the path.
230-
func NeedsGoPackagesEnv(t testing.TB, env []string) {
231-
t.Helper()
232-
233-
for _, v := range env {
234-
if strings.HasPrefix(v, "GOPACKAGESDRIVER=") {
235-
tool := strings.TrimPrefix(v, "GOPACKAGESDRIVER=")
236-
if tool == "off" {
237-
NeedsTool(t, "go")
238-
} else {
239-
NeedsTool(t, tool)
240-
}
241-
return
242-
}
243-
}
244-
245-
NeedsGoPackages(t)
246-
}
247-
248205
// NeedsGoBuild skips t if the current system can't build programs with “go build”
249206
// and then run them with os.StartProcess or exec.Command.
250207
// Android doesn't have the userspace go build needs to run,
@@ -258,43 +215,6 @@ func NeedsGoBuild(t testing.TB) {
258215
NeedsTool(t, "go")
259216
}
260217

261-
// ExitIfSmallMachine emits a helpful diagnostic and calls os.Exit(0) if the
262-
// current machine is a builder known to have scarce resources.
263-
//
264-
// It should be called from within a TestMain function.
265-
func ExitIfSmallMachine() {
266-
switch b := os.Getenv("GO_BUILDER_NAME"); b {
267-
case "linux-arm-scaleway":
268-
// "linux-arm" was renamed to "linux-arm-scaleway" in CL 303230.
269-
fmt.Fprintln(os.Stderr, "skipping test: linux-arm-scaleway builder lacks sufficient memory (https://golang.org/issue/32834)")
270-
case "plan9-arm":
271-
fmt.Fprintln(os.Stderr, "skipping test: plan9-arm builder lacks sufficient memory (https://golang.org/issue/38772)")
272-
case "netbsd-arm-bsiegert", "netbsd-arm64-bsiegert":
273-
// As of 2021-06-02, these builders are running with GO_TEST_TIMEOUT_SCALE=10,
274-
// and there is only one of each. We shouldn't waste those scarce resources
275-
// running very slow tests.
276-
fmt.Fprintf(os.Stderr, "skipping test: %s builder is very slow\n", b)
277-
case "dragonfly-amd64":
278-
// As of 2021-11-02, this builder is running with GO_TEST_TIMEOUT_SCALE=2,
279-
// and seems to have unusually slow disk performance.
280-
fmt.Fprintln(os.Stderr, "skipping test: dragonfly-amd64 has slow disk (https://golang.org/issue/45216)")
281-
case "linux-riscv64-unmatched":
282-
// As of 2021-11-03, this builder is empirically not fast enough to run
283-
// gopls tests. Ideally we should make the tests faster in short mode
284-
// and/or fix them to not assume arbitrary deadlines.
285-
// For now, we'll skip them instead.
286-
fmt.Fprintf(os.Stderr, "skipping test: %s builder is too slow (https://golang.org/issue/49321)\n", b)
287-
default:
288-
switch runtime.GOOS {
289-
case "android", "ios":
290-
fmt.Fprintf(os.Stderr, "skipping test: assuming that %s is resource-constrained\n", runtime.GOOS)
291-
default:
292-
return
293-
}
294-
}
295-
os.Exit(0)
296-
}
297-
298218
// Go1Point returns the x in Go 1.x.
299219
func Go1Point() int {
300220
for i := len(build.Default.ReleaseTags) - 1; i >= 0; i-- {
@@ -325,15 +245,6 @@ func SkipAfterGo1Point(t testing.TB, x int) {
325245
}
326246
}
327247

328-
// NeedsLocalhostNet skips t if networking does not work for ports opened
329-
// with "localhost".
330-
func NeedsLocalhostNet(t testing.TB) {
331-
switch runtime.GOOS {
332-
case "js", "wasip1":
333-
t.Skipf(`Listening on "localhost" fails on %s; see https://go.dev/issue/59718`, runtime.GOOS)
334-
}
335-
}
336-
337248
// Deadline returns the deadline of t, if known,
338249
// using the Deadline method added in Go 1.15.
339250
func Deadline(t testing.TB) (time.Time, bool) {
@@ -346,89 +257,6 @@ func Deadline(t testing.TB) (time.Time, bool) {
346257
return td.Deadline()
347258
}
348259

349-
var (
350-
gorootOnce sync.Once
351-
gorootPath string
352-
gorootErr error
353-
)
354-
355-
func findGOROOT() (string, error) {
356-
gorootOnce.Do(func() {
357-
gorootPath = runtime.GOROOT()
358-
if gorootPath != "" {
359-
// If runtime.GOROOT() is non-empty, assume that it is valid. (It might
360-
// not be: for example, the user may have explicitly set GOROOT
361-
// to the wrong directory.)
362-
return
363-
}
364-
365-
cmd := exec.Command("go", "env", "GOROOT")
366-
out, err := cmd.Output()
367-
if err != nil {
368-
gorootErr = fmt.Errorf("%v: %v", cmd, err)
369-
}
370-
gorootPath = strings.TrimSpace(string(out))
371-
})
372-
373-
return gorootPath, gorootErr
374-
}
375-
376-
// GOROOT reports the path to the directory containing the root of the Go
377-
// project source tree. This is normally equivalent to runtime.GOROOT, but
378-
// works even if the test binary was built with -trimpath.
379-
//
380-
// If GOROOT cannot be found, GOROOT skips t if t is non-nil,
381-
// or panics otherwise.
382-
func GOROOT(t testing.TB) string {
383-
path, err := findGOROOT()
384-
if err != nil {
385-
if t == nil {
386-
panic(err)
387-
}
388-
t.Helper()
389-
t.Skip(err)
390-
}
391-
return path
392-
}
393-
394-
// NeedsLocalXTools skips t if the golang.org/x/tools module is replaced and
395-
// its replacement directory does not exist (or does not contain the module).
396-
func NeedsLocalXTools(t testing.TB) {
397-
t.Helper()
398-
399-
NeedsTool(t, "go")
400-
401-
cmd := Command(t, "go", "list", "-f", "{{with .Replace}}{{.Dir}}{{end}}", "-m", "golang.org/x/tools")
402-
out, err := cmd.Output()
403-
if err != nil {
404-
if ee, ok := err.(*exec.ExitError); ok && len(ee.Stderr) > 0 {
405-
t.Skipf("skipping test: %v: %v\n%s", cmd, err, ee.Stderr)
406-
}
407-
t.Skipf("skipping test: %v: %v", cmd, err)
408-
}
409-
410-
dir := string(bytes.TrimSpace(out))
411-
if dir == "" {
412-
// No replacement directory, and (since we didn't set -e) no error either.
413-
// Maybe x/tools isn't replaced at all (as in a gopls release, or when
414-
// using a go.work file that includes the x/tools module).
415-
return
416-
}
417-
418-
// We found the directory where x/tools would exist if we're in a clone of the
419-
// repo. Is it there? (If not, we're probably in the module cache instead.)
420-
modFilePath := filepath.Join(dir, "go.mod")
421-
b, err := os.ReadFile(modFilePath)
422-
if err != nil {
423-
t.Skipf("skipping test: x/tools replacement not found: %v", err)
424-
}
425-
modulePath := modfile.ModulePath(b)
426-
427-
if want := "golang.org/x/tools"; modulePath != want {
428-
t.Skipf("skipping test: %s module path is %q, not %q", modFilePath, modulePath, want)
429-
}
430-
}
431-
432260
// NeedsGoExperiment skips t if the current process environment does not
433261
// have a GOEXPERIMENT flag set.
434262
func NeedsGoExperiment(t testing.TB, flag string) {

0 commit comments

Comments
 (0)