Documentation ¶
Overview ¶
Package testenv provides information about what functionality is available in different testing environments run by the Go team.
It is an internal package because these details are specific to the Go team's test setup (on build.golang.org) and not fundamental to tests in general.
Index ¶
- Variables
- func Builder() string
- func CPUIsSlow() bool
- func CanInternalLink(withCgo bool) bool
- func CleanCmdEnv(cmd *exec.Cmd) *exec.Cmd
- func Command(t testing.TB, name string, args ...string) *exec.Cmd
- func CommandContext(t testing.TB, ctx context.Context, name string, args ...string) *exec.Cmd
- func GOROOT(t testing.TB) string
- func GoTool() (string, error)
- func GoToolPath(t testing.TB) string
- func HasCGO() bool
- func HasExternalNetwork() bool
- func HasGoBuild() bool
- func HasGoRun() bool
- func HasLink() bool
- func HasParallelism() bool
- func HasSrc() bool
- func HasSymlink() bool
- func MustHaveBuildMode(t testing.TB, buildmode string)
- func MustHaveCGO(t testing.TB)
- func MustHaveExec(t testing.TB)
- func MustHaveExecPath(t testing.TB, path string)
- func MustHaveExternalNetwork(t testing.TB)
- func MustHaveGoBuild(t testing.TB)
- func MustHaveGoRun(t testing.TB)
- func MustHaveLink(t testing.TB)
- func MustHaveParallelism(t testing.TB)
- func MustHaveSymlink(t testing.TB)
- func MustInternalLink(t testing.TB, withCgo bool)
- func MustInternalLinkPIE(t testing.TB)
- func OptimizationOff() bool
- func ParallelOn64Bit(t *testing.T)
- func SkipFlaky(t testing.TB, issue int)
- func SkipFlakyNet(t testing.TB)
- func SkipIfOptimizationOff(t testing.TB)
- func SkipIfShortAndSlow(t testing.TB)
- func SyscallIsNotSupported(err error) bool
- func WriteImportcfg(t testing.TB, dstPath string, packageFiles map[string]string, pkgs ...string)
Constants ¶
This section is empty.
Variables ¶
var Sigquit = syscall.SIGQUIT
Sigquit is the signal to send to kill a hanging subprocess. Send SIGQUIT to get a stack trace.
Functions ¶
func Builder ¶
func Builder() string
Builder reports the name of the builder running this test (for example, "linux-amd64" or "windows-386-gce"). If the test is not running on the build infrastructure, Builder returns the empty string.
func CPUIsSlow ¶ added in v0.81.0
func CPUIsSlow() bool
CPUIsSlow reports whether the CPU running the test is suspected to be slow.
func CanInternalLink ¶ added in v0.81.0
CanInternalLink reports whether the current system can link programs with internal linking. Modified by Hugo (not needed)
func CleanCmdEnv ¶
CleanCmdEnv will fill cmd.Env with the environment, excluding certain variables that could modify the behavior of the Go tools such as GODEBUG and GOTRACEBACK.
If the caller wants to set cmd.Dir, set it before calling this function, so PWD will be set correctly in the environment.
func Command ¶ added in v0.111.0
Command is like exec.Command, but applies the same changes as testenv.CommandContext (with a default Context).
func CommandContext ¶ added in v0.111.0
CommandContext is like exec.CommandContext, but:
- skips t if the platform does not support os/exec,
- sends SIGQUIT (if supported by the platform) instead of SIGKILL in its Cancel function
- if the test has a deadline, adds a Context timeout and WaitDelay for an arbitrary grace period before the test's deadline expires,
- fails the test if the command does not complete before the test's deadline, and
- sets a Cleanup function that verifies that the test did not leak a subprocess.
func GOROOT ¶ added in v0.106.0
GOROOT reports the path to the directory containing the root of the Go project source tree. This is normally equivalent to runtime.GOROOT, but works even if the test binary was built with -trimpath and cannot exec 'go env GOROOT'.
If GOROOT cannot be found, GOROOT skips t if t is non-nil, or panics otherwise.
func GoToolPath ¶
GoToolPath reports the path to the Go tool. It is a convenience wrapper around GoTool. If the tool is unavailable GoToolPath calls t.Skip. If the tool should be available and isn't, GoToolPath calls t.Fatal.
func HasExternalNetwork ¶
func HasExternalNetwork() bool
HasExternalNetwork reports whether the current system can use external (non-localhost) networks.
func HasGoBuild ¶
func HasGoBuild() bool
HasGoBuild reports whether the current system can build programs with “go build” and then run them with os.StartProcess or exec.Command. Modified by Hugo (not needed)
func HasGoRun ¶
func HasGoRun() bool
HasGoRun reports whether the current system can run programs with “go run”.
func HasParallelism ¶ added in v0.118.0
func HasParallelism() bool
HasParallelism reports whether the current system can execute multiple threads in parallel. There is a copy of this function in cmd/dist/test.go.
func HasSrc ¶
func HasSrc() bool
HasSrc reports whether the entire source tree is available under GOROOT.
func HasSymlink ¶
func HasSymlink() bool
HasSymlink reports whether the current system can use os.Symlink.
func MustHaveBuildMode ¶ added in v0.118.0
MustHaveBuildMode reports whether the current system can build programs in the given build mode. If not, MustHaveBuildMode calls t.Skip with an explanation. Modified by Hugo (not needed)
func MustHaveExec ¶
MustHaveExec checks that the current system can start new processes using os.StartProcess or (more commonly) exec.Command. If not, MustHaveExec calls t.Skip with an explanation.
On some platforms MustHaveExec checks for exec support by re-executing the current executable, which must be a binary built by 'go test'. We intentionally do not provide a HasExec function because of the risk of inappropriate recursion in TestMain functions.
To check for exec support outside of a test, just try to exec the command. If exec is not supported, testenv.SyscallIsNotSupported will return true for the resulting error.
func MustHaveExecPath ¶
MustHaveExecPath checks that the current system can start the named executable using os.StartProcess or (more commonly) exec.Command. If not, MustHaveExecPath calls t.Skip with an explanation.
func MustHaveExternalNetwork ¶
MustHaveExternalNetwork checks that the current system can use external (non-localhost) networks. If not, MustHaveExternalNetwork calls t.Skip with an explanation.
func MustHaveGoBuild ¶
MustHaveGoBuild checks that the current system can build programs with “go build” and then run them with os.StartProcess or exec.Command. If not, MustHaveGoBuild calls t.Skip with an explanation.
func MustHaveGoRun ¶
MustHaveGoRun checks that the current system can run programs with “go run”. If not, MustHaveGoRun calls t.Skip with an explanation.
func MustHaveLink ¶
MustHaveLink reports whether the current system can use os.Link. If not, MustHaveLink calls t.Skip with an explanation.
func MustHaveParallelism ¶ added in v0.118.0
MustHaveParallelism checks that the current system can execute multiple threads in parallel. If not, MustHaveParallelism calls t.Skip with an explanation.
func MustHaveSymlink ¶
MustHaveSymlink reports whether the current system can use os.Symlink. If not, MustHaveSymlink calls t.Skip with an explanation.
func MustInternalLink ¶ added in v0.81.0
MustInternalLink checks that the current system can link programs with internal linking. If not, MustInternalLink calls t.Skip with an explanation.
func MustInternalLinkPIE ¶ added in v0.133.0
MustInternalLinkPIE checks whether the current system can link PIE binary using internal linking. If not, MustInternalLinkPIE calls t.Skip with an explanation. Modified by Hugo (not needed)
func OptimizationOff ¶ added in v0.106.0
func OptimizationOff() bool
OptimizationOff reports whether optimization is disabled.
func ParallelOn64Bit ¶ added in v0.133.0
ParallelOn64Bit calls t.Parallel() unless there is a case that cannot be parallel. This function should be used when it is necessary to avoid t.Parallel on 32-bit machines, typically because the test uses lots of memory. Disabled by Hugo.
func SkipFlakyNet ¶
func SkipIfOptimizationOff ¶ added in v0.106.0
SkipIfOptimizationOff skips t if optimization is disabled.
func SkipIfShortAndSlow ¶ added in v0.81.0
SkipIfShortAndSlow skips t if -short is set and the CPU running the test is suspected to be slow.
(This is useful for CPU-intensive tests that otherwise complete quickly.)
func SyscallIsNotSupported ¶ added in v0.118.0
SyscallIsNotSupported reports whether err may indicate that a system call is not supported by the current platform or execution environment.
func WriteImportcfg ¶ added in v0.111.0
WriteImportcfg writes an importcfg file used by the compiler or linker to dstPath containing entries for the file mappings in packageFiles, as well as for the packages transitively imported by the package(s) in pkgs.
pkgs may include any package pattern that is valid to pass to 'go list', so it may also be a list of Go source files all in the same directory.
Types ¶
This section is empty.