progtest

package
v0.20.1 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2024 License: BSD-2-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package progtest provides a framework for testing subprograms.

The entry point for the framework is the Test function, which accepts a *testing.T, the Program implementation under test, and any number of test cases.

Test cases are constructed using the ThatElvish function, followed by method calls that add additional information to it.

Example:

Test(t, someProgram,
     ThatElvish("-c", "echo hello").WritesStdout("hello\n"))

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run added in v0.17.0

func Run(p prog.Program, args ...string) (exit int, stdout, stderr string)

Run runs a Program with the given arguments. It returns the Program's exit code and output to stdout and stderr.

func Test added in v0.17.0

func Test(t *testing.T, p prog.Program, cases ...Case)

Test runs test cases against a given program.

Types

type Case added in v0.17.0

type Case struct {
	// contains filtered or unexported fields
}

Case is a test case that can be used in Test.

func ThatElvish added in v0.17.0

func ThatElvish(args ...string) Case

ThatElvish returns a new Case with the specified CLI arguments.

The new Case expects the program run to exit with 0, and write nothing to stdout or stderr.

When combined with subsequent method calls, a test case reads like English. For example, a test for the fact that "elvish -c hello" writes "hello\n" to stdout reads:

ThatElvish("-c", "hello").WritesStdout("hello\n")

func (Case) DoesNothing added in v0.17.0

func (c Case) DoesNothing() Case

DoesNothing returns c itself. It is useful to mark tests that otherwise don't have any expectations, for example:

ThatElvish("-c", "nop").DoesNothing()

func (Case) ExitsWith added in v0.17.0

func (c Case) ExitsWith(code int) Case

ExitsWith returns an altered Case that requires the program run to return with the given exit code.

func (Case) WithStdin added in v0.17.0

func (c Case) WithStdin(s string) Case

WithStdin returns an altered Case that provides the given input to stdin of the program.

func (Case) WritesStderr added in v0.17.0

func (c Case) WritesStderr(s string) Case

WritesStderr returns an altered Case that requires the program run to write exactly the given text to stderr.

func (Case) WritesStderrContaining added in v0.17.0

func (c Case) WritesStderrContaining(s string) Case

WritesStderrContaining returns an altered Case that requires the program run to write output to stderr that contains the given text as a substring.

func (Case) WritesStdout added in v0.17.0

func (c Case) WritesStdout(s string) Case

WritesStdout returns an altered Case that requires the program run to write exactly the given text to stdout.

func (Case) WritesStdoutContaining added in v0.17.0

func (c Case) WritesStdoutContaining(s string) Case

WritesStdoutContaining returns an altered Case that requires the program run to write output to stdout that contains the given text as a substring.

Jump to

Keyboard shortcuts

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