libtmux
English
Reference MCP Search

Testing with libtmux

Edit this page on GitHub

None of the eight ports mocks tmux for its own test suite, and seven of the eight expose the fixture that does that to you, for testing your code against real tmux instead of a fake. The recurring guarantee, worded differently in every port, is the same one: a server your test owns, on a socket nothing else can collide with, gone by the time the test ends — even when the test crashes or the process is killed outright.

Each fixture below is the same shape — ask for it, get a running server on a socket nothing else can reach, and never write the teardown yourself. Python’s session fixture pulls in server automatically, so a test that only asks for a session still gets the isolation:

>>> def test_example(session: "Session") -> None:
... assert isinstance(session.name, str)
... assert session.name.startswith('libtmux_')
... window = session.new_window(window_name='new one')
... assert window.name == 'new one'

TmuxFixture is a package product of its own. Each call starts a server under /tmp/libtmux-swift-test/ with a bootstrap session already in it, and limits how many fixtures run concurrently so a big test suite can’t exhaust processes or pseudo-terminals — a rate limiter the fixture owns, not something a test author has to coordinate by hand. It drives a real tmux rather than mocking one; LIBTMUX_TMUX_BIN picks the executable, falling back to the usual installed locations. Source: Tests/TmuxFixture/README.md.

TypeScript is the one port without a published fixture: the library’s own real-tmux harness (packages/libtmux/src/_internal/test/testkit.ts) is “internal and unpublished — in-repo consumers use it directly; external ones have no need for it,” and there is no @libtmux/testing package as of this page. A project needing one is building its own thin wrapper around a real Server, the same way this guide’s other examples do.

Where to go nextLink to section

  • Capturing output — the wait helpers most of these fixtures are meant to be used alongside, instead of a fixed sleep in a test.
  • Attach and send keys and Capture pane output — the same operations these fixtures give you a server to run, shown as tested examples in their own right.
Esc

Type to search.