Documentation ¶
Overview ¶
CLI testing package for the Go language.
Developing a command line application? Wanna be able to test your app from the outside? If the answer is Yes to at least one of the questions, keep reading.
`testcli` is a wrapper around os/exec to test CLI apps in Go lang, minimalistic, so you can do your tests with `testing` or any other testing framework.
Index ¶
- Variables
- func Error() error
- func Failure() bool
- func Run(name string, arg ...string)
- func Stderr() string
- func StderrContains(str string) bool
- func StderrMatches(regex string) bool
- func Stdout() string
- func StdoutContains(str string) bool
- func StdoutMatches(regex string) bool
- func Success() bool
- type Cmd
- func (c *Cmd) Error() error
- func (c *Cmd) Failure() bool
- func (c *Cmd) Run()
- func (c *Cmd) SetEnv(env []string)
- func (c *Cmd) SetStdin(stdin io.Reader)
- func (c *Cmd) Stderr() string
- func (c *Cmd) StderrContains(str string) bool
- func (c *Cmd) StderrMatches(regex string) bool
- func (c *Cmd) Stdout() string
- func (c *Cmd) StdoutContains(str string) bool
- func (c *Cmd) StdoutMatches(regex string) bool
- func (c *Cmd) Success() bool
Constants ¶
This section is empty.
Variables ¶
var ErrUninitializedCmd = errors.New("You need to run this command first")
ErrUninitializedCmd is returned when members are accessed before a run, that can only be used after a command has been run.
Functions ¶
func Run ¶
Run runs a command with name and arguments. After this, package-level functions will return the data about the last command run.
func StderrContains ¶
StderrContains determines if command's STDERR contains `str`, this operation is case insensitive.
func StderrMatches ¶
StderrMatches compares a regex to the stderr produced by the command.
func StdoutContains ¶
StdoutContains determines if command's STDOUT contains `str`, this operation is case insensitive.
func StdoutMatches ¶
StdoutMatches compares a regex to the stdout produced by the command.
Types ¶
type Cmd ¶
type Cmd struct {
// contains filtered or unexported fields
}
Cmd is typically constructed through the Command() call and provides state to the execution engine.
func (*Cmd) SetEnv ¶
SetEnv overwrites the environment with the provided one. Otherwise, the parent environment will be supplied.
func (*Cmd) SetStdin ¶
SetStdin sets the stdin stream. It makes no attempt to determine if the command accepts anything over stdin.
func (*Cmd) StderrContains ¶
StderrContains determines if command's STDERR contains `str`, this operation is case insensitive.
func (*Cmd) StderrMatches ¶
StderrMatches compares a regex to the stderr produced by the command.
func (*Cmd) StdoutContains ¶
StdoutContains determines if command's STDOUT contains `str`, this operation is case insensitive.
func (*Cmd) StdoutMatches ¶
StdoutMatches compares a regex to the stdout produced by the command.