diff options
author | Neil Kistner <neil.kistner@gmail.com> | 2019-08-27 22:11:42 -0500 |
---|---|---|
committer | Kevin Song <chipbuster@users.noreply.github.com> | 2019-08-27 20:11:42 -0700 |
commit | 9853743eda935a25ddce18e32e97cca0192d9389 (patch) | |
tree | f0522e78ae1e8e7be5ad1770066d73f5fedbb3c4 /tests/testsuite/git_status.rs | |
parent | ed27cf4a2c56d9acb5e552a45f675e03bbc72286 (diff) |
feat: Add commit count for ahead/behind symbols (#247)
Add logic for the git status module to display the number of commits the index is ahead or behind next to the symbol.
Diffstat (limited to 'tests/testsuite/git_status.rs')
-rw-r--r-- | tests/testsuite/git_status.rs | 318 |
1 files changed, 318 insertions, 0 deletions
diff --git a/tests/testsuite/git_status.rs b/tests/testsuite/git_status.rs new file mode 100644 index 000000000..4fd213b0a --- /dev/null +++ b/tests/testsuite/git_status.rs @@ -0,0 +1,318 @@ +use ansi_term::Color; +use git2::Repository; +use std::env; +use std::fs::{self, File}; +use std::io; +use std::process::Command; + +use crate::common; + +fn create_fixture_repo() -> io::Result<std::path::PathBuf> { + let fixture_repo_dir = common::new_tempdir()?.path().join("fixture"); + let fixture = env::current_dir()?.join("tests/fixtures/rocket.bundle"); + + Command::new("git") + .args(&["config", "--global", "user.email", "starship@example.com"]) + .output()?; + + Command::new("git") + .args(&["config", "--global", "user.name", "starship"]) + .output()?; + + Command::new("git") + .args(&[ + "clone", + "-b", + "master", + &fixture.to_str().unwrap(), + fixture_repo_dir.to_str().unwrap(), + ]) + .output()?; + + Ok(fixture_repo_dir) +} + +#[test] +#[ignore] +fn shows_behind_count() -> io::Result<()> { + let fixture_repo_dir = create_fixture_repo()?; + let repo_dir = common::new_tempdir()?.path().join("rocket"); + + Repository::clone(fixture_repo_dir.to_str().unwrap(), &repo_dir.as_path()).unwrap(); + + Command::new("git") + .args(&["reset", "--hard", "HEAD^"]) + .current_dir(repo_dir.as_path()) + .output()?; + + let output = common::render_module("git_status") + .arg("--path") + .arg(repo_dir) + .output()?; + let actual = String::from_utf8(output.stdout).unwrap(); + let expected = Color::Red + .bold() + .paint(format!("[{}] ", "⇣1")) + .to_string(); + + assert_eq!(expected, actual); + + Ok(()) +} + +#[test] +#[ignore] +fn shows_ahead_count() -> io::Result<()> { + let fixture_repo_dir = create_fixture_repo()?; + let repo_dir = common::new_tempdir()?.path().join("rocket"); + + Repository::clone(fixture_repo_dir.to_str().unwrap(), &repo_dir.as_path()).unwrap(); + + File::create(repo_dir.join("readme.md"))?; + + Command::new("git") + .args(&["commit", "-am", "Update readme"]) + .current_dir(&repo_dir) + .output()?; + + let output = common::render_module("git_status") + .arg("--path") + .arg(repo_dir) + .output()?; + let actual = String::from_utf8(output.stdout).unwrap(); + let expected = Color::Red + .bold() + .paint(format!("[{}] ", "⇡1")) + .to_string(); + + assert_eq!(expected, actual); + + Ok(()) +} + +#[test] +#[ignore] +fn shows_diverged() -> io::Result<()> { + let fixture_repo_dir = create_fixture_repo()?; + let repo_dir = common::new_tempdir()?.path().join("rocket"); + + Repository::clone(fixture_repo_dir.to_str().unwrap(), &repo_dir.as_path()).unwrap(); + + Command::new("git") + .args(&["reset", "--hard", "HEAD^"]) + .current_dir(repo_dir.as_path()) + .output()?; + + fs::write(repo_dir.join("Cargo.toml"), " ")?; + + Command::new("git") + .args(&["commit", "-am", "Update readme"]) + .current_dir(repo_dir.as_path()) + .output()?; + + let output = common::render_module("git_status") + .arg("--path") + .arg(repo_dir) + .output()?; + let actual = String::from_utf8(output.stdout).unwrap(); + let expected = Color::Red + .bold() + .paint(format!("[{}] ", "⇕⇡1⇣1")) + .to_string(); + + assert_eq!(expected, actual); + + Ok(()) +} + +#[test] +#[ignore] +fn shows_conflicted() -> io::Result<()> { + let fixture_repo_dir = create_fixture_repo()?; + let repo_dir = common::new_tempdir()?.path().join("rocket"); + + Repository::clone(fixture_repo_dir.to_str().unwrap(), &repo_dir.as_path()).unwrap(); + + Command::new("git") + .args(&["reset", "--hard", "HEAD^"]) + .current_dir(repo_dir.as_path()) + .output()?; + + fs::write(repo_dir.join("readme.md"), "# goodbye")?; + + Command::new("git") + .args(&["add", "."]) + .current_dir(repo_dir.as_path()) + .output()?; + + Command::new("git") + .args(&["commit", "-m", "Change readme"]) + .current_dir(repo_dir.as_path()) + .output()?; + + Command::new("git") + .args(&["pull", "--rebase"]) + .current_dir(repo_dir.as_path()) + .output()?; + + let output = common::render_module("git_status") + .arg("--path") + .arg(repo_dir) + .output()?; + let actual = String::from_utf8(output.stdout).unwrap(); + let expected = Color::Red.bold().paint(format!("[{}] ", "=")).to_string(); + + assert_eq!(expected, actual); + + Ok(()) +} + +#[test] +#[ignore] +fn shows_untracked_file() -> io::Result<()> { + let fixture_repo_dir = create_fixture_repo()?; + let repo_dir = common::new_tempdir()?.path().join("rocket"); + + Repository::clone(fixture_repo_dir.to_str().unwrap(), &repo_dir.as_path()).unwrap(); + + File::create(repo_dir.join("license"))?; + + let output = common::render_module("git_status") + .arg("--path") + .arg(repo_dir) + .output()?; + let actual = String::from_utf8(output.stdout).unwrap(); + let expected = Color::Red.bold().paint(format!("[{}] ", "?")).to_string(); + + assert_eq!(expected, actual); + + Ok(()) +} + +#[test] +#[ignore] +fn shows_stashed() -> io::Result<()> { + let fixture_repo_dir = create_fixture_repo()?; + let repo_dir = common::new_tempdir()?.path().join("rocket"); + + Repository::clone(fixture_repo_dir.to_str().unwrap(), &repo_dir.as_path()).unwrap(); + + File::create(repo_dir.join("readme.md"))?; + + Command::new("git") + .arg("stash") + .current_dir(repo_dir.as_path()) + .output()?; + + let output = common::render_module("git_status") + .arg("--path") + .arg(repo_dir) + .output()?; + let actual = String::from_utf8(output.stdout).unwrap(); + let expected = Color::Red.bold().paint(format!("[{}] ", "$")).to_string(); + + assert_eq!(expected, actual); + + Ok(()) +} + +#[test] +#[ignore] +fn shows_modified() -> io::Result<()> { + let fixture_repo_dir = create_fixture_repo()?; + let repo_dir = common::new_tempdir()?.path().join("rocket"); + + Repository::clone(fixture_repo_dir.to_str().unwrap(), &repo_dir.as_path()).unwrap(); + + File::create(repo_dir.join("readme.md"))?; + + let output = common::render_module("git_status") + .arg("--path") + .arg(repo_dir) + .output()?; + let actual = String::from_utf8(output.stdout).unwrap(); + let expected = Color::Red.bold().paint(format!("[{}] ", "!")).to_string(); + + assert_eq!(expected, actual); + + Ok(()) +} + +#[test] +#[ignore] +fn shows_added_file() -> io::Result<()> { + let fixture_repo_dir = create_fixture_repo()?; + let repo_dir = common::new_tempdir()?.path().join("rocket"); + + Repository::clone(fixture_repo_dir.to_str().unwrap(), &repo_dir.as_path()).unwrap(); + + File::create(repo_dir.join("license"))?; + + Command::new("git") + .args(&["add", "."]) + .current_dir(repo_dir.as_path()) + .output()?; + + let output = common::render_module("git_status") + .arg("--path") + .arg(repo_dir) + .output()?; + let actual = String::from_utf8(output.stdout).unwrap(); + let expected = Color::Red.bold().paint(format!("[{}] ", "+")).to_string(); + + assert_eq!(expected, actual); + + Ok(()) +} + +#[test] +#[ignore] +fn shows_renamed_file() -> io::Result<()> { + let fixture_repo_dir = create_fixture_repo()?; + let repo_dir = common::new_tempdir()?.path().join("rocket"); + + Repository::clone(fixture_repo_dir.to_str().unwrap(), &repo_dir.as_path()).unwrap(); + + Command::new("git") + .args(&["mv", "readme.md", "readme.md.bak"]) + .current_dir(repo_dir.as_path()) + .output()?; + + Command::new("git") + .args(&["add", "-A"]) + .current_dir(repo_dir.as_path()) + .output()?; + + let output = common::render_module("git_status") + .arg("--path") + .arg(repo_dir) + .output()?; + let actual = String::from_utf8(output.stdout).unwrap(); + let expected = Color::Red.bold().paint(format!("[{}] ", "»")).to_string(); + + assert_eq!(expected, actual); + + Ok(()) +} + +#[test] +#[ignore] +fn shows_deleted_file() -> io::Result<()> { + let fixture_repo_dir = create_fixture_repo()?; + let repo_dir = common::new_tempdir()?.path().join("rocket"); + + Repository::clone(fixture_repo_dir.to_str().unwrap(), &repo_dir.as_path()).unwrap(); + + fs::remove_file(repo_dir.join("readme.md"))?; + + let output = common::render_module("git_status") + .arg("--path") + .arg(repo_dir) + .output()?; + let actual = String::from_utf8(output.stdout).unwrap(); + let expected = Color::Red.bold().paint(format!("[{}] ", "✘")).to_string(); + + assert_eq!(expected, actual); + + Ok(()) +} |