Documentation
¶
Overview ¶
Package flatest is a deterministic, synchronous test harness for flat apps: it drives an App through scripted events and controlled time, exercising real async folds without goroutine races, real clocks, or a terminal.
Index ¶
- func AssertFrames(t *testing.T, path string, frames []flatte.Frame)
- func AssertGolden(t *testing.T, path string, frame string)
- func AssertGoldenFrame(t *testing.T, path string, frame flatte.Frame)
- func CleanFrame(frame string) string
- func Frames[S any](d *Driver[S], steps ...func(*Driver[S])) []flatte.Frame
- func NewHarnessEffects[S any](ctx context.Context, updates chan<- flatte.StateUpdate[S], quit func(), ...) flatte.Effects[S]
- func NewHarnessEffectsQueue[S any](ctx context.Context, enqueue func(flatte.StateUpdate[S]) bool, quit func(), ...) flatte.Effects[S]
- func RenderFrame(frame flatte.Frame) string
- type Driver
- func (d *Driver[S]) Advance(by time.Duration) flatte.Frame
- func (d *Driver[S]) Answer(r flatte.DialogResult) flatte.Frame
- func (d *Driver[S]) Close()
- func (d *Driver[S]) Dialog() (dialog flatte.Dialog, ok bool)
- func (d *Driver[S]) Frame() flatte.Frame
- func (d *Driver[S]) Notifications() []flatte.Notification
- func (d *Driver[S]) Quit() bool
- func (d *Driver[S]) Resize(width, height int) flatte.Frame
- func (d *Driver[S]) Send(ev flatte.Event) flatte.Frame
- func (d *Driver[S]) Settle() flatte.Frame
- func (d *Driver[S]) State() *S
- func (d *Driver[S]) WindowFrame(id string) (frame flatte.Frame, ok bool)
- type Options
- type Recorder
- type Step
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertFrames ¶
AssertFrames compares a frame sequence against a golden: each frame RenderFrame'd, joined by a separator line, so an interaction can be regression-tested as an ordered series of frames.
func AssertGoldenFrame ¶
AssertGoldenFrame compares a Frame against a golden: cleaned content, then metadata footer lines — only when metadata is set, so frames without cursor or title keep their existing goldens byte-identical.
func CleanFrame ¶
func Frames ¶
Frames runs the driver through a sequence of steps and returns the frame after each, for sequence goldens (see AssertFrames).
func NewHarnessEffects ¶ added in v0.2.0
func NewHarnessEffects[S any](ctx context.Context, updates chan<- flatte.StateUpdate[S], quit func(), dispatch func(func()), clock flatte.Clock) flatte.Effects[S]
NewHarnessEffects builds an Effects value for callback-level tests that need to pass Effects directly to Handle or observe named updates. Prefer Start when a test should exercise the complete app loop.
func NewHarnessEffectsQueue ¶ added in v0.2.0
func NewHarnessEffectsQueue[S any](ctx context.Context, enqueue func(flatte.StateUpdate[S]) bool, quit func(), dispatch func(func()), clock flatte.Clock) flatte.Effects[S]
NewHarnessEffectsQueue is NewHarnessEffects with a caller-owned update queue, useful when tests must avoid blocking on channel capacity.
func RenderFrame ¶
RenderFrame serializes a frame for golden comparison.
Types ¶
type Driver ¶
type Driver[S any] struct { // contains filtered or unexported fields }
Driver runs a flatte.App synchronously for tests. App-triggered async (Go/Latest/Stream) is deferred to a pending queue and only runs on Settle; time-based effects (Every) are driven by a fake clock advanced with Advance. The width is fixed so frames are deterministic.
func Start ¶
Start builds a Driver, runs Init, delivers the initial ResizeEvent, and renders the first frame.
func StartWith ¶ added in v0.2.0
StartWith builds a Driver with an explicit size and host render context.
func (*Driver[S]) Advance ¶
Advance moves the fake clock, firing due Every ticks (which queue updates), then settles any async those ticks triggered.
func (*Driver[S]) Answer ¶ added in v0.2.0
func (d *Driver[S]) Answer(r flatte.DialogResult) flatte.Frame
Answer answers the oldest open dialog as the user would — the chosen paths (none: cancelled) or button (-1: dismissed) — applies the app's fold, and returns the rendered frame. It panics when no dialog is open.
func (*Driver[S]) Close ¶
func (d *Driver[S]) Close()
Close calls the app's OnExit hook, mirroring what Run does on loop exit. Call it at the end of a test to verify state-save callbacks.
func (*Driver[S]) Dialog ¶ added in v0.2.0
Dialog is the oldest dialog the app asked for (OpenFile, SaveFile, Alert) that the test has not answered; ok is false when there is none. The driver draws no dialogs: tests answer them with Answer.
func (*Driver[S]) Frame ¶
Frame renders the current state through the same settled cell-frame rules as Send, Resize, and Run.
func (*Driver[S]) Notifications ¶ added in v0.2.0
func (d *Driver[S]) Notifications() []flatte.Notification
Notifications are the notifications the app posted with Notify, oldest first. The driver shows none; tests read them here.
func (*Driver[S]) Resize ¶ added in v0.2.0
Resize updates dimensions used by Handle, View, and root layout composition.
func (*Driver[S]) Send ¶
Send delivers one event, drains the synchronous updates it produced, and returns the rendered frame. Async results triggered by the event are NOT applied here — call Settle.
func (*Driver[S]) Settle ¶
Settle runs every pending async body (to fixpoint — a body may dispatch more) and drains the updates each produces, then renders. This is where Go/Latest/Stream results land, under test control. drain runs after each body so Latest's apply-time guard sees a superseded ctx and drops the stale result.
func (*Driver[S]) State ¶
func (d *Driver[S]) State() *S
State exposes the live state for field assertions.
func (*Driver[S]) WindowFrame ¶ added in v0.2.0
WindowFrame is secondary window id's own frame as last rendered (composed at its size, without the box the terminal draws around it); ok is false when the app does not declare it. Mouse events for it are sent in screen cells, as a terminal reports them: over its box in Frame.
type Options ¶ added in v0.2.0
type Options struct {
Width, Height int
Graphical bool
Capabilities flatte.Capabilities
}
Options configures the deterministic render context of a Driver.
type Recorder ¶
type Recorder struct {
Steps []Step
}
Recorder is a flatte.Tracer that captures the ordered event/update stream of a session for replay assertions. Use it as App.Tracer.
func Replay ¶
Replay re-drives the recorded EVENTS through a fresh Driver — settling after each so any async those events trigger lands — and returns the new recording. A test asserts the two update-name streams match: a regression lock on event→update determinism.
Limitations (honest): updates are closures and are not serialized, so only their names are compared. Settle/Advance cadence is NOT captured, so a session that batches several events before settling (e.g. a Latest supersede) will not reproduce identically under per-event settling — drive those with the Driver directly. ResizeEvents and LayoutEvents are skipped: the fresh Driver delivers its own initial resize at the fixed width and settles its own layout, exactly as the recorded session did.