github.com/llvm-mirror/llgo@v0.0.0-20190322182713-bf6f0a60fce1/third_party/gofrontend/libgo/go/internal/testenv/testenv.go (about) 1 // Copyright 2015 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 // Package testenv provides information about what functionality 6 // is available in different testing environments run by the Go team. 7 // 8 // It is an internal package because these details are specific 9 // to the Go team's test setup (on build.golang.org) and not 10 // fundamental to tests in general. 11 package testenv 12 13 import ( 14 "os" 15 "runtime" 16 "strings" 17 "testing" 18 ) 19 20 // Builder reports the name of the builder running this test 21 // (for example, "linux-amd64" or "windows-386-gce"). 22 // If the test is not running on the build infrastructure, 23 // Builder returns the empty string. 24 func Builder() string { 25 return os.Getenv("GO_BUILDER_NAME") 26 } 27 28 // HasGoBuild reports whether the current system can build programs with ``go build'' 29 // and then run them with os.StartProcess or exec.Command. 30 func HasGoBuild() bool { 31 switch runtime.GOOS { 32 case "android", "nacl": 33 return false 34 case "darwin": 35 if strings.HasPrefix(runtime.GOARCH, "arm") { 36 return false 37 } 38 } 39 // gccgo tests can not run "go build". 40 return false 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 t.Skip("skipping test: 'go build' not available for gccgo tests") 48 if !HasGoBuild() { 49 t.Skipf("skipping test: 'go build' not available on %s/%s", runtime.GOOS, runtime.GOARCH) 50 } 51 } 52 53 // HasGoRun reports whether the current system can run programs with ``go run.'' 54 func HasGoRun() bool { 55 // For now, having go run and having go build are the same. 56 return HasGoBuild() 57 } 58 59 // MustHaveGoRun checks that the current system can run programs with ``go run.'' 60 // If not, MustHaveGoRun calls t.Skip with an explanation. 61 func MustHaveGoRun(t *testing.T) { 62 t.Skip("skipping test: 'go run' not available for gccgo tests") 63 if !HasGoRun() { 64 t.Skipf("skipping test: 'go run' not available on %s/%s", runtime.GOOS, runtime.GOARCH) 65 } 66 } 67 68 // HasExec reports whether the current system can start new processes 69 // using os.StartProcess or (more commonly) exec.Command. 70 func HasExec() bool { 71 switch runtime.GOOS { 72 case "nacl": 73 return false 74 case "darwin": 75 if strings.HasPrefix(runtime.GOARCH, "arm") { 76 return false 77 } 78 } 79 return true 80 } 81 82 // MustHaveExec checks that the current system can start new processes 83 // using os.StartProcess or (more commonly) exec.Command. 84 // If not, MustHaveExec calls t.Skip with an explanation. 85 func MustHaveExec(t *testing.T) { 86 if !HasExec() { 87 t.Skipf("skipping test: cannot exec subprocess on %s/%s", runtime.GOOS, runtime.GOARCH) 88 } 89 } 90 91 // HasExternalNetwork reports whether the current system can use 92 // external (non-localhost) networks. 93 func HasExternalNetwork() bool { 94 return !testing.Short() 95 } 96 97 // MustHaveExternalNetwork checks that the current system can use 98 // external (non-localhost) networks. 99 // If not, MustHaveExternalNetwork calls t.Skip with an explanation. 100 func MustHaveExternalNetwork(t *testing.T) { 101 if testing.Short() { 102 t.Skipf("skipping test: no external network in -short mode") 103 } 104 }