-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathrepl.rs
More file actions
38 lines (34 loc) · 1.23 KB
/
repl.rs
File metadata and controls
38 lines (34 loc) · 1.23 KB
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
//! An example how you would test your own repl
use rexpect::error::Error;
use rexpect::session::PtyReplSession;
use rexpect::spawn;
use std::time;
fn ed_session() -> Result<PtyReplSession, Error> {
let mut ed = PtyReplSession {
// for `echo_on` you need to figure that out by trial and error.
// For bash and python repl it is false
echo_on: false,
// used for `wait_for_prompt()`
prompt: "> ".to_owned(),
pty_session: spawn("/bin/ed -p '> '", Some(time::Duration::from_secs(2)))?,
// command which is sent when the instance of this struct is dropped
// in the below example this is not needed, but if you don't explicitly
// exit a REPL then rexpect tries to send a SIGTERM and depending on the repl
// this does not end the repl and would end up in an error
quit_command: Some("Q".to_owned()),
};
ed.wait_for_prompt()?;
Ok(ed)
}
fn main() -> Result<(), Error> {
let mut ed = ed_session()?;
ed.send_line("a")?;
ed.send_line("ed is the best editor evar")?;
ed.send_line(".")?;
ed.wait_for_prompt()?;
ed.send_line(",l")?;
ed.exp_string("ed is the best editor evar$")?;
ed.send_line("Q")?;
ed.exp_eof()?;
Ok(())
}