testecho

package module
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2020 License: MPL-2.0 Imports: 6 Imported by: 0

README

testecho GoDoc Go Report Card Build Status

testecho is a program to assist test cases which assert the subject starts and ends processes as expected. Its flags allow selection of stdout, stderr, exit code, etc.

The testecho package provides functions to more easily run the CLI from test cases.

Usage

To install: go get -v github.com/codeactual/testecho/cmd/testecho

Examples

Display help

testecho --help

Print "out" to standard output:

testecho --stdout out

Same as above but also print "err" to standard error:

testecho --stdout out --stderr err

Same as above but also exit with code 7 instead of 0:

testecho --stdout out --stderr err --code 7

Same as above but also sleep for 5 seconds after printing:

testecho --stdout out --stderr err --code 7 --sleep 5

Spawn another testecho proecss, print its PID, and then sleep "forever" (10000 seconds):

testecho --spawn

Same as above but also print "err" to standard error:

testecho --spawn --stderr err

Print standard input:

echo "out" | testecho

Same as above but also print "err" to standard error:

echo "out" | testecho --stderr err

Same as above but also exit with code 7 instead of 0:

echo "out" | testecho --stderr err --code 7

Same as above but also sleep for 5 seconds after printing

echo "out" | testecho --stderr err --code 7 --sleep 5

Examples (in other projects)

Development

License

Mozilla Public License Version 2.0 (About, FAQ)

Contributing

  • Please feel free to submit issues, PRs, questions, and feedback.
  • Although this repository consists of snapshots extracted from a private monorepo using transplant, PRs are welcome. Standard GitHub workflows are still used.

Documentation

Overview

Package testecho assists execution of the CLI from test cases and assertion of its result.

Its provides some default inputs for the CLI to support use cases where details such as the exact standard output/error are asserted for equality but semantic content is unnecessary.

Index

Constants

View Source
const (
	// DefaultStdout is the default value for the --stdout flag.
	DefaultStdout = "some stdout message"

	// DefaultStdoutFromStdin is the standard output emitted by testecho when it receives DefaultStdout via
	// standard input.
	//
	// It supports the "testecho | testecho" use case and asserting the final process's behavior.
	DefaultStdoutFromStdin = "stdin [" + DefaultStdout + "]"

	// DefaultStderr is the default value for the --stderr flag.
	DefaultStderr = "some stderr message"

	// DefaultStdoutFromStdinNested is the standard output emitted by testecho when it receives
	// DefaultStdoutFromStdin via standard input.
	//
	// It supports the "testecho | testecho | testecho" use case and asserting the final process's behavior.
	DefaultStdoutFromStdinNested = "stdin [" + DefaultStdoutFromStdin + "]"
)

Variables

This section is empty.

Functions

func NewCmd

func NewCmd(ctx context.Context, i ...Input) *exec.Cmd

NewCmd converts an Input into a command.

It no Input is passed, a zero-valued Input is used. If one Input is passed, it is converted. If multiple Input values are passed, it panics.

func NewCmdArgs

func NewCmdArgs(inputs ...Input) (args []string)

NewCmdArgs converts an Input value into argument strings for use in exec.Command.

It no Input is passed, a zero-valued Input is used. If one Input is passed, it is converted. If multiple Input values are passed, it panics.

func NewCmdString

func NewCmdString(i ...Input) string

NewCmdString returns a full command string based on the selected CLI input.

It includes the absolute path from Which().

It no Input is passed, a zero-valued Input is used. If one Input is passed, it is converted. If multiple Input values are passed, it panics.

func Which

func Which() string

Which returns the absolute path to where the CLI would be installed based on GOPATH.

Types

type Input

type Input struct {
	// Code is the value for the --code flag.
	Code int

	// Stderr is a value for the --sleep flag.
	Sleep int

	// Spawn is true if the command should spawn a child process and block forever (because the child does).
	Spawn bool

	// Stdin is true if the command is expected to receive stdin.
	Stdin bool

	// Stderr is a value for the --stderr flag.
	//
	// If empty, DefaultStderr is used.
	Stderr string

	// Stderr is a value for the --stdout flag.
	//
	// If empty, DefaultStdout is used.
	Stdout string
}

Input defines the CLI flags to use in a testecho invocation.

Directories

Path Synopsis
cmd
testecho
Command testecho assists test cases which assert the subject handles process execution as expected.
Command testecho assists test cases which assert the subject handles process execution as expected.
internal

Jump to

Keyboard shortcuts

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