Skip to content

Commit

Permalink
fix tests on windows (#331)
Browse files Browse the repository at this point in the history
They need double-backslashes due to the escaping logic in git-config
files. They aren't particularly friendly to windows, which seems
like a fair trade-off.
  • Loading branch information
Byron committed Jul 11, 2022
1 parent f911707 commit 3d7fc18
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
7 changes: 4 additions & 3 deletions git-config/tests/file/from_env/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::{borrow::Cow, env, fs};

use crate::file::from_paths::escape_backslashes;
use git_config::{
file::{from_env, from_paths, from_paths::Options},
File,
Expand Down Expand Up @@ -131,11 +132,11 @@ fn follow_include_paths() {
.set("GIT_CONFIG_KEY_0", "core.key")
.set("GIT_CONFIG_VALUE_0", "value")
.set("GIT_CONFIG_KEY_1", "include.path")
.set("GIT_CONFIG_VALUE_1", a_path.to_str().unwrap())
.set("GIT_CONFIG_VALUE_1", escape_backslashes(a_path))
.set("GIT_CONFIG_KEY_2", "other.path")
.set("GIT_CONFIG_VALUE_2", b_path.to_str().unwrap())
.set("GIT_CONFIG_VALUE_2", escape_backslashes(&b_path))
.set("GIT_CONFIG_KEY_3", "include.origin.path")
.set("GIT_CONFIG_VALUE_3", b_path.to_str().unwrap());
.set("GIT_CONFIG_VALUE_3", escape_backslashes(b_path));

let config = File::from_env(Options::default()).unwrap().unwrap();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn relative_path_without_trailing_slash_and_dot_git_suffix_matches() -> crate::R

#[test]
fn tilde_slash_expands_the_current_user_home() -> crate::Result {
let env = GitEnv::repo_name(format!("subdir{}worktree", std::path::MAIN_SEPARATOR))?;
let env = GitEnv::repo_name(std::path::Path::new("subdir").join("worktree"))?;
assert_section_value(Condition::new("gitdir:~/subdir/worktree/"), env)
}

Expand Down Expand Up @@ -111,11 +111,7 @@ fn dot_slash_from_environment_causes_error() -> crate::Result {
);
}

let absolute_path = format!(
"{}{}include.config",
env.home_dir().display(),
std::path::MAIN_SEPARATOR
);
let absolute_path = escape_backslashes(env.home_dir().join("include.config"));
{
let _environment = crate::file::from_env::Env::new()
.set("GIT_CONFIG_COUNT", "1")
Expand Down
2 changes: 1 addition & 1 deletion git-config/tests/file/from_paths/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use tempfile::tempdir;
use crate::file::cow_str;

/// Escapes backslash when writing a path as string so that it is a valid windows path
fn escape_backslashes(path: impl AsRef<std::path::Path>) -> String {
pub(crate) fn escape_backslashes(path: impl AsRef<std::path::Path>) -> String {
path.as_ref().to_str().unwrap().replace('\\', "\\\\")
}

Expand Down

0 comments on commit 3d7fc18

Please sign in to comment.