check/
check.rs

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