diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/cli.rs | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/tests/cli.rs b/tests/cli.rs index a4d368f..ccf837b 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -4,22 +4,44 @@ use std::error::Error; fn spawn_interactive_process() -> Result<PtySession, Box<dyn Error>> { let path = cargo_bin(env!("CARGO_PKG_NAME")); - let process = spawn(&path.display().to_string(), Some(3000))?; + let mut process = spawn(&path.display().to_string(), Some(3000))?; + expect_prompt(&mut process)?; Ok(process) } +fn expect_prompt(p: &mut PtySession) -> Result<(), Box<dyn Error>> { + p.exp_string("> ")?; + Ok(()) +} + #[test] fn shows_a_prompt() -> Result<(), Box<dyn Error>> { - let mut p = spawn_interactive_process()?; - p.exp_string("> ")?; + spawn_interactive_process()?; Ok(()) } #[test] fn does_nothing_after_receiving_whitespace_input() -> Result<(), Box<dyn Error>> { let mut p = spawn_interactive_process()?; - p.exp_string("> ")?; p.send_line("")?; - p.exp_string("> ")?; + expect_prompt(&mut p)?; + p.send_line(" ")?; + expect_prompt(&mut p)?; + Ok(()) +} + +#[test] +fn quits_when_eof_is_sent() -> Result<(), Box<dyn Error>> { + let mut p = spawn_interactive_process()?; + p.send_control('d')?; + p.exp_eof()?; + Ok(()) +} + +#[test] +fn quits_when_exit_command_is_sent() -> Result<(), Box<dyn Error>> { + let mut p = spawn_interactive_process()?; + p.send_line("exit")?; + p.exp_eof()?; Ok(()) } |