// 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 MustHaveExec(t testing.TB) { … } var tryExec … // Executable is a wrapper around [MustHaveExec] and [os.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. func Executable(t testing.TB) string { … } var exePath … var execPaths … // 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 MustHaveExecPath(t testing.TB, path string) { … } // 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 CleanCmdEnv(cmd *exec.Cmd) *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 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 CommandContext(t testing.TB, ctx context.Context, name string, args ...string) *exec.Cmd { … } // Command is like exec.Command, but applies the same changes as // testenv.CommandContext (with a default Context). func Command(t testing.TB, name string, args ...string) *exec.Cmd { … }