FakeTmux
A tmux server that is not there, for testing code that uses this library without starting one.
Source and package
- Qualified name
-
io.github .libtmux .junit5. Fake Tmux - Package
- io.github.libtmux.junit5
- Distribution
- io.github.libtmux:libtmux
- Source
- libtmux-junit5/src/main/java/io/github/libtmux/junit5/FakeTmux.java
-
Description#
It answers the way tmux answers, not the way a stub would: a listing is rendered from the template the library sends, so a snapshot of a fake server is a real snapshot and every handle works; a handle command is fenced on the server's identity and refused once the fake is replaced, as tmux refuses it; a group stops at its first failure. What it models is the hierarchy — sessions, windows, panes and their names and titles — and what each pane shows. What it does not model is a shell: keys sent to a pane are recorded, not run, and a pane shows what the test says.
For behaviour that depends on tmux itself — what a release does with a flag, how a real shell echoes — test against real tmux with
TmuxExtensioninstead. This is for code whose interest in tmux ends at the calls it makes.Examples#
FakeTmux tmux = new FakeTmux();PaneId editor = tmux.addSession("work");tmux.show(editor, "$ make", "make: Nothing to be done for 'all'.");try (Server server = tmux.server()) {Pane pane = server.pane(editor).orElseThrow();pane.capture(); // → [$ make, make: Nothing to be done for 'all'.]pane.sendLine("make test");}tmux.sent(); // every command, as the library sent it
Members12#
Collections and queries1#
- sessions method The sessions the fake holds now, by id.
Other members11#
- addSession method Adds a session with one window and one pane running
sh, asnew-sessionmakes. - close method
- controlCarrier method Control clients of this fake:
server.control(session)attaches one, its commands are answered as this fake answers any other, and it hears what#output()and#notify()push. A restart ends every client attached, as a server that went away does. - execute method
- FakeTmux method A fake server with no sessions, as tmux is before anything has been created.
- notify method Pushes a notification line, such as
%window-renamed @1 logs, to every attached client. - output method Pushes what a pane wrote to every attached control client, as tmux's
%output: a control byte or a backslash as three octal digits, and the rest as it is. - restart method Replaces the server, as a restart does: a new process, and nothing in it.
- sent method Every command the library sent, in order, each as the words tmux would have read.
- server method A server this transport answers for.
- show method What the pane shows, one element per line, which is what capturing it answers.