Documentation
¶
Index ¶
- func Cmp[T any](t *testing.T, prefix string, want, got T, opts ...cmp.Option)
- func CmpError(t *testing.T, funcString string, wantErr, err error, opts ...cmp.Option)
- func CmpPanic[T any](t *testing.T, funcString string, f func() T, want interface{}, ...) T
- func FilepathAbs(t *testing.T, s ...string) string
- func StubEnv(t *testing.T, m map[string]string)
- func StubGetwd(t *testing.T, wd string, err error)
- func StubValue[T any](t *testing.T, originalValue *T, newValue T)
- func TempFile(t *testing.T, pattern string) *os.File
- func Write(t *testing.T, iow io.Writer, contents []string)
- type Changeable
- type CompleteTestCase
- type ExecuteTestCase
- type FakeOS
- type FakeRun
- type Output
- type RunContents
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CmpPanic ¶
func CmpPanic[T any](t *testing.T, funcString string, f func() T, want interface{}, opts ...cmp.Option) T
CmpPanic runs the provided function, `f`, and verifies the proper panic value is recoverd.
func FilepathAbs ¶
FilepathAbs returns the absolute, joined filepath for the provided strings. Fails the test if unsuccessful.
Types ¶
type Changeable ¶
type Changeable interface { // Changed returns whether or not the undelrying command object has changed. Changed() bool }
Changeable is an interface for commands that can be changed. Note: this is really just using a function from the `sourcerer.CLI` interface.
type CompleteTestCase ¶
type CompleteTestCase struct { // Node is the root `Node` of the command to test. Node command.Node // Args is the list of arguments provided to the command. // Remember that args requires a dummy command argument (e.g. "cmd ") // since `COMP_LINE` includes that. Args string // PassthroughArgs are the passthrough args provided to the command autocompletion. PassthroughArgs []string // Env is the map of os environment variables to stub. If nil, this is not stubbed. Env map[string]string // OS is the OS to use for the test. OS command.OS // Want is the expected `Autocompletion` object produced by the test. Want *command.Autocompletion // WantErr is the error that should be returned. WantErr error // WantData is the `Data` object that should be constructed. WantData *command.Data // SkipDataCheck skips the check on `WantData`. SkipDataCheck bool // DataCmpOpts is the set of cmp.Options that should be used // when comparing data. DataCmpOpts cmp.Options // RunResponses are the stubbed responses to return from exec.Cmd.Run. RunResponses []*FakeRun // WantRunContents are the set of shell commands that should have been run. WantRunContents []*RunContents }
CompleteTestCase is a test case object for testing command autocompletion.
func (*CompleteTestCase) GetEnv ¶
func (ctc *CompleteTestCase) GetEnv() map[string]string
type ExecuteTestCase ¶
type ExecuteTestCase struct { // Node is the root `Node` of the command to test. Node command.Node // Args is the list of arguments provided to the command. Args []string // Env is the map of os environment variables to stub. If nil, this is not stubbed. Env map[string]string // OS is the OS to use for the test. OS command.OS // WantData is the `Data` object that should be constructed. WantData *command.Data // SkipDataCheck skips the check on `WantData`. SkipDataCheck bool // DataCmpOpts is the set of cmp.Options that should be used // when comparing data. DataCmpOpts cmp.Options // WantExecuteData is the `ExecuteData` object that should be constructed. WantExecuteData *command.ExecuteData // WantStdout is the data that should be sent to stdout. WantStdout string // WantStderr is the data that should be sent to stderr. WantStderr string // WantErr is the error that should be returned. WantErr error // WantPanic is the object that should be passed to panic (or nil if no panic expected). WantPanic interface{} // WantRunContents are the set of shell commands that should have been run. WantRunContents []*RunContents // RequiresSetup indicates whether or not the command requires setup RequiresSetup bool // SetupContents is the contents of the setup file provided to the command. SetupContents []string // RunResponses are the stubbed responses to return from exec.Cmd.Run. RunResponses []*FakeRun }
ExecuteTestCase is a test case object for testing command execution.
func (*ExecuteTestCase) GetEnv ¶
func (etc *ExecuteTestCase) GetEnv() map[string]string
type FakeOS ¶
type FakeOS struct{}
FakeOS is a fake `command.OS` interface implementer that can be used for testing purposes.
func (*FakeOS) UnsetEnvVar ¶
type Output ¶
Output is a fake `Output` object that can be used for testing.
func (*Output) GetStderr ¶
GetStderr returns all of the data that was written to the stderr channel.
func (*Output) GetStderrByCalls ¶
GetStderrByCalls returns all of the individual calls made to stdout.
func (*Output) GetStdout ¶
GetStdout returns all of the data that was written to the stdout channel.
func (*Output) GetStdoutByCalls ¶
GetStdoutByCalls returns all of the individual calls made to stdout.