blob: 31892525dea8a126bce802b8c4bc0a5f774425ae (
plain)
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
|
use super::*;
use nix::{pty::openpty, unistd::close};
struct TestTerminal {
openpty: OpenptyResult,
}
impl TestTerminal {
pub fn new() -> TestTerminal {
let openpty = openpty(None, None).expect("Could not create openpty");
TestTerminal { openpty }
}
#[allow(dead_code)]
pub fn master(&self) -> RawFd {
self.openpty.master
}
pub fn slave(&self) -> RawFd {
self.openpty.slave
}
}
impl Drop for TestTerminal {
fn drop(&mut self) {
close(self.openpty.master).expect("Failed to close the master");
close(self.openpty.slave).expect("Failed to close the slave");
}
}
#[test]
fn get_cwd() {
let test_terminal = TestTerminal::new();
let test_termios =
termios::tcgetattr(test_terminal.slave()).expect("Could not configure the termios");
let server = ServerOsInputOutput {
orig_termios: Arc::new(Mutex::new(Some(test_termios))),
client_senders: Arc::default(),
terminal_id_to_raw_fd: Arc::default(),
cached_resizes: Arc::default(),
};
let pid = nix::unistd::getpid();
assert!(
server.get_cwd(pid).is_some(),
"Get current working directory from PID {}",
pid
);
}
|