Movatterモバイル変換


[0]ホーム

URL:


testenv

packagestandard library
go1.25.5Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2025 License:BSD-3-ClauseImports:19Imported by:0

Details

Repository

cs.opensource.google/go/go

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

Constants

This section is empty.

Variables

Sigquit 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.

funcCPUIsSlowadded ingo1.16

func CPUIsSlow()bool

CPUIsSlow reports whether the CPU running the test is suspected to be slow.

funcCPUProfilingBrokenadded ingo1.23.8

func CPUProfilingBroken()bool

CPUProfilingBroken returns true if CPU profiling has known issues on thisplatform.

funcCanInternalLinkadded ingo1.16

func CanInternalLink(withCgobool)bool

CanInternalLink reports whether the current system can link programs withinternal linking.

funcCleanCmdEnvadded ingo1.10

func CleanCmdEnv(cmd *exec.Cmd) *exec.Cmd

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.

funcCommandadded ingo1.20

func Command(ttesting.TB, namestring, args ...string) *exec.Cmd

Command is like exec.Command, but applies the same changes astestenv.CommandContext (with a default Context).

funcCommandContextadded ingo1.20

func CommandContext(ttesting.TB, ctxcontext.Context, namestring, args ...string) *exec.Cmd

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.

funcExecutableadded ingo1.24.0

func Executable(ttesting.TB)string

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.

funcGOROOTadded ingo1.19

func GOROOT(ttesting.TB)string

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.

funcGoTooladded ingo1.8

func GoTool() (string,error)

GoTool reports the path to the Go tool.

funcGoToolPathadded ingo1.7

func GoToolPath(ttesting.TB)string

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.

funcHasCGOadded ingo1.10

func HasCGO()bool

HasCGO reports whether the current system can use cgo.

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”.

funcHasLinkadded ingo1.8

func HasLink()bool

HasLink reports whether the current system can use os.Link.

funcHasParallelismadded 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.

funcHasSymlinkadded ingo1.8

func HasSymlink()bool

HasSymlink reports whether the current system can use os.Symlink.

funcMustHaveBuildModeadded ingo1.21.0

func MustHaveBuildMode(ttesting.TB, buildmodestring)

MustHaveBuildMode reports whether the current system can build programs inthe given build mode.If not, MustHaveBuildMode calls t.Skip with an explanation.

funcMustHaveCGOadded ingo1.8.1

func MustHaveCGO(ttesting.TB)

MustHaveCGO calls t.Skip if cgo is not available.

funcMustHaveExec

func MustHaveExec(ttesting.TB)

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.

funcMustHaveExecPathadded ingo1.13

func MustHaveExecPath(ttesting.TB, pathstring)

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

func MustHaveExternalNetwork(ttesting.TB)

MustHaveExternalNetwork checks that the current system can useexternal (non-localhost) networks.If not, MustHaveExternalNetwork calls t.Skip with an explanation.

funcMustHaveGoBuild

func MustHaveGoBuild(ttesting.TB)

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

func MustHaveGoRun(ttesting.TB)

MustHaveGoRun checks that the current system can run programs with “go run”.If not, MustHaveGoRun calls t.Skip with an explanation.

funcMustHaveLinkadded ingo1.8

func MustHaveLink(ttesting.TB)

MustHaveLink reports whether the current system can use os.Link.If not, MustHaveLink calls t.Skip with an explanation.

funcMustHaveParallelismadded ingo1.21.0

func MustHaveParallelism(ttesting.TB)

MustHaveParallelism checks that the current system can execute multiplethreads in parallel. If not, MustHaveParallelism calls t.Skip with an explanation.

funcMustHaveSourceadded ingo1.24.0

func MustHaveSource(ttesting.TB)

MustHaveSource checks that the entire source tree is available under GOROOT.If not, it calls t.Skip with an explanation.

funcMustHaveSymlinkadded ingo1.8

func MustHaveSymlink(ttesting.TB)

MustHaveSymlink reports whether the current system can use os.Symlink.If not, MustHaveSymlink calls t.Skip with an explanation.

funcMustInternalLinkadded 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.

funcMustInternalLinkPIEadded ingo1.23.0

func MustInternalLinkPIE(ttesting.TB)

MustInternalLinkPIE checks whether the current system can link PIE binary usinginternal linking.If not, MustInternalLinkPIE calls t.Skip with an explanation.

funcOptimizationOffadded ingo1.20

func OptimizationOff()bool

OptimizationOff reports whether optimization is disabled.

funcParallelOn64Bitadded ingo1.23.0

func ParallelOn64Bit(t *testing.T)

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.

funcSkipFlakyadded ingo1.7

func SkipFlaky(ttesting.TB, issueint)

funcSkipFlakyNetadded ingo1.7

func SkipFlakyNet(ttesting.TB)

funcSkipIfOptimizationOffadded ingo1.20

func SkipIfOptimizationOff(ttesting.TB)

SkipIfOptimizationOff skips t if optimization is disabled.

funcSkipIfShortAndSlowadded ingo1.16

func SkipIfShortAndSlow(ttesting.TB)

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.)

funcSyscallIsNotSupportedadded ingo1.21.0

func SyscallIsNotSupported(errerror)bool

SyscallIsNotSupported reports whether err may indicate that a system call isnot supported by the current platform or execution environment.

funcWriteImportcfgadded ingo1.20

func WriteImportcfg(ttesting.TB, dstPathstring, packageFiles map[string]string, pkgs ...string)

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

typeSpecialBuildTypesadded ingo1.25.0

type SpecialBuildTypes struct {CgoboolAsanboolMsanboolRacebool}

SpecialBuildTypes are interesting build types that may affect linking.

var NoSpecialBuildTypesSpecialBuildTypes

NoSpecialBuildTypes indicates a standard, no cgo go build.

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp