testenv
packagestandard libraryThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
Documentation¶
Overview¶
Package testenv provides information about what functionalityis available in different testing environments run by the Go team.
It is an internal package because these details are specificto the Go team's test setup (on build.golang.org) and notfundamental to tests in general.
Index¶
- Variables
- func Builder() string
- func CPUIsSlow() bool
- func CPUProfilingBroken() 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 Executable(t testing.TB) string
- 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 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 MustHaveSource(t testing.TB)
- func MustHaveSymlink(t testing.TB)
- func MustInternalLink(t testing.TB, with SpecialBuildTypes)
- 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)
- type SpecialBuildTypes
Constants¶
This section is empty.
Variables¶
var Sigquit =syscall.SIGQUITSigquit is the signal to send to kill a hanging subprocess.Send SIGQUIT to get a stack trace.
Functions¶
funcBuilder¶
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.
funcCPUIsSlow¶added ingo1.16
func CPUIsSlow()bool
CPUIsSlow reports whether the CPU running the test is suspected to be slow.
funcCPUProfilingBroken¶added ingo1.23.8
func CPUProfilingBroken()bool
CPUProfilingBroken returns true if CPU profiling has known issues on thisplatform.
funcCanInternalLink¶added ingo1.16
CanInternalLink reports whether the current system can link programs withinternal linking.
funcCleanCmdEnv¶added ingo1.10
CleanCmdEnv will fill cmd.Env with the environment, excluding certainvariables that could modify the behavior of the Go tools such asGODEBUG 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.
funcCommand¶added ingo1.20
Command is like exec.Command, but applies the same changes astestenv.CommandContext (with a default Context).
funcCommandContext¶added ingo1.20
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 SIGKILLin its Cancel function
- if the test has a deadline, adds a Context timeout and WaitDelayfor 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.
funcExecutable¶added ingo1.24.0
Executable is a wrapper aroundMustHaveExec andos.Executable.It returns the path name for the executable that started the current process,or skips the test if the current system can't start new processes,or fails the test if the path can not be obtained.
funcGOROOT¶added ingo1.19
GOROOT reports the path to the directory containing the root of the Goproject source tree. This is normally equivalent to runtime.GOROOT, butworks 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.
funcGoToolPath¶added ingo1.7
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.
funcHasExternalNetwork¶
func HasExternalNetwork()bool
HasExternalNetwork reports whether the current system can useexternal (non-localhost) networks.
funcHasGoBuild¶
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.
funcHasGoRun¶
func HasGoRun()bool
HasGoRun reports whether the current system can run programs with “go run”.
funcHasLink¶added ingo1.8
func HasLink()bool
HasLink reports whether the current system can use os.Link.
funcHasParallelism¶added ingo1.21.0
func HasParallelism()bool
HasParallelism reports whether the current system can execute multiplethreads in parallel.There is a copy of this function in cmd/dist/test.go.
funcHasSymlink¶added ingo1.8
func HasSymlink()bool
HasSymlink reports whether the current system can use os.Symlink.
funcMustHaveBuildMode¶added ingo1.21.0
MustHaveBuildMode reports whether the current system can build programs inthe given build mode.If not, MustHaveBuildMode calls t.Skip with an explanation.
funcMustHaveCGO¶added ingo1.8.1
MustHaveCGO calls t.Skip if cgo is not available.
funcMustHaveExec¶
MustHaveExec checks that the current system can start new processesusing 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 thecurrent executable, which must be a binary built by 'go test'.We intentionally do not provide a HasExec function because of the risk ofinappropriate 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 truefor the resulting error.
funcMustHaveExecPath¶added ingo1.13
MustHaveExecPath checks that the current system can start the named executableusing os.StartProcess or (more commonly) exec.Command.If not, MustHaveExecPath calls t.Skip with an explanation.
funcMustHaveExternalNetwork¶
MustHaveExternalNetwork checks that the current system can useexternal (non-localhost) networks.If not, MustHaveExternalNetwork calls t.Skip with an explanation.
funcMustHaveGoBuild¶
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.
funcMustHaveGoRun¶
MustHaveGoRun checks that the current system can run programs with “go run”.If not, MustHaveGoRun calls t.Skip with an explanation.
funcMustHaveLink¶added ingo1.8
MustHaveLink reports whether the current system can use os.Link.If not, MustHaveLink calls t.Skip with an explanation.
funcMustHaveParallelism¶added ingo1.21.0
MustHaveParallelism checks that the current system can execute multiplethreads in parallel. If not, MustHaveParallelism calls t.Skip with an explanation.
funcMustHaveSource¶added ingo1.24.0
MustHaveSource checks that the entire source tree is available under GOROOT.If not, it calls t.Skip with an explanation.
funcMustHaveSymlink¶added ingo1.8
MustHaveSymlink reports whether the current system can use os.Symlink.If not, MustHaveSymlink calls t.Skip with an explanation.
funcMustInternalLink¶added ingo1.16
func MustInternalLink(ttesting.TB, withSpecialBuildTypes)
MustInternalLink checks that the current system can link programs with internallinking.If not, MustInternalLink calls t.Skip with an explanation.
funcMustInternalLinkPIE¶added ingo1.23.0
MustInternalLinkPIE checks whether the current system can link PIE binary usinginternal linking.If not, MustInternalLinkPIE calls t.Skip with an explanation.
funcOptimizationOff¶added ingo1.20
func OptimizationOff()bool
OptimizationOff reports whether optimization is disabled.
funcParallelOn64Bit¶added ingo1.23.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 on32-bit machines, typically because the test uses lots of memory.
funcSkipFlakyNet¶added ingo1.7
funcSkipIfOptimizationOff¶added ingo1.20
SkipIfOptimizationOff skips t if optimization is disabled.
funcSkipIfShortAndSlow¶added ingo1.16
SkipIfShortAndSlow skips t if -short is set and the CPU running the test issuspected to be slow.
(This is useful for CPU-intensive tests that otherwise complete quickly.)
funcSyscallIsNotSupported¶added ingo1.21.0
SyscallIsNotSupported reports whether err may indicate that a system call isnot supported by the current platform or execution environment.
funcWriteImportcfg¶added ingo1.20
WriteImportcfg writes an importcfg file used by the compiler or linker todstPath containing entries for the file mappings in packageFiles, as wellas 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¶
typeSpecialBuildTypes¶added ingo1.25.0
SpecialBuildTypes are interesting build types that may affect linking.
var NoSpecialBuildTypesSpecialBuildTypesNoSpecialBuildTypes indicates a standard, no cgo go build.