clitest

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2024 License: ISC Imports: 7 Imported by: 0

Documentation

Overview

Package clitest provides utilities for testing command-line applications.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run[App cli.App](t *testing.T, setup func(*testing.T) App, cases map[string]Case[App])

Run runs the provided test cases against the given command-line application.

Types

type Case

type Case[App cli.App] struct {
	// Args are the command-line arguments to pass to the application.
	Args []string
	// Env are the environment variables to set before running the application.
	Env map[string]string
	// WantErr is the expected error to be returned by the application, checked
	// with errors.Is.
	WantErr error
	// WantErrType is the expected type of the error to be returned by the
	// application, checked with errors.As.
	WantErrType error
	// WantNothingPrinted indicates that no output should be printed to stdout or
	// stderr.
	WantNothingPrinted bool
	// WantInStdout is the expected substring to be present in the stdout output.
	WantInStdout string
	// WantInStderr is the expected substring to be present in the stderr output.
	WantInStderr string
	// CheckFunc is an optional function to perform additional checks after the
	// application has run.
	CheckFunc func(*testing.T, App)
}

Case represents a single test case for a command-line application.

Jump to

Keyboard shortcuts

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