#![cfg(feature = "blocking")]
use std::process::Command;
use std::time::Duration;
use tmuxctl::{Client, Notification, SpawnOpts};
fn tmux_bin() -> String {
std::env::var("TMUXCTL_TMUX_BIN").unwrap_or_else(|_| "tmux".to_string())
}
fn opts(socket: &str) -> SpawnOpts {
SpawnOpts::new()
.program(tmux_bin())
.socket(socket)
.session("it")
}
fn kill_server(socket: &str) {
let _ = Command::new(tmux_bin())
.args(["-L", socket, "kill-server"])
.status();
}
#[test]
#[ignore = "spawns real tmux; run via scripts/integration.sh"]
fn command_round_trip() {
let socket = format!("tmuxctl-it-rt-{}", std::process::id());
let client = Client::spawn(opts(&socket)).expect("spawn tmux -C");
let windows = client
.command("list-windows -F '#{window_id}'")
.expect("list-windows succeeds");
assert!(!windows.lines.is_empty(), "expected at least one window");
assert!(
windows.lines[0].starts_with('@'),
"expected a window id, got {:?}",
windows.lines
);
assert!(
client.command("this-is-not-a-tmux-command").is_err(),
"a bogus command should be Err"
);
drop(client);
kill_server(&socket);
}
#[test]
#[ignore = "spawns real tmux; run via scripts/integration.sh"]
fn new_window_emits_notification() {
let socket = format!("tmuxctl-it-win-{}", std::process::id());
let mut client = Client::spawn(opts(&socket)).expect("spawn tmux -C");
let events = client.events().expect("events receiver");
client.command("new-window").expect("new-window succeeds");
let mut saw_window_add = false;
while let Ok(notification) = events.recv_timeout(Duration::from_secs(2)) {
if matches!(notification, Notification::WindowAdd(_)) {
saw_window_add = true;
break;
}
}
assert!(saw_window_add, "expected a %window-add notification");
drop(client);
kill_server(&socket);
}