@@ -19,8 +19,6 @@ import (
19
19
"sync"
20
20
"testing"
21
21
"time"
22
-
23
- "golang.org/x/mod/modfile"
24
22
)
25
23
26
24
// packageMainIsDevel reports whether the module containing package main
@@ -204,47 +202,6 @@ func NeedsTool(t testing.TB, tool string) {
204
202
}
205
203
}
206
204
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
-
248
205
// NeedsGoBuild skips t if the current system can't build programs with “go build”
249
206
// and then run them with os.StartProcess or exec.Command.
250
207
// Android doesn't have the userspace go build needs to run,
@@ -258,43 +215,6 @@ func NeedsGoBuild(t testing.TB) {
258
215
NeedsTool (t , "go" )
259
216
}
260
217
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
-
298
218
// Go1Point returns the x in Go 1.x.
299
219
func Go1Point () int {
300
220
for i := len (build .Default .ReleaseTags ) - 1 ; i >= 0 ; i -- {
@@ -325,15 +245,6 @@ func SkipAfterGo1Point(t testing.TB, x int) {
325
245
}
326
246
}
327
247
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
-
337
248
// Deadline returns the deadline of t, if known,
338
249
// using the Deadline method added in Go 1.15.
339
250
func Deadline (t testing.TB ) (time.Time , bool ) {
@@ -346,89 +257,6 @@ func Deadline(t testing.TB) (time.Time, bool) {
346
257
return td .Deadline ()
347
258
}
348
259
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
-
432
260
// NeedsGoExperiment skips t if the current process environment does not
433
261
// have a GOEXPERIMENT flag set.
434
262
func NeedsGoExperiment (t testing.TB , flag string ) {
0 commit comments