github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/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 "github.com/shogo82148/std/testing" 15 ) 16 17 // Builder reports the name of the builder running this test 18 // (for example, "linux-amd64" or "windows-386-gce"). 19 // If the test is not running on the build infrastructure, 20 // Builder returns the empty string. 21 func Builder() string 22 23 // HasGoBuild reports whether the current system can build programs with “go build” 24 // and then run them with os.StartProcess or exec.Command. 25 func HasGoBuild() bool 26 27 // MustHaveGoBuild checks that the current system can build programs with “go build” 28 // and then run them with os.StartProcess or exec.Command. 29 // If not, MustHaveGoBuild calls t.Skip with an explanation. 30 func MustHaveGoBuild(t testing.TB) 31 32 // HasGoRun reports whether the current system can run programs with “go run”. 33 func HasGoRun() bool 34 35 // MustHaveGoRun checks that the current system can run programs with “go run”. 36 // If not, MustHaveGoRun calls t.Skip with an explanation. 37 func MustHaveGoRun(t testing.TB) 38 39 // HasParallelism reports whether the current system can execute multiple 40 // threads in parallel. 41 // There is a copy of this function in cmd/dist/test.go. 42 func HasParallelism() bool 43 44 // MustHaveParallelism checks that the current system can execute multiple 45 // threads in parallel. If not, MustHaveParallelism calls t.Skip with an explanation. 46 func MustHaveParallelism(t testing.TB) 47 48 // GoToolPath reports the path to the Go tool. 49 // It is a convenience wrapper around GoTool. 50 // If the tool is unavailable GoToolPath calls t.Skip. 51 // If the tool should be available and isn't, GoToolPath calls t.Fatal. 52 func GoToolPath(t testing.TB) string 53 54 // GOROOT reports the path to the directory containing the root of the Go 55 // project source tree. This is normally equivalent to runtime.GOROOT, but 56 // works even if the test binary was built with -trimpath and cannot exec 57 // 'go env GOROOT'. 58 // 59 // If GOROOT cannot be found, GOROOT skips t if t is non-nil, 60 // or panics otherwise. 61 func GOROOT(t testing.TB) string 62 63 // GoTool reports the path to the Go tool. 64 func GoTool() (string, error) 65 66 // HasSrc reports whether the entire source tree is available under GOROOT. 67 func HasSrc() bool 68 69 // HasExternalNetwork reports whether the current system can use 70 // external (non-localhost) networks. 71 func HasExternalNetwork() bool 72 73 // MustHaveExternalNetwork checks that the current system can use 74 // external (non-localhost) networks. 75 // If not, MustHaveExternalNetwork calls t.Skip with an explanation. 76 func MustHaveExternalNetwork(t testing.TB) 77 78 // HasCGO reports whether the current system can use cgo. 79 func HasCGO() bool 80 81 // MustHaveCGO calls t.Skip if cgo is not available. 82 func MustHaveCGO(t testing.TB) 83 84 // CanInternalLink reports whether the current system can link programs with 85 // internal linking. 86 func CanInternalLink(withCgo bool) bool 87 88 // MustInternalLink checks that the current system can link programs with internal 89 // linking. 90 // If not, MustInternalLink calls t.Skip with an explanation. 91 func MustInternalLink(t testing.TB, withCgo bool) 92 93 // MustInternalLinkPIE checks whether the current system can link PIE binary using 94 // internal linking. 95 // If not, MustInternalLinkPIE calls t.Skip with an explanation. 96 func MustInternalLinkPIE(t testing.TB) 97 98 // MustHaveBuildMode reports whether the current system can build programs in 99 // the given build mode. 100 // If not, MustHaveBuildMode calls t.Skip with an explanation. 101 func MustHaveBuildMode(t testing.TB, buildmode string) 102 103 // HasSymlink reports whether the current system can use os.Symlink. 104 func HasSymlink() bool 105 106 // MustHaveSymlink reports whether the current system can use os.Symlink. 107 // If not, MustHaveSymlink calls t.Skip with an explanation. 108 func MustHaveSymlink(t testing.TB) 109 110 // HasLink reports whether the current system can use os.Link. 111 func HasLink() bool 112 113 // MustHaveLink reports whether the current system can use os.Link. 114 // If not, MustHaveLink calls t.Skip with an explanation. 115 func MustHaveLink(t testing.TB) 116 117 func SkipFlaky(t testing.TB, issue int) 118 119 func SkipFlakyNet(t testing.TB) 120 121 // CPUIsSlow reports whether the CPU running the test is suspected to be slow. 122 func CPUIsSlow() bool 123 124 // SkipIfShortAndSlow skips t if -short is set and the CPU running the test is 125 // suspected to be slow. 126 // 127 // (This is useful for CPU-intensive tests that otherwise complete quickly.) 128 func SkipIfShortAndSlow(t testing.TB) 129 130 // SkipIfOptimizationOff skips t if optimization is disabled. 131 func SkipIfOptimizationOff(t testing.TB) 132 133 // WriteImportcfg writes an importcfg file used by the compiler or linker to 134 // dstPath containing entries for the file mappings in packageFiles, as well 135 // as for the packages transitively imported by the package(s) in pkgs. 136 // 137 // pkgs may include any package pattern that is valid to pass to 'go list', 138 // so it may also be a list of Go source files all in the same directory. 139 func WriteImportcfg(t testing.TB, dstPath string, packageFiles map[string]string, pkgs ...string) 140 141 // SyscallIsNotSupported reports whether err may indicate that a system call is 142 // not supported by the current platform or execution environment. 143 func SyscallIsNotSupported(err error) bool