check/
check.rs

1use expectrl::{check, spawn, Error};
2
3#[cfg(not(feature = "async"))]
4fn main() {
5    let mut session = spawn("python ./tests/source/ansi.py").expect("Can't spawn a session");
6
7    loop {
8        match check!(
9            &mut session,
10            _ = "Password: " => {
11                println!("Set password to SECURE_PASSWORD");
12                session.send_line("SECURE_PASSWORD").unwrap();
13            },
14            _ = "Continue [y/n]:" => {
15                println!("Stop processing");
16                session.send_line("n").unwrap();
17            },
18        ) {
19            Err(Error::Eof) => break,
20            result => result.unwrap(),
21        };
22    }
23}
24
25#[cfg(feature = "async")]
26fn main() {
27    futures_lite::future::block_on(async {
28        let mut session = spawn("python ./tests/source/ansi.py").expect("Can't spawn a session");
29
30        loop {
31            match check!(
32                &mut session,
33                _ = "Password: " => {
34                    println!("Set password to SECURE_PASSWORD");
35                    session.send_line("SECURE_PASSWORD").await.unwrap();
36                },
37                _ = "Continue [y/n]:" => {
38                    println!("Stop processing");
39                    session.send_line("n").await.unwrap();
40                },
41            )
42            .await
43            {
44                Err(Error::Eof) => break,
45                result => result.unwrap(),
46            };
47        }
48    })
49}