From 6268956e826b477a2f6fecde7d1ab701fffb1f58 Mon Sep 17 00:00:00 2001 From: Justin Wernick Date: Sun, 12 Mar 2023 10:52:52 +0200 Subject: Test for batch command --- tests/cli.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'tests') diff --git a/tests/cli.rs b/tests/cli.rs index 01e8f2b..fcd1437 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -19,6 +19,18 @@ fn spawn_interactive_process() -> Result { Ok(TestContext { p, workdir }) } +fn run_batch_command(batch_command: &str) -> Result { + let workdir = tempfile::tempdir()?; + + let path = cargo_bin(env!("CARGO_PKG_NAME")); + let mut command = std::process::Command::new(&path); + command.current_dir(&workdir); + command.args(["-c", batch_command]); + let p = spawn_command(command, Some(3000))?; + + Ok(TestContext { p, workdir }) +} + fn expect_prompt(p: &mut PtySession) -> Result<()> { p.exp_string("> ")?; Ok(()) @@ -90,3 +102,11 @@ fn can_init_a_new_git_repo() -> Result<()> { .stdout(""); Ok(()) } + +#[test] +fn runs_a_single_command_and_exit_with_cli_flag() -> Result<()> { + let mut c = run_batch_command("git-init another-new-repo")?; + c.p.exp_string("Successfully created my-new-repo.git")?; + c.p.exp_eof()?; + Ok(()) +} -- cgit v1.2.3