1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
#![cfg(unix)]
use insta::assert_snapshot;
use zellij_integration_tests::{
claim_first_terminal_and_wait_for_prompt, col, keys, normalized, start_zellij, PROMPT,
TERMINAL_SIZE,
};
#[test]
fn override_layout_from_default_to_compact() {
let mut zellij = start_zellij();
claim_first_terminal_and_wait_for_prompt(&zellij);
zellij.override_layout("compact");
let grid_snapshot =
zellij.wait_until("compact bar rendered with session name", |grid_snapshot| {
grid_snapshot.contains("Zellij (test")
&& grid_snapshot.contains("NORMAL")
&& grid_snapshot.contains("Tab #1")
&& !grid_snapshot.status_bar_appears()
});
assert_snapshot!(normalized(&grid_snapshot));
zellij.quit();
}
#[test]
fn send_command_through_the_cli() {
let mut zellij = start_zellij();
claim_first_terminal_and_wait_for_prompt(&zellij);
zellij.run_suspended_command(&["suspended-command"]);
let command_terminal = zellij.expect_pty_spawn();
zellij.wait_until("suspended command pane waiting to run", |grid_snapshot| {
grid_snapshot.contains("<Ctrl-c>")
});
zellij.send_stdin(&keys::ENTER);
zellij.wait_until("command running", |grid_snapshot| {
!grid_snapshot.contains("<Ctrl-c>")
});
command_terminal.output(b"foo\r\n");
zellij.wait_until("first run printed foo", |grid_snapshot| {
grid_snapshot.contains("foo")
});
command_terminal.exit(Some(0));
zellij.wait_until("command pane held again after exit", |grid_snapshot| {
grid_snapshot.contains("EXIT CODE")
});
zellij.send_stdin(&keys::ENTER);
zellij.wait_until("command re-running", |grid_snapshot| {
!grid_snapshot.contains("EXIT CODE")
});
command_terminal.output(b"foo\r\nfoo\r\n");
let grid_snapshot = zellij.wait_until("command re-ran", |grid_snapshot| {
grid_snapshot.text.matches("foo").count() >= 2
});
assert_snapshot!(normalized(&grid_snapshot));
zellij.quit();
}
#[test]
fn send_blocking_command_through_the_cli() {
let mut zellij = start_zellij();
claim_first_terminal_and_wait_for_prompt(&zellij);
let blocking_command = zellij.run_blocking_floating_command(&["blocking-command"]);
let floating_terminal = zellij.expect_pty_spawn();
zellij.wait_until("floating command pane appeared", |grid_snapshot| {
grid_snapshot.contains("PIN")
});
floating_terminal.exit(Some(42));
assert_eq!(blocking_command.wait_for_exit(), 42);
let grid_snapshot = zellij.wait_until("floating pane closed on exit", |grid_snapshot| {
!grid_snapshot.contains("PIN") && grid_snapshot.cursor_is_at(col(2).row(1))
});
assert_snapshot!(normalized(&grid_snapshot));
zellij.quit();
}
#[test]
fn watcher_client_functionality() {
let mut zellij = start_zellij();
let first_terminal = claim_first_terminal_and_wait_for_prompt(&zellij);
first_terminal.output(b"\r\nWATCHER_OUTPUT_1\r\n");
zellij.wait_until("first output line", |grid_snapshot| {
grid_snapshot.contains("WATCHER_OUTPUT_1")
});
let watcher = zellij.attach_watcher(TERMINAL_SIZE);
watcher.wait_until("watcher connected and sees the output", |grid_snapshot| {
grid_snapshot.status_bar_appears() && grid_snapshot.contains("WATCHER_OUTPUT_1")
});
zellij.send_stdin(&keys::ctrl('p'));
zellij.send_stdin(&keys::key('r'));
let right_terminal = zellij.expect_pty_spawn();
right_terminal.output(PROMPT);
watcher.wait_until("watcher sees the split", |grid_snapshot| {
grid_snapshot.contains("│")
});
let ignored_new_tab_from_watcher = [keys::ctrl('t'), keys::key('n')].concat();
watcher.send_stdin(&ignored_new_tab_from_watcher);
zellij.detach_main_client();
first_terminal.output(b"WATCHER_OUTPUT_2\r\nWATCHER_OUTPUT_3\r\nWATCHER_DONE\r\n");
watcher.wait_until(
"watcher keeps receiving output while no main client is attached",
|grid_snapshot| {
grid_snapshot.contains("WATCHER_DONE")
&& grid_snapshot.contains("│")
&& !grid_snapshot.contains("Tab #2")
},
);
let main = zellij.attach_client(TERMINAL_SIZE);
let main_snapshot = main.wait_until(
"re-attached main converges on the same state",
|grid_snapshot| {
grid_snapshot.status_bar_appears()
&& grid_snapshot.contains("WATCHER_DONE")
&& grid_snapshot.contains("│")
},
);
assert_snapshot!(normalized(&main_snapshot));
let watcher_snapshot =
watcher.wait_until("watcher mirrors the re-attached session", |grid_snapshot| {
grid_snapshot.status_bar_appears()
&& grid_snapshot.contains("WATCHER_DONE")
&& grid_snapshot.contains("│")
&& !grid_snapshot.contains("Tab #2")
});
assert_snapshot!(normalized(&watcher_snapshot));
main.quit();
watcher.quit();
zellij.quit();
}
|