aboutsummaryrefslogtreecommitdiffstats
path: root/tests/multiple.rs
blob: 7e275123c6344ece558f8444d1f43240b589a946 (plain) (blame)
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
#[test]
fn test_multiple() {
    use std::io::Read as _;

    let mut pty = pty_process::blocking::Pty::new().unwrap();
    pty.resize(pty_process::Size::new(24, 80)).unwrap();

    let mut child = pty_process::blocking::Command::new("echo")
        .arg("foo")
        .spawn(&pty)
        .unwrap();
    let mut buf = [0u8; 1024];
    let bytes = pty.read(&mut buf).unwrap();
    assert_eq!(&buf[..bytes], b"foo\r\n");
    let status = child.wait().unwrap();
    assert_eq!(status.code().unwrap(), 0);

    let mut child = pty_process::blocking::Command::new("echo")
        .arg("bar")
        .spawn(&pty)
        .unwrap();
    let mut buf = [0u8; 1024];
    let bytes = pty.read(&mut buf).unwrap();
    assert_eq!(&buf[..bytes], b"bar\r\n");
    let status = child.wait().unwrap();
    assert_eq!(status.code().unwrap(), 0);
}

#[cfg(feature = "async")]
#[test]
fn test_multiple_async() {
    use async_std::io::ReadExt as _;

    async_std::task::block_on(async {
        let mut pty = pty_process::Pty::new().unwrap();
        pty.resize(pty_process::Size::new(24, 80)).unwrap();

        let mut child = pty_process::Command::new("echo")
            .arg("foo")
            .spawn(&pty)
            .unwrap();
        let mut buf = [0u8; 1024];
        let bytes = pty.read(&mut buf).await.unwrap();
        assert_eq!(&buf[..bytes], b"foo\r\n");
        let status = child.status().await.unwrap();
        assert_eq!(status.code().unwrap(), 0);

        let mut child = pty_process::Command::new("echo")
            .arg("bar")
            .spawn(&pty)
            .unwrap();
        let mut buf = [0u8; 1024];
        let bytes = pty.read(&mut buf).await.unwrap();
        assert_eq!(&buf[..bytes], b"bar\r\n");
        let status = child.status().await.unwrap();
        assert_eq!(status.code().unwrap(), 0);
    });
}