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 <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ævar Arnfjörð Bjarmason committed
May 20, 2017 at 21:42 UTC
77f6f4406fef43130e9c72e32ac5e30c5bbe0b9e
1 file changed
+29
-29
t/t7008-grep-binary.sh
+29
-29
@@ -4,6 +4,29 @@ test_description='git grep in binary files'
4
5
. ./test-lib.sh
6
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
+
30
test_expect_success 'setup' "
31
echo 'binaryQfile' | q_to_nul >a &&
32
git add a &&
@@ -69,35 +92,12 @@ test_expect_failure 'git grep .fi a' '
92
git grep .fi a
93
'
94
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'
101
102
test_expect_success 'grep respects binary diff attribute' '
103
echo text >t &&