Package icmd executes binaries and provides convenient assertions for testing the results.
- type Cmd
- type CmdOp
- type Expected
- type Result
const None = "[NOTHING]"
None is a token to inform Result.Assert that the output should be empty
Success is the default expected result. A Success result is one with a 0 ExitCode.
Cmd contains the arguments and options for a process to run as part of a test suite.
type CmdOp func(*Cmd)
CmdOp is an operation which modified a Cmd structure used to execute commands
WithEnv sets the environment variable of the command. Each arguments are in the form of KEY=VALUE
WithStdin sets the standard input of the command to the specified reader
Expected is the expected output from a Command. This struct is compared to a Result struct by Result.Assert().
Result stores the result of running a command
RunCmd runs a command and returns a Result
func RunCommand ¶
RunCommand runs a command with default options, and returns a result
StartCmd starts a command, but doesn't wait for it to finish
WaitOnCmd waits for a command to complete. If timeout is non-nil then only wait until the timeout.
Assert compares the Result against the Expected struct, and fails the test if any of the expectations are not met.
This function is equivalent to assert.Assert(t, result.Equal(exp)).
Combined returns the stdout and stderr combined into a single string
Compare the result to Expected and return an error if they do not match.
Equal compares the result to Expected. If the result doesn't match expected returns a formatted failure message with the command, stdout, stderr, exit code, and any failed expectations.
Stderr returns the stderr of the process as a string
Stdout returns the stdout of the process as a string