Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / golang.org / x / tools@v0.0.0-20201028153306-37f0764111ff / go / internal / gccgoimporter / testenv_test.go
1 // Copyright 2018 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 // This file contains testing utilities copied from $GOROOT/src/internal/testenv/testenv.go.
6
7 package gccgoimporter
8
9 import (
10         "runtime"
11         "strings"
12         "testing"
13 )
14
15 // HasGoBuild reports whether the current system can build programs with ``go build''
16 // and then run them with os.StartProcess or exec.Command.
17 func HasGoBuild() bool {
18         switch runtime.GOOS {
19         case "android", "nacl":
20                 return false
21         case "darwin":
22                 if strings.HasPrefix(runtime.GOARCH, "arm") {
23                         return false
24                 }
25         }
26         return true
27 }
28
29 // HasExec reports whether the current system can start new processes
30 // using os.StartProcess or (more commonly) exec.Command.
31 func HasExec() bool {
32         switch runtime.GOOS {
33         case "nacl", "js":
34                 return false
35         case "darwin":
36                 if strings.HasPrefix(runtime.GOARCH, "arm") {
37                         return false
38                 }
39         }
40         return true
41 }
42
43 // MustHaveGoBuild checks that the current system can build programs with ``go build''
44 // and then run them with os.StartProcess or exec.Command.
45 // If not, MustHaveGoBuild calls t.Skip with an explanation.
46 func MustHaveGoBuild(t *testing.T) {
47         if !HasGoBuild() {
48                 t.Skipf("skipping test: 'go build' not available on %s/%s", runtime.GOOS, runtime.GOARCH)
49         }
50 }
51
52 // MustHaveExec checks that the current system can start new processes
53 // using os.StartProcess or (more commonly) exec.Command.
54 // If not, MustHaveExec calls t.Skip with an explanation.
55 func MustHaveExec(t *testing.T) {
56         if !HasExec() {
57                 t.Skipf("skipping test: cannot exec subprocess on %s/%s", runtime.GOOS, runtime.GOARCH)
58         }
59 }
60
61 var testenv = struct {
62         HasGoBuild      func() bool
63         MustHaveGoBuild func(*testing.T)
64         MustHaveExec    func(*testing.T)
65 }{
66         HasGoBuild:      HasGoBuild,
67         MustHaveGoBuild: MustHaveGoBuild,
68         MustHaveExec:    MustHaveExec,
69 }