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
Run runs a Program with the given arguments. It returns the Program's exit code and output to stdout and stderr.
func SetDeprecationLevel ¶
SetDeprecationLevel sets prog.DeprecationLevel to the given value for the duration of a test.
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
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
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
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
WithStdin returns an altered Case that provides the given input to stdin of the program.
func (Case) WritesStderr ¶ added in v0.17.0
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
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
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
WritesStdoutContaining returns an altered Case that requires the program run to write output to stdout that contains the given text as a substring.