forked from rust-cli/rexpect
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrepl.rs
More file actions
32 lines (29 loc) · 1.11 KB
/
repl.rs
File metadata and controls
32 lines (29 loc) · 1.11 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
//! An example how you would test your own repl
use rexpect::error::Error;
use rexpect::session::PtyReplSession;
use rexpect::spawn;
fn ed_session() -> Result<PtyReplSession, Error> {
let mut ed = PtyReplSession::new(spawn("/bin/ed -p '> '", Some(2000))?, "> ".to_owned())
// for `echo_on` you need to figure that out by trial and error.
// For bash and python repl it is false
.echo_on(false)
// 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(())
}