subshell

package
v13.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	// Dir contains the directory in which to execute the command.
	// If empty, runs in the current directory.
	Dir string

	// Env allows to override the environment variables to use in the subshell, in the format provided by os.Environ()
	// If empty, uses the environment variables of this process.
	Env []string

	// when set, captures the output and returns it
	IgnoreOutput bool
}

Options defines optional arguments for ShellRunner.RunWith().

type TestRunner

type TestRunner struct {
	// the directory that contains mock executables, ignored if empty
	BinDir string

	// the directory that contains the global Git configuration
	HomeDir string

	// whether to log the output of subshell commands
	Verbose bool `exhaustruct:"optional"`

	// the directory in which this runner executes shell commands
	WorkingDir string
	// contains filtered or unexported fields
}

TestRunner runs shell commands using a customizable environment. This is useful in tests. Possible customizations:

  • overide environment variables
  • Temporarily override certain shell commands with mock implementations. Temporary mocks are only valid for the next command being run.

func (*TestRunner) MockBrokenCommand

func (self *TestRunner) MockBrokenCommand(name string)

MockBrokenCommand adds a mock for the given command that returns an error.

func (*TestRunner) MockCommand

func (self *TestRunner) MockCommand(name string)

MockCommand adds a mock for the command with the given name.

func (*TestRunner) MockCommitMessage

func (self *TestRunner) MockCommitMessage(message string)

MockCommitMessage sets up this runner with an editor that enters the given commit message.

func (*TestRunner) MockGit

func (self *TestRunner) MockGit(version string)

MockGit pretends that this repo has Git in the given version installed.

func (*TestRunner) MockNoCommandsInstalled

func (self *TestRunner) MockNoCommandsInstalled()

MockNoCommandsInstalled pretends that no commands are installed.

func (*TestRunner) MustQuery

func (self *TestRunner) MustQuery(name string, arguments ...string) string

MustQuery provides the output of the given command with the given arguments. Overrides will be used and removed when done.

func (*TestRunner) MustQueryStringCode

func (self *TestRunner) MustQueryStringCode(fullCmd string) (string, int)

func (*TestRunner) MustQueryStringCodeWith

func (self *TestRunner) MustQueryStringCodeWith(fullCmd string, opts *Options) (string, int)

func (*TestRunner) MustQueryWith

func (self *TestRunner) MustQueryWith(opts *Options, cmd string, args ...string) string

MustQueryWith provides the output of the given command and didn't encounter any form of error.

func (*TestRunner) MustRun

func (self *TestRunner) MustRun(name string, arguments ...string)

Run runs the given command with the given arguments. Overrides will be used and removed when done.

func (*TestRunner) MustRunMany

func (self *TestRunner) MustRunMany(commands [][]string)

func (*TestRunner) Query

func (self *TestRunner) Query(name string, arguments ...string) (string, error)

Query provides the output of the given command. Overrides will be used and removed when done.

func (*TestRunner) QueryString

func (self *TestRunner) QueryString(fullCmd string) (string, error)

QueryString runs the given command (including possible arguments). Overrides will be used and removed when done.

func (*TestRunner) QueryStringWith

func (self *TestRunner) QueryStringWith(fullCmd string, opts *Options) (string, error)

QueryStringWith runs the given command (including possible arguments) using the given options. opts.Dir is a relative path inside the working directory of this ShellRunner. Overrides will be used and removed when done.

func (*TestRunner) QueryTrim

func (self *TestRunner) QueryTrim(name string, arguments ...string) (string, error)

Query provides the output of the given command. Overrides will be used and removed when done.

func (*TestRunner) QueryWith

func (self *TestRunner) QueryWith(opts *Options, cmd string, args ...string) (string, error)

QueryWith provides the output of the given command and ensures it exited with code 0.

func (*TestRunner) QueryWithCode

func (self *TestRunner) QueryWithCode(opts *Options, cmd string, args ...string) (string, int, error)

QueryWith runs the given command with the given options in this ShellRunner's directory.

func (*TestRunner) Run

func (self *TestRunner) Run(name string, arguments ...string) error

Run runs the given command with the given arguments. Overrides will be used and removed when done.

func (*TestRunner) RunMany

func (self *TestRunner) RunMany(commands [][]string) error

func (*TestRunner) SetTestOrigin

func (self *TestRunner) SetTestOrigin(content string)

SetTestOrigin adds the given environment variable to subsequent runs of commands.

Jump to

Keyboard shortcuts

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