]>
git.ipfire.org Git - thirdparty/git.git/blob - t/t7816-grep-binary-pattern.sh
3 test_description
='git grep with a binary pattern files'
11 pattern_human
=$
(echo "$pattern" |
sed 's/Q/<NUL>/g')
13 if test "$matches" = 1
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
19 elif test "$matches" = 0
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
25 elif test "$matches" = T1
27 test_expect_failure
"git grep -f f $flags '$pattern_human' a" "
28 printf '$pattern' | q_to_nul >f &&
29 git grep -f f $flags a
31 elif test "$matches" = T0
33 test_expect_failure
"git grep -f f $flags '$pattern_human' a" "
34 printf '$pattern' | q_to_nul >f &&
35 test_must_fail git grep -f f $flags a
38 test_expect_success
"PANIC: Test framework error. Unknown matches value $matches" 'false'
42 test_expect_success
'setup' "
43 echo 'binaryQfileQm[*]cQ*æQð' | q_to_nul >a &&
48 nul_match
1 '-F' 'yQf'
49 nul_match
0 '-F' 'yQx'
50 nul_match
1 '-Fi' 'YQf'
51 nul_match
0 '-Fi' 'YQx'
55 nul_match
1 '-F' 'eQm[*]c'
56 nul_match
1 '-Fi' 'EQM[*]C'
58 # Regex patterns that would match but shouldn't with -F
59 nul_match
0 '-F' 'yQ[f]'
60 nul_match
0 '-F' '[y]Qf'
61 nul_match
0 '-Fi' 'YQ[F]'
62 nul_match
0 '-Fi' '[Y]QF'
63 nul_match
0 '-F' 'æQ[ð]'
64 nul_match
0 '-F' '[æ]Qð'
65 nul_match
0 '-Fi' 'ÆQ[Ð]'
66 nul_match
0 '-Fi' '[Æ]QÐ'
68 # kwset is disabled on -i & non-ASCII. No way to match non-ASCII \0
69 # patterns case-insensitively.
70 nul_match T1
'-i' 'ÆQÐ'
72 # \0 implicitly disables regexes. This is an undocumented internal
74 nul_match T1
'' 'yQ[f]'
75 nul_match T1
'' '[y]Qf'
76 nul_match T1
'-i' 'YQ[F]'
77 nul_match T1
'-i' '[Y]Qf'
78 nul_match T1
'' 'æQ[ð]'
79 nul_match T1
'' '[æ]Qð'
80 nul_match T1
'-i' 'ÆQ[Ð]'
82 # ... because of \0 implicitly disabling regexes regexes that
83 # should/shouldn't match don't do the right thing.
84 nul_match T1
'' 'eQm.*cQ'
85 nul_match T1
'-i' 'EQM.*cQ'
86 nul_match T0
'' 'eQm[*]c'
87 nul_match T0
'-i' 'EQM[*]C'
89 # Due to the REG_STARTEND extension when kwset() is disabled on -i &
90 # non-ASCII the string will be matched in its entirety, but the
91 # pattern will be cut off at the first \0.
92 nul_match
0 '-i' 'NOMATCHQð'
93 nul_match T0
'-i' '[Æ]QNOMATCH'
94 nul_match T0
'-i' '[æ]QNOMATCH'
95 # Matches, but for the wrong reasons, just stops at [æ]
96 nul_match
1 '-i' '[Æ]Qð'
97 nul_match
1 '-i' '[æ]Qð'
99 # Ensure that the matcher doesn't regress to something that stops at
101 nul_match
0 '-F' 'yQ[f]'
102 nul_match
0 '-Fi' 'YQ[F]'
103 nul_match
0 '' 'yQNOMATCH'
104 nul_match
0 '' 'QNOMATCH'
105 nul_match
0 '-i' 'YQNOMATCH'
106 nul_match
0 '-i' 'QNOMATCH'
107 nul_match
0 '-F' 'æQ[ð]'
108 nul_match
0 '-Fi' 'ÆQ[Ð]'
109 nul_match
0 '' 'yQNÓMATCH'
110 nul_match
0 '' 'QNÓMATCH'
111 nul_match
0 '-i' 'YQNÓMATCH'
112 nul_match
0 '-i' 'QNÓMATCH'