package clitest
import "src.elv.sh/pkg/cli/clitest"
Package clitest provides utilities for testing cli.App.
Index ¶
- Constants
- Variables
- func StartReadCode(readCode func() (string, error)) (<-chan string, <-chan error)
- func WithSpec(f func(*cli.AppSpec)) func(*cli.AppSpec, TTYCtrl)
- func WithTTY(f func(TTYCtrl)) func(*cli.AppSpec, TTYCtrl)
- type Fixture
- func Setup(fns ...func(*cli.AppSpec, TTYCtrl)) *Fixture
- func (f *Fixture) MakeBuffer(args ...interface{}) *term.Buffer
- func (f *Fixture) Stop()
- func (f *Fixture) TestTTY(t *testing.T, args ...interface{})
- func (f *Fixture) TestTTYNotes(t *testing.T, args ...interface{})
- func (f *Fixture) Wait() (string, error)
- type TTYCtrl
- func GetTTYCtrl(t cli.TTY) (TTYCtrl, bool)
- func NewFakeTTY() (cli.TTY, TTYCtrl)
- func (t TTYCtrl) Buffer() *term.Buffer
- func (t TTYCtrl) BufferHistory() []*term.Buffer
- func (t TTYCtrl) ClearScreen()
- func (t TTYCtrl) EventCh() chan term.Event
- func (t TTYCtrl) Inject(events ...term.Event)
- func (t TTYCtrl) InjectSignal(sigs ...os.Signal)
- func (t TTYCtrl) LastBuffer() *term.Buffer
- func (t TTYCtrl) LastNotesBuffer() *term.Buffer
- func (t TTYCtrl) NotesBufferHistory() []*term.Buffer
- func (t TTYCtrl) NotifySignals() <-chan os.Signal
- func (t TTYCtrl) RawInput() int
- func (t TTYCtrl) ReadEvent() (term.Event, error)
- func (t TTYCtrl) ResetBuffer()
- func (t TTYCtrl) ScreenCleared() int
- func (t TTYCtrl) SetRawInput(n int)
- func (t TTYCtrl) SetSetup(restore func(), err error)
- func (t TTYCtrl) SetSize(h, w int)
- func (t TTYCtrl) Setup() (func(), error)
- func (t TTYCtrl) Size() (h, w int)
- func (t TTYCtrl) StopInput()
- func (t TTYCtrl) StopSignals()
- func (t TTYCtrl) TestBuffer(tt *testing.T, b *term.Buffer)
- func (t TTYCtrl) TestNotesBuffer(tt *testing.T, b *term.Buffer)
- func (t TTYCtrl) UpdateBuffer(bufNotes, buf *term.Buffer, _ bool) error
Package Files ¶
Constants ¶
const ( FakeTTYHeight = 20 FakeTTYWidth = 50 )
Initial size of fake TTY.
Variables ¶
var Styles = ui.RuneStylesheet{ '_': ui.Underlined, 'b': ui.Bold, '*': ui.Stylings(ui.Bold, ui.FgWhite, ui.BgMagenta), '+': ui.Inverse, '/': ui.FgBlue, '#': ui.Stylings(ui.Inverse, ui.FgBlue), '!': ui.FgRed, '?': ui.Stylings(ui.FgBrightWhite, ui.BgRed), '-': ui.FgMagenta, 'X': ui.Stylings(ui.Inverse, ui.FgMagenta), 'v': ui.FgGreen, 'V': ui.Stylings(ui.Underlined, ui.FgGreen), '$': ui.FgMagenta, 'c': ui.FgCyan, }
Styles defines a common stylesheet for unit tests.
func StartReadCode ¶
StartReadCode starts the readCode function asynchronously, and returns two channels that deliver its return values. The two channels are closed after return values are delivered, so that subsequent reads will return zero values and not block.
func WithSpec ¶
WithSpec takes a function that operates on *cli.AppSpec, and wraps it into a form suitable for passing to Setup.
func WithTTY ¶
WithTTY takes a function that operates on TTYCtrl, and wraps it to a form suitable for passing to Setup.
type Fixture ¶
Fixture is a test fixture.
func Setup ¶
Setup sets up a test fixture. It contains an App whose ReadCode method has been started asynchronously.
func (*Fixture) MakeBuffer ¶
MakeBuffer is a helper for building a buffer. It is equivalent to term.NewBufferBuilder(width of terminal).MarkLines(args...).Buffer().
func (*Fixture) Stop ¶
Stop stops ReadCode and waits for it to finish. If ReadCode has already been stopped, it is a no-op.
func (*Fixture) TestTTY ¶
TestTTY is equivalent to f.TTY.TestBuffer(f.MakeBuffer(args...)).
func (*Fixture) TestTTYNotes ¶
TestTTYNotes is equivalent to f.TTY.TestNotesBuffer(f.MakeBuffer(args...)).
func (*Fixture) Wait ¶
Wait waits for ReaCode to finish, and returns its return values.
type TTYCtrl ¶
type TTYCtrl struct {
// contains filtered or unexported fields
}
TTYCtrl is an interface for controlling a fake terminal.
func GetTTYCtrl ¶
GetTTYCtrl takes a TTY and returns a TTYCtrl and true, if the TTY is a fake terminal. Otherwise it returns an invalid TTYCtrl and false.
func NewFakeTTY ¶
NewFakeTTY creates a new FakeTTY and a handle for controlling it. The initial size of the terminal is FakeTTYHeight and FakeTTYWidth.
func (TTYCtrl) Buffer ¶
Returns the last recorded buffer.
func (TTYCtrl) BufferHistory ¶
BufferHistory returns a slice of all buffers that have appeared.
func (TTYCtrl) ClearScreen ¶
func (t TTYCtrl) ClearScreen()
func (TTYCtrl) EventCh ¶
EventCh returns the underlying channel for delivering events.
func (TTYCtrl) Inject ¶
Inject injects events to the fake terminal.
func (TTYCtrl) InjectSignal ¶
InjectSignal injects signals.
func (TTYCtrl) LastBuffer ¶
LastBuffer returns the last buffer that has appeared.
func (TTYCtrl) LastNotesBuffer ¶
func (TTYCtrl) NotesBufferHistory ¶
NotesBufferHistory returns a slice of all notes buffers that have appeared.
func (TTYCtrl) NotifySignals ¶
func (TTYCtrl) RawInput ¶
RawInput returns the argument in the last call to the SetRawInput method of the TTY.
func (TTYCtrl) ReadEvent ¶
Returns next event from t.eventCh.
func (TTYCtrl) ResetBuffer ¶
func (t TTYCtrl) ResetBuffer()
Records a nil buffer.
func (TTYCtrl) ScreenCleared ¶
ScreenCleared returns the number of times ClearScreen has been called on the TTY.
func (TTYCtrl) SetRawInput ¶
Records the argument.
func (TTYCtrl) SetSetup ¶
SetSetup sets the return values of the Setup method of the fake terminal.
func (TTYCtrl) SetSize ¶
SetSize sets the size of the fake terminal.
func (TTYCtrl) Setup ¶
Delegates to the setup function specified using the SetSetup method of TTYCtrl, or return a nop function and a nil error.
func (TTYCtrl) Size ¶
Returns the size specified by using the SetSize method of TTYCtrl.
func (TTYCtrl) StopInput ¶
func (t TTYCtrl) StopInput()
Closes eventCh.
func (TTYCtrl) StopSignals ¶
func (t TTYCtrl) StopSignals()
func (TTYCtrl) TestBuffer ¶
TestBuffer verifies that a buffer will appear within the timeout of 4 seconds, and fails the test if it doesn't
func (TTYCtrl) TestNotesBuffer ¶
TestNotesBuffer verifies that a notes buffer will appear within the timeout of 4 seconds, and fails the test if it doesn't
func (TTYCtrl) UpdateBuffer ¶
UpdateBuffer records a new pair of buffers, i.e. sending them to their respective channels and appending them to their respective slices.
Package clitest imports 9 packages (graph). Updated now.
Tools for package owners.