elvish: github.com/elves/elvish/pkg/cli/apptest Index | Files

package apptest

import "github.com/elves/elvish/pkg/cli/apptest"

Package apptest provides utilities for testing cli.App.


Package Files

apptest.go fake_tty.go


const (
    FakeTTYHeight = 20
    FakeTTYWidth  = 50

Initial size of fake TTY.


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.

func StartReadCode Uses

func StartReadCode(readCode func() (string, error)) (<-chan string, <-chan error)

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.

func WithSpec Uses

func WithSpec(f func(*cli.AppSpec)) func(*cli.AppSpec, TTYCtrl)

WithSpec takes a function that operates on *cli.AppSpec, and wraps it into a form suitable for passing to Setup.

func WithTTY Uses

func WithTTY(f func(TTYCtrl)) func(*cli.AppSpec, TTYCtrl)

WithTTY takes a function that operates on TTYCtrl, and wraps it to a form suitable for passing to Setup.

type Fixture Uses

type Fixture struct {
    App cli.App
    TTY TTYCtrl
    // contains filtered or unexported fields

Fixture is a test fixture.

func Setup Uses

func Setup(fns ...func(*cli.AppSpec, TTYCtrl)) *Fixture

Setup sets up a test fixture. It contains an App whose ReadCode method has been started asynchronously.

func (*Fixture) MakeBuffer Uses

func (f *Fixture) MakeBuffer(args ...interface{}) *term.Buffer

MakeBuffer is a helper for building a buffer. It is equivalent to term.NewBufferBuilder(width of terminal).MarkLines(args...).Buffer().

func (*Fixture) Stop Uses

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) TestTTY Uses

func (f *Fixture) TestTTY(t *testing.T, args ...interface{})

TestTTY is equivalent to f.TTY.TestBuffer(f.MakeBuffer(args...)).

func (*Fixture) TestTTYNotes Uses

func (f *Fixture) TestTTYNotes(t *testing.T, args ...interface{})

TestTTYNotes is equivalent to f.TTY.TestNotesBuffer(f.MakeBuffer(args...)).

func (*Fixture) Wait Uses

func (f *Fixture) Wait() (string, error)

Wait waits for ReaCode to finish, and returns its return values.

type TTYCtrl Uses

type TTYCtrl struct {
    // contains filtered or unexported fields

TTYCtrl is an interface for controlling a fake terminal.

func GetTTYCtrl Uses

func GetTTYCtrl(t cli.TTY) (TTYCtrl, bool)

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 Uses

func NewFakeTTY() (cli.TTY, TTYCtrl)

NewFakeTTY creates a new FakeTTY and a handle for controlling it. The initial size of the terminal is FakeTTYHeight and FakeTTYWidth.

func (TTYCtrl) Buffer Uses

func (t TTYCtrl) Buffer() *term.Buffer

Returns the last recorded buffer.

func (TTYCtrl) BufferHistory Uses

func (t TTYCtrl) BufferHistory() []*term.Buffer

BufferHistory returns a slice of all buffers that have appeared.

func (TTYCtrl) EventCh Uses

func (t TTYCtrl) EventCh() chan term.Event

EventCh returns the underlying channel for delivering events.

func (TTYCtrl) Inject Uses

func (t TTYCtrl) Inject(events ...term.Event)

Inject injects events to the fake terminal.

func (TTYCtrl) InjectSignal Uses

func (t TTYCtrl) InjectSignal(sigs ...os.Signal)

InjectSignal injects signals.

func (TTYCtrl) LastBuffer Uses

func (t TTYCtrl) LastBuffer() *term.Buffer

LastBuffer returns the last buffer that has appeared.

func (TTYCtrl) LastNotesBuffer Uses

func (t TTYCtrl) LastNotesBuffer() *term.Buffer

func (TTYCtrl) NotesBufferHistory Uses

func (t TTYCtrl) NotesBufferHistory() []*term.Buffer

NotesBufferHistory returns a slice of all notes buffers that have appeared.

func (TTYCtrl) NotifySignals Uses

func (t TTYCtrl) NotifySignals() <-chan os.Signal

func (TTYCtrl) RawInput Uses

func (t TTYCtrl) RawInput() int

RawInput returns the argument in the last call to the SetRawInput method of the TTY.

func (TTYCtrl) ReadEvent Uses

func (t TTYCtrl) ReadEvent() (term.Event, error)

Returns next event from t.eventCh.

func (TTYCtrl) ResetBuffer Uses

func (t TTYCtrl) ResetBuffer()

Records a nil buffer.

func (TTYCtrl) SetRawInput Uses

func (t TTYCtrl) SetRawInput(n int)

Records the argument.

func (TTYCtrl) SetSetup Uses

func (t TTYCtrl) SetSetup(restore func(), err error)

SetSetup sets the return values of the Setup method of the fake terminal.

func (TTYCtrl) SetSize Uses

func (t TTYCtrl) SetSize(h, w int)

SetSize sets the size of the fake terminal.

func (TTYCtrl) Setup Uses

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 Uses

func (t TTYCtrl) Size() (h, w int)

Returns the size specified by using the SetSize method of TTYCtrl.

func (TTYCtrl) StopInput Uses

func (t TTYCtrl) StopInput()

Closes eventCh.

func (TTYCtrl) StopSignals Uses

func (t TTYCtrl) StopSignals()

func (TTYCtrl) TestBuffer Uses

func (t TTYCtrl) TestBuffer(tt *testing.T, b *term.Buffer)

TestBuffer verifies that a buffer will appear within the timeout of 4 seconds, and fails the test if it doesn't

func (TTYCtrl) TestNotesBuffer Uses

func (t TTYCtrl) TestNotesBuffer(tt *testing.T, b *term.Buffer)

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 Uses

func (t TTYCtrl) UpdateBuffer(bufNotes, buf *term.Buffer, _ bool) error

UpdateBuffer records a new pair of buffers, i.e. sending them to their respective channels and appending them to their respective slices.

Package apptest imports 8 packages (graph). Updated 2020-02-22. Refresh now. Tools for package owners.