summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJustin Wernick <justin@worthe-it.co.za>2023-04-07 11:50:57 +0200
committerJustin Wernick <justin@worthe-it.co.za>2023-04-07 11:50:57 +0200
commit108fef99d19ade71013dc25562e3c3c3e23347ef (patch)
treefd2082991d11fdbfe00c4345c0daec49e070c999 /tests
parentd7ac6f915079c2385be902106f97b994f5f65bc5 (diff)
Failing test for setting description
Diffstat (limited to 'tests')
-rw-r--r--tests/cli.rs85
1 files changed, 65 insertions, 20 deletions
diff --git a/tests/cli.rs b/tests/cli.rs
index e64ce6b..dfbb915 100644
--- a/tests/cli.rs
+++ b/tests/cli.rs
@@ -225,15 +225,30 @@ fn allows_single_quotes_and_spaces_inside_double_quotes() -> Result<()> {
Ok(())
}
+const DEFAULT_DESCRIPTION: &str =
+ "Unnamed repository; edit this file 'description' to name the repository.";
+
+fn expect_list_table(c: &mut TestContext, repos: &[(String, String)]) -> Result<()> {
+ c.p.send_line("list")?;
+ c.p.exp_regex(r"\+-+\+-+\+")?;
+ c.p.exp_regex(r"\| path +\| description +\|")?;
+ c.p.exp_regex(r"\+=+\+")?;
+ for (path, description) in repos {
+ c.p.exp_string("| ")?;
+ c.p.exp_string(path)?;
+ c.p.exp_regex(r" +\| ")?;
+ c.p.exp_string(&description)?;
+ c.p.exp_regex(r" +\|")?;
+ }
+ c.p.exp_regex(r"\+-+\+-+\+")?;
+ expect_prompt(&mut c.p)?;
+ Ok(())
+}
+
#[test]
fn list_can_print_an_empty_list() -> Result<()> {
let mut c = spawn_interactive_process()?;
- c.p.send_line("list")?;
- c.p.exp_string("+------+-------------+")?;
- c.p.exp_string("| path | description |")?;
- c.p.exp_string("+====================+")?;
- c.p.exp_string("+------+-------------+")?;
- expect_prompt(&mut c.p)?;
+ expect_list_table(&mut c, &[])?;
Ok(())
}
@@ -245,13 +260,13 @@ fn list_can_print_a_list_of_personal_repos_with_descriptions() -> Result<()> {
let personal_repo_name = "my-personal-repo";
c.p.send_line(&format!("git-init {}", personal_repo_name))?;
- 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)?;
+ expect_list_table(
+ &mut c,
+ &[(
+ format!("git/{user}/{personal_repo_name}.git"),
+ DEFAULT_DESCRIPTION.to_owned(),
+ )],
+ )?;
Ok(())
}
@@ -267,13 +282,43 @@ fn list_can_print_a_list_of_all_repos_with_descriptions() -> Result<()> {
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_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"\+-+\+-+\+")?;
+ expect_list_table(
+ &mut c,
+ &[
+ (
+ format!("git/{user}/{personal_repo_name}.git"),
+ DEFAULT_DESCRIPTION.to_owned(),
+ ),
+ (
+ format!("git/{group}/{shared_repo_name}.git"),
+ DEFAULT_DESCRIPTION.to_owned(),
+ ),
+ ],
+ )?;
+
+ Ok(())
+}
+
+#[test]
+fn can_set_the_description_on_a_repo_during_init() -> Result<()> {
+ let mut c = spawn_interactive_process()?;
+ let user = get_username().unwrap();
+ let repo_name = "my-personal-repo";
+ let description = "A cool repo that does cool things";
+ c.p.send_line(&format!(
+ "git-init --description \"{description}\" {repo_name}"
+ ))?;
+ c.p.exp_string(&format!(
+ "Successfully created \"git/{user}/{repo_name}.git\"",
+ ))?;
+
+ expect_list_table(
+ &mut c,
+ &[(
+ format!("git/{user}/{repo_name}.git"),
+ description.to_owned(),
+ )],
+ )?;
Ok(())
}