programtest

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 9, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

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

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

func New(tb testing.TB, width, height int) *Host

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

func (h *Host) Close() error

Close stops the frame writer. It is idempotent.

func (*Host) Err

func (h *Host) Err() error

Err reports a clean input end. Tests normally stop a program through their context or the program's own quit action.

func (*Host) Events

func (h *Host) Events() <-chan input.Event

Events is the ordered input channel.

func (*Host) Frame

func (h *Host) Frame() string

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

func (h *Host) Frames() string

Frames returns every byte written so far as a string.

func (*Host) Hides

func (h *Host) Hides(tb testing.TB, text string)

Hides waits until a full repaint does not contain text.

func (*Host) Input

func (h *Host) Input() program.EventSource

Input returns the host's clean-ending input stream.

func (*Host) Press

func (h *Host) Press(code input.Code) bool

Press sends a non-character key.

func (*Host) Repaint

func (h *Host) Repaint() bool

Repaint asks the program for a full frame at its current size.

func (*Host) Resize

func (h *Host) Resize(width, height int) bool

Resize changes the reported size and sends the corresponding event. Dimensions outside program.ValidateSize are rejected.

func (*Host) Send

func (h *Host) Send(event input.Event) bool

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

func (h *Host) Shows(tb testing.TB, text string)

Shows waits until a full repaint contains text.

func (*Host) Size

func (h *Host) Size() (width, height int, err error)

Size returns the opening size passed to New.

func (*Host) Type

func (h *Host) Type(text string) bool

Type sends text one character key at a time.

func (*Host) Until

func (h *Host) Until(tb testing.TB, what string, cond func() bool)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL