Documentation
¶
Overview ¶
Package apptest 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
- type TTYCtrl
- func (t TTYCtrl) Buffer() *term.Buffer
- func (t TTYCtrl) BufferHistory() []*term.Buffer
- 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) 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
Constants ¶
const ( FakeTTYHeight = 20 FakeTTYWidth = 50 )
Initial size of fake TTY.
Variables ¶
var Styles = ui.RuneStylesheet{ '_': ui.Underlined, '*': ui.Stylings(ui.Bold, ui.FgWhite, ui.BgMagenta), '+': ui.Inverse, '/': ui.FgBlue, '#': ui.Stylings(ui.Inverse, ui.FgBlue), '!': ui.FgRed, '?': ui.BgRed, '-': ui.FgMagenta, 'X': ui.Stylings(ui.Inverse, ui.FgMagenta), 'v': ui.FgGreen, 'V': ui.Stylings(ui.Underlined, ui.FgGreen), '$': ui.FgMagenta, }
Common stylesheet.
Functions ¶
func StartReadCode ¶
StartReadCode starts the given function asynchronously. It returns two channels; when the function returns, the return values will be delivered on those two channels and the two channels will be closed.
Types ¶
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 ¶
func (f *Fixture) Stop()
Stop stops ReadCode and waits for it to finish. If ReadCode has already been stopped, it is a no-op.
func (*Fixture) TestTTYNotes ¶
TestTTYNotes is equivalent to f.TTY.TestNotesBuffer(f.MakeBuffer(args...)).
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) BufferHistory ¶
BufferHistory returns a slice of all buffers that have appeared.
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) Setup ¶
func (t TTYCtrl) Setup() (func(), error)
Delegates to the setup function specified using the SetSetup method of TTYCtrl, or return a nop function and a nil error.
func (TTYCtrl) Size ¶
func (t TTYCtrl) Size() (h, w int)
Returns the size specified by using the SetSize method of TTYCtrl.
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