diff --git a/tests/testsuite/common.rs b/tests/testsuite/common.rs index a2bc10f1..0f611a20 100644 --- a/tests/testsuite/common.rs +++ b/tests/testsuite/common.rs @@ -1,7 +1,8 @@ use lazy_static::lazy_static; use std::io::prelude::*; use std::path::{Path, PathBuf}; -use std::{io, process}; +use std::process::Command; +use std::{env, io, process}; lazy_static! { static ref MANIFEST_DIR: &'static Path = Path::new(env!("CARGO_MANIFEST_DIR")); @@ -43,6 +44,32 @@ pub fn new_tempdir() -> io::Result { tempfile::tempdir_in("/tmp") } +/// Create a repo from the fixture to be used in git module tests +pub fn create_fixture_repo() -> io::Result { + let fixture_repo_dir = 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) +} + /// Extends `std::process::Command` with methods for testing pub trait TestCommand { fn use_config(&mut self, toml: toml::value::Value) -> &mut process::Command; diff --git a/tests/testsuite/git_branch.rs b/tests/testsuite/git_branch.rs index 16d889b4..c1cd3101 100644 --- a/tests/testsuite/git_branch.rs +++ b/tests/testsuite/git_branch.rs @@ -106,7 +106,7 @@ fn test_truncate_length_with_config( truncation_symbol: &str, config_options: &str, ) -> io::Result<()> { - let fixture_repo_dir = create_fixture_repo()?; + let fixture_repo_dir = common::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(); @@ -141,28 +141,3 @@ fn test_truncate_length_with_config( assert_eq!(expected, actual); Ok(()) } - -fn create_fixture_repo() -> io::Result { - 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) -} diff --git a/tests/testsuite/git_status.rs b/tests/testsuite/git_status.rs index 510d1baa..00866247 100644 --- a/tests/testsuite/git_status.rs +++ b/tests/testsuite/git_status.rs @@ -7,35 +7,10 @@ use std::process::Command; use crate::common; -fn create_fixture_repo() -> io::Result { - 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 fixture_repo_dir = common::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(); @@ -63,7 +38,7 @@ fn shows_behind_count() -> io::Result<()> { #[test] #[ignore] fn shows_ahead_count() -> io::Result<()> { - let fixture_repo_dir = create_fixture_repo()?; + let fixture_repo_dir = common::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(); @@ -93,7 +68,7 @@ fn shows_ahead_count() -> io::Result<()> { #[test] #[ignore] fn shows_diverged() -> io::Result<()> { - let fixture_repo_dir = create_fixture_repo()?; + let fixture_repo_dir = common::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(); @@ -128,7 +103,7 @@ fn shows_diverged() -> io::Result<()> { #[test] #[ignore] fn shows_conflicted() -> io::Result<()> { - let fixture_repo_dir = create_fixture_repo()?; + let fixture_repo_dir = common::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(); @@ -170,7 +145,7 @@ fn shows_conflicted() -> io::Result<()> { #[test] #[ignore] fn shows_untracked_file() -> io::Result<()> { - let fixture_repo_dir = create_fixture_repo()?; + let fixture_repo_dir = common::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(); @@ -192,7 +167,7 @@ fn shows_untracked_file() -> io::Result<()> { #[test] #[ignore] fn doesnt_show_untracked_file_if_disabled() -> io::Result<()> { - let fixture_repo_dir = create_fixture_repo()?; + let fixture_repo_dir = common::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(); @@ -219,7 +194,7 @@ fn doesnt_show_untracked_file_if_disabled() -> io::Result<()> { #[test] #[ignore] fn shows_stashed() -> io::Result<()> { - let fixture_repo_dir = create_fixture_repo()?; + let fixture_repo_dir = common::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(); @@ -246,7 +221,7 @@ fn shows_stashed() -> io::Result<()> { #[test] #[ignore] fn shows_modified() -> io::Result<()> { - let fixture_repo_dir = create_fixture_repo()?; + let fixture_repo_dir = common::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(); @@ -268,7 +243,7 @@ fn shows_modified() -> io::Result<()> { #[test] #[ignore] fn shows_staged_file() -> io::Result<()> { - let fixture_repo_dir = create_fixture_repo()?; + let fixture_repo_dir = common::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(); @@ -295,7 +270,7 @@ fn shows_staged_file() -> io::Result<()> { #[test] #[ignore] fn shows_renamed_file() -> io::Result<()> { - let fixture_repo_dir = create_fixture_repo()?; + let fixture_repo_dir = common::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(); @@ -325,7 +300,7 @@ fn shows_renamed_file() -> io::Result<()> { #[test] #[ignore] fn shows_deleted_file() -> io::Result<()> { - let fixture_repo_dir = create_fixture_repo()?; + let fixture_repo_dir = common::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();