diff --git a/tests/testsuite/common.rs b/tests/testsuite/common.rs index 60da0e26..babe43a1 100644 --- a/tests/testsuite/common.rs +++ b/tests/testsuite/common.rs @@ -1,5 +1,6 @@ use lazy_static::lazy_static; use std::io::prelude::*; +use std::io::{Error, ErrorKind}; use std::path::{Path, PathBuf}; use std::process::Command; use std::{env, fs, io, process}; @@ -46,34 +47,38 @@ pub fn new_tempdir() -> io::Result { } /// 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 repo_dir = new_tempdir()?.path().join("rocket"); - let fixture = env::current_dir()?.join("tests/fixtures/rocket.bundle"); +pub fn create_fixture_repo() -> io::Result { + let fixture_repo_path = new_tempdir()?.path().join("fixture"); + let repo_path = new_tempdir()?.path().join("rocket"); + let fixture_path = env::current_dir()?.join("tests/fixtures/rocket.bundle"); + + let fixture_repo_dir = path_str(&fixture_repo_path)?; + let repo_dir = path_str(&repo_path)?; + let fixture = path_str(&fixture_path)?; Command::new("git") - .args(&[ - "clone", - "-b", - "master", - &fixture.to_str().unwrap(), - fixture_repo_dir.to_str().unwrap(), - ]) + .args(&["clone", "-b", "master", fixture, fixture_repo_dir]) .output()?; - git2::Repository::clone(fixture_repo_dir.to_str().unwrap(), &repo_dir.as_path()).unwrap(); + git2::Repository::clone(fixture_repo_dir, repo_dir).ok(); Command::new("git") .args(&["config", "--local", "user.email", "starship@example.com"]) - .current_dir(repo_dir.as_path()) + .current_dir(repo_dir) .output()?; Command::new("git") .args(&["config", "--local", "user.name", "starship"]) - .current_dir(repo_dir.as_path()) + .current_dir(repo_dir) .output()?; - Ok(repo_dir) + Ok(repo_path) +} + +fn path_str(repo_dir: &PathBuf) -> io::Result<&str> { + repo_dir + .to_str() + .ok_or_else(|| Error::from(ErrorKind::Other)) } /// Extends `std::process::Command` with methods for testing