Documentation

Overview

    Package clitest provides utilities for testing cli.App.

    Index

    Constants

    View Source
    const (
    	FakeTTYHeight = 20
    	FakeTTYWidth  = 50
    )

      Initial size of fake TTY.

      Variables

        Styles defines a common stylesheet for unit tests.

        Functions

        func StartReadCode

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

          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

          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

            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.

              Types

              type Fixture

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

                Fixture is a test fixture.

                func Setup

                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

                  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

                    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

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

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

                        func (*Fixture) TestTTYNotes

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

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

                          func (*Fixture) Wait

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

                            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

                              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

                                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

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

                                    Returns the last recorded buffer.

                                    func (TTYCtrl) BufferHistory

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

                                      BufferHistory returns a slice of all buffers that have appeared.

                                      func (TTYCtrl) EventCh

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

                                        EventCh returns the underlying channel for delivering events.

                                        func (TTYCtrl) Inject

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

                                          Inject injects events to the fake terminal.

                                          func (TTYCtrl) InjectSignal

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

                                            InjectSignal injects signals.

                                            func (TTYCtrl) LastBuffer

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

                                              LastBuffer returns the last buffer that has appeared.

                                              func (TTYCtrl) LastNotesBuffer

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

                                              func (TTYCtrl) NotesBufferHistory

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

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

                                                func (TTYCtrl) NotifySignals

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

                                                func (TTYCtrl) RawInput

                                                func (t TTYCtrl) RawInput() int

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

                                                  func (TTYCtrl) ReadEvent

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

                                                    Returns next event from t.eventCh.

                                                    func (TTYCtrl) ResetBuffer

                                                    func (t TTYCtrl) ResetBuffer()

                                                      Records a nil buffer.

                                                      func (TTYCtrl) SetRawInput

                                                      func (t TTYCtrl) SetRawInput(n int)

                                                        Records the argument.

                                                        func (TTYCtrl) SetSetup

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

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

                                                          func (TTYCtrl) SetSize

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

                                                            SetSize sets the size of the fake terminal.

                                                            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) StopInput

                                                                func (t TTYCtrl) StopInput()

                                                                  Closes eventCh.

                                                                  func (TTYCtrl) StopSignals

                                                                  func (t TTYCtrl) StopSignals()

                                                                  func (TTYCtrl) TestBuffer

                                                                  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

                                                                    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

                                                                      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.