From 7475e89080d292cf995f805b3ca3e6dca11b8810 Mon Sep 17 00:00:00 2001 From: Justin Wernick Date: Tue, 4 Apr 2023 21:03:46 +0200 Subject: Figure out the testing for listing Needs regexes to accomodate the different table sizes --- tests/cli.rs | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/tests/cli.rs b/tests/cli.rs index 648b6c1..e64ce6b 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -140,7 +140,7 @@ fn can_init_a_new_git_repo() -> Result<()> { #[test] fn can_init_a_new_shared_git_repo() -> Result<()> { let mut c = spawn_interactive_process()?; - let group = get_user_groups().pop().unwrap(); + let group = get_user_groups().into_iter().next().unwrap(); let repo_name = "my-new-shared-repo"; c.p.send_line(&format!("git-init --group {} {}", group, repo_name))?; c.p.exp_string(&format!( @@ -239,23 +239,41 @@ fn list_can_print_an_empty_list() -> Result<()> { } #[test] -fn list_can_print_an_list_of_all_repos_with_descriptions() -> Result<()> { +fn list_can_print_a_list_of_personal_repos_with_descriptions() -> Result<()> { let mut c = spawn_interactive_process()?; + let user = get_username().unwrap(); let personal_repo_name = "my-personal-repo"; c.p.send_line(&format!("git-init {}", personal_repo_name))?; - let group = get_user_groups().pop().unwrap(); + c.p.send_line("list")?; + c.p.exp_regex(r"\+-+\+-+\+")?; + c.p.exp_regex(r"\| path +\| description +\|")?; + c.p.exp_regex(r"\+=+\+")?; + c.p.exp_regex(&format!(r"\| git/{user}/{personal_repo_name}\.git +\| Unnamed repository; edit this file 'description' to name the repository\. +\|"))?; + c.p.exp_regex(r"\+-+\+-+\+")?; + expect_prompt(&mut c.p)?; + + Ok(()) +} + +#[test] +fn list_can_print_a_list_of_all_repos_with_descriptions() -> Result<()> { + let mut c = spawn_interactive_process()?; + let user = get_username().unwrap(); + let personal_repo_name = "my-personal-repo"; + c.p.send_line(&format!("git-init {}", personal_repo_name))?; + + let group = get_user_groups().into_iter().next().unwrap(); let shared_repo_name = "my-shared-repo"; c.p.send_line(&format!("git-init --group {} {}", group, shared_repo_name))?; c.p.send_line("list")?; - c.p.exp_string("+------+-------------+")?; - c.p.exp_string("| path | description |")?; - c.p.exp_string("+====================+")?; - c.p.exp_string("| git/shukkie/my-personal-repo | |+")?; - c.p.exp_string(&format!("| git/{group}/{shared_repo_name} | |+"))?; - c.p.exp_string("+------+-------------+")?; - expect_prompt(&mut c.p)?; + c.p.exp_regex(r"\+-+\+-+\+")?; + c.p.exp_regex(r"| path +| description +|")?; + c.p.exp_regex(r"\+=+\+")?; + c.p.exp_regex(&format!(r"\| git/{user}/{personal_repo_name}\.git +\| Unnamed repository; edit this file 'description' to name the repository\. +\|"))?; + c.p.exp_regex(&format!(r"\| git/{group}/{shared_repo_name}\.git +\| Unnamed repository; edit this file 'description' to name the repository\. +\|"))?; + c.p.exp_regex(r"\+-+\+-+\+")?; Ok(()) } -- cgit v1.2.3