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. Repaint requests a full frame before an assertion, which keeps this package small and keeps renderer tests honest about the bytes a host actually receives.
Index ¶
- 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 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.
func New ¶
New returns a host of the given 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) 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) 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.