tui-testing
tui-testing
How to write and run unit tests for Warp's headless TUI front-end (crates/warp_tui and the element library at crates/warpui_core/src/elements/tui). This complements rust-unit-tests (general Rust test conventions) and parallels gui-integration-test for the TUI.
TUI tests are plain, fast unit tests: they render an element tree to a fixed cell grid and assert on the resulting text lines. They do not use the GUI real-display / integration / computer-use framework (that's gui-integration-test / gui-integration-test-video, which are GUI-only).
Two test locations, two harnesses
TUI tests live in two crates, and which render helper you use depends on where the test is:
Element-library tests (in warpui_core)
Tests for the shared cell-grid elements live in crates/warpui_core/src/elements/tui/*_tests.rs and use the crate-internal test_support helpers from crates/warpui_core/src/elements/tui/mod.rs:
test_support::render_to_lines(element: &dyn TuiElement, size: TuiSize) -> Vec<String>— one-call harness: buildsarea = TuiRect::new(0, 0, size.width, size.height)andTuiBuffer::empty(area), callselement.render(area, &mut buffer, ctx)inside a paint context, and returnsbuffer.to_lines(). It only callsrender, notlayout— fine for a leaf likeTuiText, but composite elements (e.g.TuiFlex) populate child sizes duringlayout, so lay the element out first (see thelayout_athelper inflex_tests.rs) or it renders empty/stale.test_support::with_paint_context(|ctx| ...)— runs a closure with aTuiPaintContextover a fresh, empty view map. Use it when you need theTuiBufferafterward to assert on individualCells.
These helpers are pub(crate) to warpui_core, so they are only callable from that crate's own tests. Simplest leaf assertion (see text_tests.rs, flex_tests.rs):