Skip to content

Commit 120675d

Browse files
committed
Test for case-sensitivity as well (#301)
1 parent 6793bab commit 120675d

File tree

2 files changed

+32
-30
lines changed

2 files changed

+32
-30
lines changed

git-worktree/src/fs/cache/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ pub enum State {
3131

3232
#[cfg(debug_assertions)]
3333
impl<'paths> Cache<'paths> {
34+
pub fn set_case(&mut self, case: git_glob::pattern::Case) {
35+
self.case = case;
36+
}
3437
pub fn num_mkdir_calls(&self) -> usize {
3538
match self.state {
3639
State::CreateDirectoryAndAttributesStack { test_mkdir_calls, .. } => test_mkdir_calls,

git-worktree/tests/worktree/fs/cache.rs

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ mod create_directory {
1212
}
1313

1414
#[test]
15-
fn root_is_assumed_to_exist_and_files_in_root_do_not_create_directory() {
16-
let dir = tempdir().unwrap();
15+
fn root_is_assumed_to_exist_and_files_in_root_do_not_create_directory() -> crate::Result {
16+
let dir = tempdir()?;
1717
let mut cache = fs::Cache::new(
1818
dir.path().join("non-existing-root"),
1919
fs::cache::State::for_checkout(false, Default::default()),
@@ -23,9 +23,10 @@ mod create_directory {
2323
);
2424
assert_eq!(cache.num_mkdir_calls(), 0);
2525

26-
let path = cache.at_path("hello", Some(false), panic_on_find).unwrap().path();
26+
let path = cache.at_path("hello", Some(false), panic_on_find)?.path();
2727
assert!(!path.parent().unwrap().exists(), "prefix itself is never created");
2828
assert_eq!(cache.num_mkdir_calls(), 0);
29+
Ok(())
2930
}
3031

3132
#[test]
@@ -50,23 +51,24 @@ mod create_directory {
5051
}
5152

5253
#[test]
53-
fn existing_directories_are_fine() {
54+
fn existing_directories_are_fine() -> crate::Result {
5455
let (mut cache, tmp) = new_cache();
55-
std::fs::create_dir(tmp.path().join("dir")).unwrap();
56+
std::fs::create_dir(tmp.path().join("dir"))?;
5657

57-
let path = cache.at_path("dir/file", Some(false), panic_on_find).unwrap().path();
58+
let path = cache.at_path("dir/file", Some(false), panic_on_find)?.path();
5859
assert!(path.parent().unwrap().is_dir(), "directory is still present");
5960
assert!(!path.exists(), "it won't create the file");
6061
assert_eq!(cache.num_mkdir_calls(), 1);
62+
Ok(())
6163
}
6264

6365
#[test]
64-
fn symlinks_or_files_in_path_are_forbidden_or_unlinked_when_forced() {
66+
fn symlinks_or_files_in_path_are_forbidden_or_unlinked_when_forced() -> crate::Result {
6567
let (mut cache, tmp) = new_cache();
6668
let forbidden = tmp.path().join("forbidden");
67-
std::fs::create_dir(&forbidden).unwrap();
68-
symlink::symlink_dir(&forbidden, tmp.path().join("link-to-dir")).unwrap();
69-
std::fs::write(tmp.path().join("file-in-dir"), &[]).unwrap();
69+
std::fs::create_dir(&forbidden)?;
70+
symlink::symlink_dir(&forbidden, tmp.path().join("link-to-dir"))?;
71+
std::fs::write(tmp.path().join("file-in-dir"), &[])?;
7072

7173
for dirname in &["file-in-dir", "link-to-dir"] {
7274
cache.unlink_on_collision(false);
@@ -88,10 +90,7 @@ mod create_directory {
8890
for dirname in &["link-to-dir", "file-in-dir"] {
8991
cache.unlink_on_collision(true);
9092
let relative_path = format!("{}/file", dirname);
91-
let path = cache
92-
.at_path(&relative_path, Some(false), panic_on_find)
93-
.unwrap()
94-
.path();
93+
let path = cache.at_path(&relative_path, Some(false), panic_on_find)?.path();
9594
assert!(path.parent().unwrap().is_dir(), "directory was forcefully created");
9695
assert!(!path.exists());
9796
}
@@ -100,6 +99,7 @@ mod create_directory {
10099
4,
101100
"like before, but it unlinks what's there and tries again"
102101
);
102+
Ok(())
103103
}
104104

105105
fn new_cache() -> (fs::Cache<'static>, TempDir) {
@@ -120,6 +120,7 @@ mod ignore_and_attributes {
120120
use bstr::{BStr, ByteSlice};
121121
use std::path::Path;
122122

123+
use git_glob::pattern::Case;
123124
use git_index::entry::Mode;
124125
use git_odb::pack::bundle::write::Options;
125126
use git_odb::FindExt;
@@ -153,23 +154,23 @@ mod ignore_and_attributes {
153154
}
154155

155156
#[test]
156-
fn check_against_baseline() {
157-
let dir = git_testtools::scripted_fixture_repo_read_only("make_ignore_and_attributes_setup.sh").unwrap();
157+
fn check_against_baseline() -> crate::Result {
158+
let dir = git_testtools::scripted_fixture_repo_read_only("make_ignore_and_attributes_setup.sh")?;
158159
let worktree_dir = dir.join("repo");
159160
let git_dir = worktree_dir.join(".git");
160161
let mut buf = Vec::new();
161-
let baseline = std::fs::read(git_dir.parent().unwrap().join("git-check-ignore.baseline")).unwrap();
162+
let baseline = std::fs::read(git_dir.parent().unwrap().join("git-check-ignore.baseline"))?;
162163
let user_exclude_path = dir.join("user.exclude");
163164
assert!(user_exclude_path.is_file());
164165

165-
let mut index = git_index::File::at(git_dir.join("index"), Default::default()).unwrap();
166-
let odb = git_odb::at(git_dir.join("objects")).unwrap();
166+
let mut index = git_index::File::at(git_dir.join("index"), Default::default())?;
167+
let odb = git_odb::at(git_dir.join("objects"))?;
167168
let case = git_glob::pattern::Case::Sensitive;
168169
let state = git_worktree::fs::cache::State::for_add(
169170
Default::default(), // TODO: attribute tests
170171
git_worktree::fs::cache::state::Ignore::new(
171172
git_attributes::MatchGroup::from_overrides(vec!["!force-include"]),
172-
git_attributes::MatchGroup::from_git_dir(&git_dir, Some(user_exclude_path), &mut buf).unwrap(),
173+
git_attributes::MatchGroup::from_git_dir(&git_dir, Some(user_exclude_path), &mut buf)?,
173174
None,
174175
case,
175176
),
@@ -191,9 +192,7 @@ mod ignore_and_attributes {
191192
let relative_path = git_path::from_byte_slice(relative_entry);
192193
let is_dir = worktree_dir.join(&relative_path).metadata().ok().map(|m| m.is_dir());
193194

194-
let platform = cache
195-
.at_entry(relative_entry, is_dir, |oid, buf| odb.find_blob(oid, buf))
196-
.unwrap();
195+
let platform = cache.at_entry(relative_entry, is_dir, |oid, buf| odb.find_blob(oid, buf))?;
197196

198197
let match_ = platform.matching_exclude_pattern();
199198
let is_excluded = platform.is_excluded();
@@ -207,12 +206,7 @@ mod ignore_and_attributes {
207206
if m.source.map_or(false, |p| p.exists()) {
208207
assert_eq!(
209208
m.source.map(|p| p.canonicalize().unwrap()),
210-
Some(
211-
worktree_dir
212-
.join(source_file.to_str_lossy().as_ref())
213-
.canonicalize()
214-
.unwrap()
215-
)
209+
Some(worktree_dir.join(source_file.to_str_lossy().as_ref()).canonicalize()?)
216210
);
217211
}
218212
}
@@ -224,6 +218,11 @@ mod ignore_and_attributes {
224218
}
225219
}
226220
}
227-
// TODO: at least one case-insensitive test
221+
222+
cache.set_case(Case::Fold);
223+
let platform = cache.at_entry("User-file-ANYWHERE", Some(false), |oid, buf| odb.find_blob(oid, buf))?;
224+
let m = platform.matching_exclude_pattern().expect("match");
225+
assert_eq!(m.pattern.text, "user-file-anywhere");
226+
Ok(())
228227
}
229228
}

0 commit comments

Comments
 (0)