use anyhow::Result; use assert_cmd::cargo::cargo_bin; use rexpect::{session::PtySession, spawn}; fn spawn_interactive_process() -> Result { let path = cargo_bin(env!("CARGO_PKG_NAME")); let mut process = spawn(&path.display().to_string(), Some(3000))?; expect_prompt(&mut process)?; Ok(process) } fn expect_prompt(p: &mut PtySession) -> Result<()> { p.exp_string("> ")?; Ok(()) } #[test] fn shows_a_prompt() -> Result<()> { spawn_interactive_process()?; Ok(()) } #[test] fn does_nothing_after_receiving_whitespace_input() -> Result<()> { let mut p = spawn_interactive_process()?; p.send_line("")?; expect_prompt(&mut p)?; p.send_line(" ")?; expect_prompt(&mut p)?; Ok(()) } #[test] fn quits_when_eof_is_sent() -> Result<()> { let mut p = spawn_interactive_process()?; p.send_control('d')?; p.exp_eof()?; Ok(()) } #[test] fn quits_when_exit_command_is_sent() -> Result<()> { let mut p = spawn_interactive_process()?; p.send_line("exit")?; p.exp_eof()?; Ok(()) }