testenv

package standard library
go1.19 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2022 License: BSD-3-Clause Imports: 15 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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 go1.16

func CPUIsSlow() bool

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

func CanInternalLink() bool

CanInternalLink reports whether the current system can link programs with internal linking. (This is the opposite of cmd/internal/sys.MustLinkExternal. Keep them in sync.)

func CleanCmdEnv added in go1.10

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

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.

func GOROOT added in go1.19

func GOROOT(t testing.TB) string

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.

If GOROOT cannot be found, GOROOT skips t if t is non-nil, or panics otherwise.

func GoTool added in go1.8

func GoTool() (string, error)

GoTool reports the path to the Go tool.

func GoToolPath added in go1.7

func GoToolPath(t testing.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.

func HasCGO added in go1.10

func HasCGO() bool

HasCGO reports whether the current system can use cgo.

func HasExec

func HasExec() bool

HasExec reports whether the current system can start new processes using os.StartProcess or (more commonly) exec.Command.

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.

func HasGoRun

func HasGoRun() bool

HasGoRun reports whether the current system can run programs with “go run.”

func HasLink() bool

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

func HasSrc added in go1.9

func HasSrc() bool

HasSrc reports whether the entire source tree is available under GOROOT.

func HasSymlink() bool

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

func MustHaveCGO added in go1.8.1

func MustHaveCGO(t testing.TB)

MustHaveCGO calls t.Skip if cgo is not available.

func MustHaveExec

func MustHaveExec(t testing.TB)

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.

func MustHaveExecPath added in go1.13

func MustHaveExecPath(t testing.TB, path string)

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

func MustHaveExternalNetwork(t testing.TB)

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

func MustHaveGoBuild

func MustHaveGoBuild(t testing.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.

func MustHaveGoRun

func MustHaveGoRun(t testing.TB)

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

func MustHaveLink(t testing.TB)

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

func MustHaveSymlink(t testing.TB)

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

func MustInternalLink(t testing.TB)

MustInternalLink checks that the current system can link programs with internal linking. If not, MustInternalLink calls t.Skip with an explanation.

func RunWithTimeout added in go1.18

func RunWithTimeout(t testing.TB, cmd *exec.Cmd) ([]byte, error)

RunWithTimeout runs cmd and returns its combined output. If the subprocess exits with a non-zero status, it will log that status and return a non-nil error, but this is not considered fatal.

func SkipFlaky added in go1.7

func SkipFlaky(t testing.TB, issue int)

func SkipFlakyNet added in go1.7

func SkipFlakyNet(t testing.TB)

func SkipIfShortAndSlow added in go1.16

func SkipIfShortAndSlow(t testing.TB)

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

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL