Documentation
¶
Overview ¶
Package programtest drives a program without opening a terminal.
Host implements only program.Host's transport boundary: ordered events in, frames out, and an opening cell size. Optional terminal capabilities are deliberately not present. A test that needs one can embed *Host in its own type and implement exactly that capability, so absence and partial support remain testable rather than being hidden by an all-powerful fake.
Frames are terminal escape streams, not a simulated screen. Shows and Hides request a full frame and inspect its appearance-free text runs: style and hyperlink changes are transparent, while cursor movement and erasure remain boundaries. Tests that need terminal cell state use package ptytest instead.
Index ¶
- type Config
- type Host
- func (h *Host) Close() error
- func (h *Host) Err() error
- func (h *Host) Events() <-chan input.Event
- func (h *Host) Frame() string
- func (h *Host) Frames() string
- func (h *Host) Hides(tb testing.TB, text string)
- func (h *Host) Input() program.EventSource
- func (h *Host) Press(code input.Code) bool
- func (h *Host) Repaint() bool
- func (h *Host) Resize(width, height int) bool
- func (h *Host) Send(event input.Event) bool
- func (h *Host) Shows(tb testing.TB, text string)
- func (h *Host) Size() (width, height int, err error)
- func (h *Host) Type(text string) bool
- func (h *Host) Until(tb testing.TB, what string, cond func() bool)
- func (h *Host) Writer() program.FrameWriter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶ added in v0.13.0
Config is the complete initial state of a test Host. Width and Height must be positive terminal-cell dimensions.
type Host ¶
type Host struct {
// contains filtered or unexported fields
}
Host is an in-memory program host for tests.
Every method is safe to call from the test goroutine while program.Run owns the program goroutine. New arranges cleanup; Close is also available when a test wants to settle the frame writer earlier. The zero Host is inert and refuses events. A Host must not be copied after first use: its event stream, frame writer and captured output are one test session.
func New ¶
New returns a host of the configured positive cell size.
t owns the host. Its cleanup closes the asynchronous frame writer after the test context has been cancelled, so a failed test cannot leave a goroutine behind.
func (*Host) Err ¶
Err reports a clean input end. Tests normally stop a program through their context or the program's own quit action.
func (*Host) Frame ¶
Frame returns the most recent frame write.
Ordinary frames are diffs. Call Repaint before an assertion that needs the whole screen, or use Shows and Hides, which do that automatically.
func (*Host) Hides ¶
Hides waits until no visible text run in a full repaint contains text. It uses the same appearance-free projection as Host.Shows.
func (*Host) Input ¶
func (h *Host) Input() program.EventSource
Input returns the host's clean-ending input stream.
func (*Host) Resize ¶
Resize changes the reported size and sends the corresponding event. Dimensions outside program.ValidateSize are rejected.
func (*Host) Send ¶
Send queues an event for the program and reports whether the host was open. It does not wait for the program to receive earlier events.
func (*Host) Shows ¶
Shows waits until one visible text run in a full repaint contains text. Appearance changes do not split a run; terminal geometry operations do. This is a content assertion rather than a raw escape-stream assertion — use Frame or Frames when exact transport bytes are the subject of the test.
func (*Host) Until ¶
Until waits for output activity until cond becomes true, failing the test with the last frame after a bounded wait.
cond must inspect concurrency-safe state: Host output methods are safe, as is application-owned state protected by its own synchronization. The wait is driven by frame writes rather than a polling sleep.
func (*Host) Writer ¶
func (h *Host) Writer() program.FrameWriter
Writer is where the program queues terminal frames.