Documentation ¶
Overview ¶
Package cmdtest contains utilities for testing commands.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CannedOutput ¶
type CannedOutput string
CannedOutput represents expected output of a command.
This type automatically accepts conversions from string literals but makes it harder to misuse with variables of string type.
func (CannedOutput) MatchesBuffer ¶
func (c CannedOutput) MatchesBuffer(buf *bytes.Buffer) (a, e string, ok bool)
MatchesBuffer returns actual, expected strings and equality flag
The contents of the buffer is transformed, such, so that white-space differences become more apparent. Tabs present in the buffer are replaced with <TAB>, while any line-trailing white-space is terminated with <EOL>.
type Invocation ¶
type Invocation struct { Cmd cmdr.Cmd Args []string Stdin, Stdout, Stderr bytes.Buffer ExitCode int }
Invocation represents a single execution of a command for testing.
func Invoke ¶
func Invoke(cmd cmdr.Cmd, args ...string) *Invocation
Invoke returns a Invocation for the given command and arguments.
The tested command will be invoked with argv0 matching the name of the package being tested. Use InvokeWithArgv0 to provide a custom value.
Tested command is passed to cmdr.RunMain for execution. Instead of exiting, non zero exit code is recorded for inspection. Standard input-output streams are replaced by byte buffers.
Note that IO redirection does not happen at the OS level. Tested commands must use cmdr.Stdio helper function to access suggested IO interfaces.
func InvokeWithArgv0 ¶
func InvokeWithArgv0(cmd cmdr.Cmd, argv0 string, args ...string) *Invocation
InvokeWithArgv0 is like Invoke with explicit argv0.
func (*Invocation) ExpectExitCode ¶
func (inv *Invocation) ExpectExitCode(code int) error
ExpectExitCode checks an expected exit code.
func (*Invocation) ExpectStderr ¶
func (inv *Invocation) ExpectStderr(c CannedOutput) error
ExpectStderr assets presence of expected content printed to stderr.
func (*Invocation) ExpectStdout ¶
func (inv *Invocation) ExpectStdout(c CannedOutput) error
ExpectStdout assets presence of expected content printed to stdout.