diff options
author | Justin Wernick <justin@worthe-it.co.za> | 2023-02-24 10:56:06 +0200 |
---|---|---|
committer | Justin Wernick <justin@worthe-it.co.za> | 2023-02-24 10:56:06 +0200 |
commit | dc314144fdd2ea4f86d7e951770b0763ea22be78 (patch) | |
tree | f4a1df26ef21ea58d21688d39a556c47564faa23 /tests/cli.rs | |
parent | ff6025a26312dd2e098fb2d6e3920eecffdad217 (diff) |
Exit
Diffstat (limited to 'tests/cli.rs')
-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(()) } |