Skip to content

Commit bc928f9

Browse files
committed
case-insensitive tests for baseline path matching (#301)
also: prepare for OS specific tests, even though right now there should be none.
1 parent 8fd9f24 commit bc928f9

File tree

2 files changed

+38
-29
lines changed

2 files changed

+38
-29
lines changed

git-glob/tests/fixtures/make_baseline.sh

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ git config commit.gpgsign false
77
git config core.autocrlf false
88
git config core.ignorecase false
99

10-
while read -r pattern nomatch; do
11-
echo "$pattern" "$nomatch"
10+
while read -r pattern value; do
11+
echo "$pattern" "$value"
1212
echo "$pattern" > .gitignore
13-
git check-ignore -vn "$nomatch" 2>&1 || :
14-
done <<EOF >>git-baseline.nmatch
13+
echo "$value" | git check-ignore -vn --stdin 2>&1 || :
14+
done <<EOF >git-baseline.nmatch
1515
*/\ XXX/\
1616
*/\\ XXX/\
1717
/*foo bar/foo
@@ -68,11 +68,15 @@ foo/** foo
6868
abc[/]def abc/def
6969
EOF
7070

71-
while read -r pattern match; do
72-
echo "$pattern" "$match"
71+
while read -r pattern value; do
72+
echo "$pattern" "$value"
7373
echo "$pattern" > .gitignore
74-
git check-ignore -vn "$match" 2>&1 || :
75-
done <<EOF >>git-baseline.match
74+
echo "$value" | git check-ignore -vn --stdin 2>&1 || :
75+
done <<EOF >git-baseline.match
76+
\a a
77+
\\\[a-z] \a
78+
\\\? \a
79+
\\\* \\
7680
/*foo.txt barfoo.txt
7781
*foo.txt bar/foo.txt
7882
*.c mozilla-sha1/sha1.c
@@ -141,38 +145,25 @@ abc/def abc/def
141145
EOF
142146

143147
git config core.ignorecase true
144-
while read -r pattern match; do
145-
echo "$pattern" "$match"
148+
while read -r pattern value; do
149+
echo "$pattern" "$value"
146150
echo "$pattern" > .gitignore
147-
git check-ignore -vn "$match" 2>&1 || :
148-
done <<EOF >>git-baseline.match-icase
151+
echo "$value" | git check-ignore -vn --stdin 2>&1 || :
152+
done <<EOF >git-baseline.match-icase
149153
aBcDeFg aBcDeFg
150154
aBcDeFg abcdefg
151155
aBcDeFg ABCDEFG
152156
aBcDeFg AbCdEfG
153157
EOF
154158

155159
# nmatches OS specific
156-
# windows
157-
# "abc?def" "abc\\def"
158160
# unix
159161
# "abc\\def" "abc/def"
160162

161163

162-
# matches OS specific
163-
164-
# unix only
165-
# "\\a" "a"
166-
#"abc\\def" "abc/def"
167-
#"abc?def" "abc/def"
168-
# \[a-z] \a
169-
# \? \a
170-
# \* \\
171-
172164
# windows only
173-
# "abc[/]def" "abc/def"
174-
# "abc\\def" "abc/def"
175-
#"abc?def" "abc\\def"
165+
# abc[/]def "abc/def"
166+
# abc\def "abc/def"
176167

177168
# empty string is not a valid path-spec
178169
#** " "

git-glob/tests/matching/mod.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,22 @@ fn compare_baseline_with_ours() {
4646
let dir = git_testtools::scripted_fixture_repo_read_only("make_baseline.sh").unwrap();
4747
let (mut total_matches, mut total_correct, mut panics) = (0, 0, 0);
4848
let mut mismatches = Vec::new();
49-
for (input_file, expected_matches) in &[("git-baseline.match", true), ("git-baseline.nmatch", false)] {
49+
for (input_file, mut expected_matches, case, invert_expectation_on_other_os) in &[
50+
("git-baseline.match", true, pattern::Case::Sensitive, false),
51+
("git-baseline.nmatch", false, pattern::Case::Sensitive, false),
52+
("git-baseline.match-icase", true, pattern::Case::Fold, false),
53+
// (
54+
// "git-baseline-unix.match",
55+
// true,
56+
// pattern::Case::Sensitive,
57+
// if cfg!(unix) { false } else { true },
58+
// ),
59+
] {
5060
let input = std::fs::read(dir.join(*input_file)).unwrap();
5161
let mut seen = BTreeSet::default();
62+
if *invert_expectation_on_other_os {
63+
expected_matches = !expected_matches;
64+
}
5265

5366
for m @ GitMatch {
5467
pattern,
@@ -58,13 +71,18 @@ fn compare_baseline_with_ours() {
5871
{
5972
total_matches += 1;
6073
assert!(seen.insert(m), "duplicate match entry: {:?}", m);
74+
assert_eq!(
75+
is_match, expected_matches,
76+
"baseline for matches must be {} - check baseline and git version: {:?}",
77+
expected_matches, m
78+
);
6179
match std::panic::catch_unwind(|| {
6280
let pattern = pat(pattern);
6381
pattern.matches_repo_relative_path(
6482
value,
6583
basename_start_pos(value),
6684
false, // TODO: does it make sense to pretend it is a dir and see what happens?
67-
pattern::Case::Sensitive,
85+
*case,
6886
)
6987
}) {
7088
Ok(actual_match) => {

0 commit comments

Comments
 (0)