execxtest

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2026 License: MIT Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package execxtest provides a fake execx.Runner that records every command instead of running it.

Index

Constants

This section is empty.

Variables

View Source
var ErrFailed = errors.New("exit status 1")

ErrFailed is a generic command failure for handlers to return.

View Source
var ErrKilled = errors.New("signal: killed")

ErrKilled is what Wait returns for a fake process stopped with Kill or by its context.

Functions

This section is empty.

Types

type Fake

type Fake struct {
	// Handler decides the result of each Run or Output call. When nil, every
	// command succeeds with no output.
	Handler func(c execx.Cmd) ([]byte, error)
	// Installed lists the executables LookPath reports as present.
	Installed map[string]bool
	// OnStart is called with every process launched through Start, e.g. to
	// make it exit at once. Returning an error makes Start fail instead.
	OnStart func(p *Process) error
	// contains filtered or unexported fields
}

Fake is an execx.Runner that records commands and answers them through Handler. The zero value succeeds for every command with empty output and reports every executable as missing from PATH.

func Install

func Install(t testing.TB) *Fake

Install replaces the execx runner with a new Fake for the duration of t. Tests using it must not run in parallel, since the runner is package-level.

func (*Fake) Calls

func (f *Fake) Calls() []execx.Cmd

Calls returns the recorded commands in order.

func (*Fake) Commands

func (f *Fake) Commands() []string

Commands returns the recorded command lines, e.g. "go test -v ./...".

func (*Fake) Find

func (f *Fake) Find(prefix string) (execx.Cmd, bool)

Find returns the first recorded command whose line starts with prefix.

func (*Fake) LookPath

func (f *Fake) LookPath(name string) (string, error)

LookPath implements execx.Runner.

func (*Fake) Output

func (f *Fake) Output(c execx.Cmd) ([]byte, error)

Output implements execx.Runner.

func (*Fake) Processes added in v0.5.0

func (f *Fake) Processes() []*Process

Processes returns the processes launched through Start, in order.

func (*Fake) Run

func (f *Fake) Run(c execx.Cmd) error

Run implements execx.Runner.

func (*Fake) Start added in v0.5.0

func (f *Fake) Start(ctx context.Context, c execx.Cmd) (execx.Process, error)

Start implements execx.Runner. The command is recorded like any other, and the returned process runs until killed, exited or ctx is canceled.

type Process added in v0.5.0

type Process struct {
	Cmd execx.Cmd
	// contains filtered or unexported fields
}

Process is a fake background process. It runs until Kill, Exit or the cancellation of the context it was started with.

func (*Process) Done added in v0.5.0

func (p *Process) Done() bool

Done reports whether the process has terminated for any reason.

func (*Process) Exit added in v0.5.0

func (p *Process) Exit(err error)

Exit makes the process terminate on its own with err (nil for success).

func (*Process) Kill added in v0.5.0

func (p *Process) Kill() error

Kill implements execx.Process.

func (*Process) Killed added in v0.5.0

func (p *Process) Killed() bool

Killed reports whether Kill was called.

func (*Process) Wait added in v0.5.0

func (p *Process) Wait() error

Wait implements execx.Process.

Jump to

Keyboard shortcuts

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