Skip to content

Commit 77f6f44

Browse files
avargitster
authored andcommitted
grep: add a test helper function for less verbose -f \0 tests
Add a helper function to make the tests which check for patterns with \0 in them more succinct. Right now this isn't a big win, but subsequent commits will add a lot more of these tests. The helper is based on the match() function in t3070-wildmatch.sh. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5ee6f1a commit 77f6f44

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

t/t7008-grep-binary.sh

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,29 @@ test_description='git grep in binary files'
44

55
. ./test-lib.sh
66

7+
nul_match () {
8+
matches=$1
9+
flags=$2
10+
pattern=$3
11+
pattern_human=$(echo "$pattern" | sed 's/Q/<NUL>/g')
12+
13+
if test "$matches" = 1
14+
then
15+
test_expect_success "git grep -f f $flags '$pattern_human' a" "
16+
printf '$pattern' | q_to_nul >f &&
17+
git grep -f f $flags a
18+
"
19+
elif test "$matches" = 0
20+
then
21+
test_expect_success "git grep -f f $flags '$pattern_human' a" "
22+
printf '$pattern' | q_to_nul >f &&
23+
test_must_fail git grep -f f $flags a
24+
"
25+
else
26+
test_expect_success "PANIC: Test framework error. Unknown matches value $matches" 'false'
27+
fi
28+
}
29+
730
test_expect_success 'setup' "
831
echo 'binaryQfile' | q_to_nul >a &&
932
git add a &&
@@ -69,35 +92,12 @@ test_expect_failure 'git grep .fi a' '
6992
git grep .fi a
7093
'
7194

72-
test_expect_success 'git grep -F y<NUL>f a' "
73-
printf 'yQf' | q_to_nul >f &&
74-
git grep -f f -F a
75-
"
76-
77-
test_expect_success 'git grep -F y<NUL>x a' "
78-
printf 'yQx' | q_to_nul >f &&
79-
test_must_fail git grep -f f -F a
80-
"
81-
82-
test_expect_success 'git grep -Fi Y<NUL>f a' "
83-
printf 'YQf' | q_to_nul >f &&
84-
git grep -f f -Fi a
85-
"
86-
87-
test_expect_success 'git grep -Fi Y<NUL>x a' "
88-
printf 'YQx' | q_to_nul >f &&
89-
test_must_fail git grep -f f -Fi a
90-
"
91-
92-
test_expect_success 'git grep y<NUL>f a' "
93-
printf 'yQf' | q_to_nul >f &&
94-
git grep -f f a
95-
"
96-
97-
test_expect_success 'git grep y<NUL>x a' "
98-
printf 'yQx' | q_to_nul >f &&
99-
test_must_fail git grep -f f a
100-
"
95+
nul_match 1 '-F' 'yQf'
96+
nul_match 0 '-F' 'yQx'
97+
nul_match 1 '-Fi' 'YQf'
98+
nul_match 0 '-Fi' 'YQx'
99+
nul_match 1 '' 'yQf'
100+
nul_match 0 '' 'yQx'
101101

102102
test_expect_success 'grep respects binary diff attribute' '
103103
echo text >t &&

0 commit comments

Comments
 (0)