From dc314144fdd2ea4f86d7e951770b0763ea22be78 Mon Sep 17 00:00:00 2001 From: Justin Wernick Date: Fri, 24 Feb 2023 10:56:06 +0200 Subject: Exit --- tests/cli.rs | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) (limited to 'tests') 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> { 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> { + p.exp_string("> ")?; + Ok(()) +} + #[test] fn shows_a_prompt() -> Result<(), Box> { - let mut p = spawn_interactive_process()?; - p.exp_string("> ")?; + spawn_interactive_process()?; Ok(()) } #[test] fn does_nothing_after_receiving_whitespace_input() -> Result<(), Box> { 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> { + let mut p = spawn_interactive_process()?; + p.send_control('d')?; + p.exp_eof()?; + Ok(()) +} + +#[test] +fn quits_when_exit_command_is_sent() -> Result<(), Box> { + let mut p = spawn_interactive_process()?; + p.send_line("exit")?; + p.exp_eof()?; Ok(()) } -- cgit v1.2.3