Junio C Hamano | f25b793 | 2006-08-04 22:16:42 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2006 Junio C Hamano |
| 4 | # |
| 5 | |
Junio C Hamano | 0d042fe | 2006-08-11 00:44:42 -0700 | [diff] [blame] | 6 | test_description='git grep various. |
Junio C Hamano | f25b793 | 2006-08-04 22:16:42 -0700 | [diff] [blame] | 7 | ' |
| 8 | |
| 9 | . ./test-lib.sh |
| 10 | |
René Scharfe | 2944e4e | 2009-07-02 00:06:34 +0200 | [diff] [blame] | 11 | cat >hello.c <<EOF |
| 12 | #include <stdio.h> |
| 13 | int main(int argc, const char **argv) |
| 14 | { |
| 15 | printf("Hello world.\n"); |
| 16 | return 0; |
Brian Collins | 5183bf6 | 2009-11-06 01:22:35 -0800 | [diff] [blame] | 17 | /* char ?? */ |
René Scharfe | 2944e4e | 2009-07-02 00:06:34 +0200 | [diff] [blame] | 18 | } |
| 19 | EOF |
| 20 | |
Junio C Hamano | f25b793 | 2006-08-04 22:16:42 -0700 | [diff] [blame] | 21 | test_expect_success setup ' |
| 22 | { |
| 23 | echo foo mmap bar |
| 24 | echo foo_mmap bar |
| 25 | echo foo_mmap bar mmap |
| 26 | echo foo mmap bar_mmap |
| 27 | echo foo_mmap bar mmap baz |
| 28 | } >file && |
Michał Kiedrowicz | 8f852ce | 2011-05-09 23:52:07 +0200 | [diff] [blame] | 29 | { |
| 30 | echo Hello world |
| 31 | echo HeLLo world |
| 32 | echo Hello_world |
| 33 | echo HeLLo_world |
| 34 | } >hello_world && |
Michał Kiedrowicz | f556e4a | 2011-05-22 13:37:28 +0200 | [diff] [blame] | 35 | { |
Michał Kiedrowicz | d0042ab | 2011-05-27 00:43:59 +0200 | [diff] [blame] | 36 | echo "a+b*c" |
| 37 | echo "a+bc" |
| 38 | echo "abc" |
Michał Kiedrowicz | f556e4a | 2011-05-22 13:37:28 +0200 | [diff] [blame] | 39 | } >ab && |
Michał Kiedrowicz | a91f453 | 2009-07-22 19:52:15 +0200 | [diff] [blame] | 40 | echo vvv >v && |
René Scharfe | dbb6a4a | 2009-05-23 13:45:26 +0200 | [diff] [blame] | 41 | echo ww w >w && |
Junio C Hamano | f25b793 | 2006-08-04 22:16:42 -0700 | [diff] [blame] | 42 | echo x x xx x >x && |
| 43 | echo y yy >y && |
| 44 | echo zzz > z && |
Junio C Hamano | 0d042fe | 2006-08-11 00:44:42 -0700 | [diff] [blame] | 45 | mkdir t && |
| 46 | echo test >t/t && |
Michał Kiedrowicz | a91f453 | 2009-07-22 19:52:15 +0200 | [diff] [blame] | 47 | echo vvv >t/v && |
| 48 | mkdir t/a && |
| 49 | echo vvv >t/a/v && |
Michał Kiedrowicz | d29d787 | 2012-02-27 17:45:49 +0100 | [diff] [blame] | 50 | { |
| 51 | echo "line without leading space1" |
| 52 | echo " line with leading space1" |
| 53 | echo " line with leading space2" |
| 54 | echo " line with leading space3" |
| 55 | echo "line without leading space2" |
| 56 | } >space && |
Michał Kiedrowicz | a91f453 | 2009-07-22 19:52:15 +0200 | [diff] [blame] | 57 | git add . && |
Junio C Hamano | a4d7d2c | 2008-09-04 22:15:02 -0700 | [diff] [blame] | 58 | test_tick && |
Junio C Hamano | f25b793 | 2006-08-04 22:16:42 -0700 | [diff] [blame] | 59 | git commit -m initial |
| 60 | ' |
| 61 | |
Linus Torvalds | c922b01 | 2009-04-27 11:10:24 -0700 | [diff] [blame] | 62 | test_expect_success 'grep should not segfault with a bad input' ' |
| 63 | test_must_fail git grep "(" |
| 64 | ' |
| 65 | |
Junio C Hamano | f25b793 | 2006-08-04 22:16:42 -0700 | [diff] [blame] | 66 | for H in HEAD '' |
| 67 | do |
| 68 | case "$H" in |
| 69 | HEAD) HC='HEAD:' L='HEAD' ;; |
| 70 | '') HC= L='in working tree' ;; |
| 71 | esac |
| 72 | |
| 73 | test_expect_success "grep -w $L" ' |
| 74 | { |
| 75 | echo ${HC}file:1:foo mmap bar |
| 76 | echo ${HC}file:3:foo_mmap bar mmap |
| 77 | echo ${HC}file:4:foo mmap bar_mmap |
| 78 | echo ${HC}file:5:foo_mmap bar mmap baz |
| 79 | } >expected && |
Joe Ratterman | b22520a | 2011-03-30 14:31:05 -0500 | [diff] [blame] | 80 | git -c grep.linenumber=false grep -n -w -e mmap $H >actual && |
| 81 | test_cmp expected actual |
| 82 | ' |
| 83 | |
| 84 | test_expect_success "grep -w $L" ' |
| 85 | { |
| 86 | echo ${HC}file:1:foo mmap bar |
| 87 | echo ${HC}file:3:foo_mmap bar mmap |
| 88 | echo ${HC}file:4:foo mmap bar_mmap |
| 89 | echo ${HC}file:5:foo_mmap bar mmap baz |
| 90 | } >expected && |
| 91 | git -c grep.linenumber=true grep -w -e mmap $H >actual && |
| 92 | test_cmp expected actual |
| 93 | ' |
| 94 | |
| 95 | test_expect_success "grep -w $L" ' |
| 96 | { |
| 97 | echo ${HC}file:foo mmap bar |
| 98 | echo ${HC}file:foo_mmap bar mmap |
| 99 | echo ${HC}file:foo mmap bar_mmap |
| 100 | echo ${HC}file:foo_mmap bar mmap baz |
| 101 | } >expected && |
| 102 | git -c grep.linenumber=true grep --no-line-number -w -e mmap $H >actual && |
Gary V. Vaughan | 4fdf71b | 2010-05-14 09:31:37 +0000 | [diff] [blame] | 103 | test_cmp expected actual |
Junio C Hamano | f25b793 | 2006-08-04 22:16:42 -0700 | [diff] [blame] | 104 | ' |
| 105 | |
René Scharfe | dbb6a4a | 2009-05-23 13:45:26 +0200 | [diff] [blame] | 106 | test_expect_success "grep -w $L (w)" ' |
| 107 | : >expected && |
Jared Hance | ce14e0b | 2010-07-20 19:18:34 -0400 | [diff] [blame] | 108 | test_must_fail git grep -n -w -e "^w" >actual && |
René Scharfe | dbb6a4a | 2009-05-23 13:45:26 +0200 | [diff] [blame] | 109 | test_cmp expected actual |
| 110 | ' |
| 111 | |
Junio C Hamano | f25b793 | 2006-08-04 22:16:42 -0700 | [diff] [blame] | 112 | test_expect_success "grep -w $L (x)" ' |
| 113 | { |
| 114 | echo ${HC}x:1:x x xx x |
| 115 | } >expected && |
| 116 | git grep -n -w -e "x xx* x" $H >actual && |
Gary V. Vaughan | 4fdf71b | 2010-05-14 09:31:37 +0000 | [diff] [blame] | 117 | test_cmp expected actual |
Junio C Hamano | f25b793 | 2006-08-04 22:16:42 -0700 | [diff] [blame] | 118 | ' |
| 119 | |
| 120 | test_expect_success "grep -w $L (y-1)" ' |
| 121 | { |
| 122 | echo ${HC}y:1:y yy |
| 123 | } >expected && |
| 124 | git grep -n -w -e "^y" $H >actual && |
Gary V. Vaughan | 4fdf71b | 2010-05-14 09:31:37 +0000 | [diff] [blame] | 125 | test_cmp expected actual |
Junio C Hamano | f25b793 | 2006-08-04 22:16:42 -0700 | [diff] [blame] | 126 | ' |
| 127 | |
| 128 | test_expect_success "grep -w $L (y-2)" ' |
| 129 | : >expected && |
| 130 | if git grep -n -w -e "^y y" $H >actual |
| 131 | then |
| 132 | echo should not have matched |
| 133 | cat actual |
| 134 | false |
| 135 | else |
Gary V. Vaughan | 4fdf71b | 2010-05-14 09:31:37 +0000 | [diff] [blame] | 136 | test_cmp expected actual |
Junio C Hamano | f25b793 | 2006-08-04 22:16:42 -0700 | [diff] [blame] | 137 | fi |
| 138 | ' |
| 139 | |
| 140 | test_expect_success "grep -w $L (z)" ' |
| 141 | : >expected && |
| 142 | if git grep -n -w -e "^z" $H >actual |
| 143 | then |
| 144 | echo should not have matched |
| 145 | cat actual |
| 146 | false |
| 147 | else |
Gary V. Vaughan | 4fdf71b | 2010-05-14 09:31:37 +0000 | [diff] [blame] | 148 | test_cmp expected actual |
Junio C Hamano | f25b793 | 2006-08-04 22:16:42 -0700 | [diff] [blame] | 149 | fi |
| 150 | ' |
Junio C Hamano | 0d042fe | 2006-08-11 00:44:42 -0700 | [diff] [blame] | 151 | |
| 152 | test_expect_success "grep $L (t-1)" ' |
| 153 | echo "${HC}t/t:1:test" >expected && |
| 154 | git grep -n -e test $H >actual && |
Gary V. Vaughan | 4fdf71b | 2010-05-14 09:31:37 +0000 | [diff] [blame] | 155 | test_cmp expected actual |
Junio C Hamano | 0d042fe | 2006-08-11 00:44:42 -0700 | [diff] [blame] | 156 | ' |
| 157 | |
| 158 | test_expect_success "grep $L (t-2)" ' |
| 159 | echo "${HC}t:1:test" >expected && |
| 160 | ( |
| 161 | cd t && |
| 162 | git grep -n -e test $H |
| 163 | ) >actual && |
Gary V. Vaughan | 4fdf71b | 2010-05-14 09:31:37 +0000 | [diff] [blame] | 164 | test_cmp expected actual |
Junio C Hamano | 0d042fe | 2006-08-11 00:44:42 -0700 | [diff] [blame] | 165 | ' |
| 166 | |
| 167 | test_expect_success "grep $L (t-3)" ' |
| 168 | echo "${HC}t/t:1:test" >expected && |
| 169 | ( |
| 170 | cd t && |
| 171 | git grep --full-name -n -e test $H |
| 172 | ) >actual && |
Gary V. Vaughan | 4fdf71b | 2010-05-14 09:31:37 +0000 | [diff] [blame] | 173 | test_cmp expected actual |
Junio C Hamano | 0d042fe | 2006-08-11 00:44:42 -0700 | [diff] [blame] | 174 | ' |
| 175 | |
Junio C Hamano | 41ac414 | 2008-02-01 01:50:53 -0800 | [diff] [blame] | 176 | test_expect_success "grep -c $L (no /dev/null)" ' |
Jeff King | 8753941 | 2008-09-30 04:03:55 -0400 | [diff] [blame] | 177 | ! git grep -c test $H | grep /dev/null |
Junio C Hamano | d99ebf0 | 2007-09-14 00:31:00 -0700 | [diff] [blame] | 178 | ' |
| 179 | |
Michał Kiedrowicz | a91f453 | 2009-07-22 19:52:15 +0200 | [diff] [blame] | 180 | test_expect_success "grep --max-depth -1 $L" ' |
| 181 | { |
| 182 | echo ${HC}t/a/v:1:vvv |
| 183 | echo ${HC}t/v:1:vvv |
| 184 | echo ${HC}v:1:vvv |
| 185 | } >expected && |
| 186 | git grep --max-depth -1 -n -e vvv $H >actual && |
| 187 | test_cmp expected actual |
| 188 | ' |
| 189 | |
| 190 | test_expect_success "grep --max-depth 0 $L" ' |
| 191 | { |
| 192 | echo ${HC}v:1:vvv |
| 193 | } >expected && |
| 194 | git grep --max-depth 0 -n -e vvv $H >actual && |
| 195 | test_cmp expected actual |
| 196 | ' |
| 197 | |
| 198 | test_expect_success "grep --max-depth 0 -- '*' $L" ' |
| 199 | { |
| 200 | echo ${HC}t/a/v:1:vvv |
| 201 | echo ${HC}t/v:1:vvv |
| 202 | echo ${HC}v:1:vvv |
| 203 | } >expected && |
| 204 | git grep --max-depth 0 -n -e vvv $H -- "*" >actual && |
| 205 | test_cmp expected actual |
| 206 | ' |
| 207 | |
| 208 | test_expect_success "grep --max-depth 1 $L" ' |
| 209 | { |
| 210 | echo ${HC}t/v:1:vvv |
| 211 | echo ${HC}v:1:vvv |
| 212 | } >expected && |
| 213 | git grep --max-depth 1 -n -e vvv $H >actual && |
| 214 | test_cmp expected actual |
| 215 | ' |
| 216 | |
| 217 | test_expect_success "grep --max-depth 0 -- t $L" ' |
| 218 | { |
| 219 | echo ${HC}t/v:1:vvv |
| 220 | } >expected && |
| 221 | git grep --max-depth 0 -n -e vvv $H -- t >actual && |
| 222 | test_cmp expected actual |
| 223 | ' |
| 224 | |
Nguyễn Thái Ngọc Duy | b31f688 | 2010-12-15 22:02:56 +0700 | [diff] [blame] | 225 | test_expect_success "grep --max-depth 0 -- . t $L" ' |
| 226 | { |
| 227 | echo ${HC}t/v:1:vvv |
| 228 | echo ${HC}v:1:vvv |
| 229 | } >expected && |
| 230 | git grep --max-depth 0 -n -e vvv $H -- . t >actual && |
| 231 | test_cmp expected actual |
| 232 | ' |
| 233 | |
| 234 | test_expect_success "grep --max-depth 0 -- t . $L" ' |
| 235 | { |
| 236 | echo ${HC}t/v:1:vvv |
| 237 | echo ${HC}v:1:vvv |
| 238 | } >expected && |
| 239 | git grep --max-depth 0 -n -e vvv $H -- t . >actual && |
| 240 | test_cmp expected actual |
| 241 | ' |
Michał Kiedrowicz | f556e4a | 2011-05-22 13:37:28 +0200 | [diff] [blame] | 242 | test_expect_success "grep $L with grep.extendedRegexp=false" ' |
Michał Kiedrowicz | d0042ab | 2011-05-27 00:43:59 +0200 | [diff] [blame] | 243 | echo "ab:a+bc" >expected && |
| 244 | git -c grep.extendedRegexp=false grep "a+b*c" ab >actual && |
Michał Kiedrowicz | f556e4a | 2011-05-22 13:37:28 +0200 | [diff] [blame] | 245 | test_cmp expected actual |
| 246 | ' |
Nguyễn Thái Ngọc Duy | b31f688 | 2010-12-15 22:02:56 +0700 | [diff] [blame] | 247 | |
Michał Kiedrowicz | f556e4a | 2011-05-22 13:37:28 +0200 | [diff] [blame] | 248 | test_expect_success "grep $L with grep.extendedRegexp=true" ' |
Michał Kiedrowicz | d0042ab | 2011-05-27 00:43:59 +0200 | [diff] [blame] | 249 | echo "ab:abc" >expected && |
| 250 | git -c grep.extendedRegexp=true grep "a+b*c" ab >actual && |
Michał Kiedrowicz | f556e4a | 2011-05-22 13:37:28 +0200 | [diff] [blame] | 251 | test_cmp expected actual |
| 252 | ' |
J Smith | 84befcd | 2012-08-03 10:53:50 -0400 | [diff] [blame] | 253 | |
| 254 | test_expect_success "grep $L with grep.patterntype=basic" ' |
| 255 | echo "ab:a+bc" >expected && |
| 256 | git -c grep.patterntype=basic grep "a+b*c" ab >actual && |
| 257 | test_cmp expected actual |
| 258 | ' |
| 259 | |
| 260 | test_expect_success "grep $L with grep.patterntype=extended" ' |
| 261 | echo "ab:abc" >expected && |
| 262 | git -c grep.patterntype=extended grep "a+b*c" ab >actual && |
| 263 | test_cmp expected actual |
| 264 | ' |
| 265 | |
| 266 | test_expect_success "grep $L with grep.patterntype=fixed" ' |
| 267 | echo "ab:a+b*c" >expected && |
| 268 | git -c grep.patterntype=fixed grep "a+b*c" ab >actual && |
| 269 | test_cmp expected actual |
| 270 | ' |
| 271 | |
| 272 | test_expect_success LIBPCRE "grep $L with grep.patterntype=perl" ' |
| 273 | echo "ab:a+b*c" >expected && |
| 274 | git -c grep.patterntype=perl grep "a\x{2b}b\x{2a}c" ab >actual && |
| 275 | test_cmp expected actual |
| 276 | ' |
| 277 | |
| 278 | test_expect_success "grep $L with grep.patternType=default and grep.extendedRegexp=true" ' |
| 279 | echo "ab:abc" >expected && |
| 280 | git \ |
| 281 | -c grep.patternType=default \ |
| 282 | -c grep.extendedRegexp=true \ |
| 283 | grep "a+b*c" ab >actual && |
| 284 | test_cmp expected actual |
| 285 | ' |
| 286 | |
| 287 | test_expect_success "grep $L with grep.extendedRegexp=true and grep.patternType=default" ' |
| 288 | echo "ab:abc" >expected && |
| 289 | git \ |
| 290 | -c grep.extendedRegexp=true \ |
| 291 | -c grep.patternType=default \ |
| 292 | grep "a+b*c" ab >actual && |
| 293 | test_cmp expected actual |
| 294 | ' |
| 295 | |
| 296 | test_expect_success 'grep $L with grep.patternType=extended and grep.extendedRegexp=false' ' |
| 297 | echo "ab:abc" >expected && |
| 298 | git \ |
| 299 | -c grep.patternType=extended \ |
| 300 | -c grep.extendedRegexp=false \ |
| 301 | grep "a+b*c" ab >actual && |
| 302 | test_cmp expected actual |
| 303 | ' |
| 304 | |
| 305 | test_expect_success 'grep $L with grep.patternType=basic and grep.extendedRegexp=true' ' |
| 306 | echo "ab:a+bc" >expected && |
| 307 | git \ |
| 308 | -c grep.patternType=basic \ |
| 309 | -c grep.extendedRegexp=true \ |
| 310 | grep "a+b*c" ab >actual && |
| 311 | test_cmp expected actual |
| 312 | ' |
| 313 | |
| 314 | test_expect_success 'grep $L with grep.extendedRegexp=false and grep.patternType=extended' ' |
| 315 | echo "ab:abc" >expected && |
| 316 | git \ |
| 317 | -c grep.extendedRegexp=false \ |
| 318 | -c grep.patternType=extended \ |
| 319 | grep "a+b*c" ab >actual && |
| 320 | test_cmp expected actual |
| 321 | ' |
| 322 | |
| 323 | test_expect_success 'grep $L with grep.extendedRegexp=true and grep.patternType=basic' ' |
| 324 | echo "ab:a+bc" >expected && |
| 325 | git \ |
| 326 | -c grep.extendedRegexp=true \ |
| 327 | -c grep.patternType=basic \ |
| 328 | grep "a+b*c" ab >actual && |
| 329 | test_cmp expected actual |
| 330 | ' |
Junio C Hamano | f25b793 | 2006-08-04 22:16:42 -0700 | [diff] [blame] | 331 | done |
| 332 | |
Thomas Rast | 0f70504 | 2009-06-27 20:47:44 +0200 | [diff] [blame] | 333 | cat >expected <<EOF |
Albert Yale | 50dd0f2 | 2012-01-23 18:52:44 +0100 | [diff] [blame] | 334 | file |
| 335 | EOF |
| 336 | test_expect_success 'grep -l -C' ' |
| 337 | git grep -l -C1 foo >actual && |
| 338 | test_cmp expected actual |
| 339 | ' |
| 340 | |
| 341 | cat >expected <<EOF |
| 342 | file:5 |
| 343 | EOF |
| 344 | test_expect_success 'grep -l -C' ' |
| 345 | git grep -c -C1 foo >actual && |
| 346 | test_cmp expected actual |
| 347 | ' |
| 348 | |
| 349 | test_expect_success 'grep -L -C' ' |
| 350 | git ls-files >expected && |
| 351 | git grep -L -C1 nonexistent_string >actual && |
| 352 | test_cmp expected actual |
| 353 | ' |
| 354 | |
| 355 | cat >expected <<EOF |
Thomas Rast | 0f70504 | 2009-06-27 20:47:44 +0200 | [diff] [blame] | 356 | file:foo mmap bar_mmap |
| 357 | EOF |
| 358 | |
| 359 | test_expect_success 'grep -e A --and -e B' ' |
| 360 | git grep -e "foo mmap" --and -e bar_mmap >actual && |
| 361 | test_cmp expected actual |
| 362 | ' |
| 363 | |
| 364 | cat >expected <<EOF |
| 365 | file:foo_mmap bar mmap |
| 366 | file:foo_mmap bar mmap baz |
| 367 | EOF |
| 368 | |
| 369 | |
| 370 | test_expect_success 'grep ( -e A --or -e B ) --and -e B' ' |
| 371 | git grep \( -e foo_ --or -e baz \) \ |
| 372 | --and -e " mmap" >actual && |
| 373 | test_cmp expected actual |
| 374 | ' |
| 375 | |
| 376 | cat >expected <<EOF |
| 377 | file:foo mmap bar |
| 378 | EOF |
| 379 | |
| 380 | test_expect_success 'grep -e A --and --not -e B' ' |
| 381 | git grep -e "foo mmap" --and --not -e bar_mmap >actual && |
| 382 | test_cmp expected actual |
| 383 | ' |
| 384 | |
René Scharfe | b482759 | 2009-11-22 16:58:09 +0100 | [diff] [blame] | 385 | test_expect_success 'grep should ignore GREP_OPTIONS' ' |
| 386 | GREP_OPTIONS=-v git grep " mmap bar\$" >actual && |
| 387 | test_cmp expected actual |
| 388 | ' |
| 389 | |
Matt Kraai | cfe370c | 2009-10-16 07:13:25 -0700 | [diff] [blame] | 390 | test_expect_success 'grep -f, non-existent file' ' |
| 391 | test_must_fail git grep -f patterns |
| 392 | ' |
| 393 | |
| 394 | cat >expected <<EOF |
| 395 | file:foo mmap bar |
| 396 | file:foo_mmap bar |
| 397 | file:foo_mmap bar mmap |
| 398 | file:foo mmap bar_mmap |
| 399 | file:foo_mmap bar mmap baz |
| 400 | EOF |
| 401 | |
| 402 | cat >pattern <<EOF |
| 403 | mmap |
| 404 | EOF |
| 405 | |
| 406 | test_expect_success 'grep -f, one pattern' ' |
| 407 | git grep -f pattern >actual && |
| 408 | test_cmp expected actual |
| 409 | ' |
| 410 | |
| 411 | cat >expected <<EOF |
| 412 | file:foo mmap bar |
| 413 | file:foo_mmap bar |
| 414 | file:foo_mmap bar mmap |
| 415 | file:foo mmap bar_mmap |
| 416 | file:foo_mmap bar mmap baz |
| 417 | t/a/v:vvv |
| 418 | t/v:vvv |
| 419 | v:vvv |
| 420 | EOF |
| 421 | |
| 422 | cat >patterns <<EOF |
| 423 | mmap |
| 424 | vvv |
| 425 | EOF |
| 426 | |
| 427 | test_expect_success 'grep -f, multiple patterns' ' |
| 428 | git grep -f patterns >actual && |
| 429 | test_cmp expected actual |
| 430 | ' |
| 431 | |
René Scharfe | 526a858 | 2012-05-20 16:33:07 +0200 | [diff] [blame] | 432 | test_expect_success 'grep, multiple patterns' ' |
| 433 | git grep "$(cat patterns)" >actual && |
| 434 | test_cmp expected actual |
| 435 | ' |
| 436 | |
Matt Kraai | cfe370c | 2009-10-16 07:13:25 -0700 | [diff] [blame] | 437 | cat >expected <<EOF |
| 438 | file:foo mmap bar |
| 439 | file:foo_mmap bar |
| 440 | file:foo_mmap bar mmap |
| 441 | file:foo mmap bar_mmap |
| 442 | file:foo_mmap bar mmap baz |
| 443 | t/a/v:vvv |
| 444 | t/v:vvv |
| 445 | v:vvv |
| 446 | EOF |
| 447 | |
| 448 | cat >patterns <<EOF |
| 449 | |
| 450 | mmap |
| 451 | |
| 452 | vvv |
| 453 | |
| 454 | EOF |
| 455 | |
| 456 | test_expect_success 'grep -f, ignore empty lines' ' |
| 457 | git grep -f patterns >actual && |
| 458 | test_cmp expected actual |
| 459 | ' |
| 460 | |
René Scharfe | c41dd2f | 2011-03-19 19:33:15 +0100 | [diff] [blame] | 461 | test_expect_success 'grep -f, ignore empty lines, read patterns from stdin' ' |
| 462 | git grep -f - <patterns >actual && |
| 463 | test_cmp expected actual |
| 464 | ' |
| 465 | |
René Scharfe | 046802d | 2009-07-02 00:03:44 +0200 | [diff] [blame] | 466 | cat >expected <<EOF |
| 467 | y:y yy |
| 468 | -- |
| 469 | z:zzz |
| 470 | EOF |
| 471 | |
Junio C Hamano | 4ff61c2 | 2010-01-28 12:33:42 -0800 | [diff] [blame] | 472 | test_expect_success 'grep -q, silently report matches' ' |
| 473 | >empty && |
| 474 | git grep -q mmap >actual && |
| 475 | test_cmp empty actual && |
| 476 | test_must_fail git grep -q qfwfq >actual && |
| 477 | test_cmp empty actual |
| 478 | ' |
| 479 | |
Junio C Hamano | bbc09c2 | 2010-01-12 19:06:41 -0800 | [diff] [blame] | 480 | test_expect_success 'grep -C1 hunk mark between files' ' |
| 481 | git grep -C1 "^[yz]" >actual && |
René Scharfe | 046802d | 2009-07-02 00:03:44 +0200 | [diff] [blame] | 482 | test_cmp expected actual |
| 483 | ' |
| 484 | |
Junio C Hamano | a4d7d2c | 2008-09-04 22:15:02 -0700 | [diff] [blame] | 485 | test_expect_success 'log grep setup' ' |
| 486 | echo a >>file && |
| 487 | test_tick && |
| 488 | GIT_AUTHOR_NAME="With * Asterisk" \ |
| 489 | GIT_AUTHOR_EMAIL="xyzzy@frotz.com" \ |
| 490 | git commit -a -m "second" && |
| 491 | |
| 492 | echo a >>file && |
| 493 | test_tick && |
Junio C Hamano | 5aaeb73 | 2010-09-12 22:15:35 -0700 | [diff] [blame] | 494 | git commit -a -m "third" && |
Junio C Hamano | a4d7d2c | 2008-09-04 22:15:02 -0700 | [diff] [blame] | 495 | |
Junio C Hamano | 5aaeb73 | 2010-09-12 22:15:35 -0700 | [diff] [blame] | 496 | echo a >>file && |
| 497 | test_tick && |
| 498 | GIT_AUTHOR_NAME="Night Fall" \ |
| 499 | GIT_AUTHOR_EMAIL="nitfol@frobozz.com" \ |
| 500 | git commit -a -m "fourth" |
Junio C Hamano | a4d7d2c | 2008-09-04 22:15:02 -0700 | [diff] [blame] | 501 | ' |
| 502 | |
| 503 | test_expect_success 'log grep (1)' ' |
| 504 | git log --author=author --pretty=tformat:%s >actual && |
| 505 | ( echo third ; echo initial ) >expect && |
| 506 | test_cmp expect actual |
| 507 | ' |
| 508 | |
| 509 | test_expect_success 'log grep (2)' ' |
| 510 | git log --author=" * " -F --pretty=tformat:%s >actual && |
| 511 | ( echo second ) >expect && |
| 512 | test_cmp expect actual |
| 513 | ' |
| 514 | |
| 515 | test_expect_success 'log grep (3)' ' |
| 516 | git log --author="^A U" --pretty=tformat:%s >actual && |
| 517 | ( echo third ; echo initial ) >expect && |
| 518 | test_cmp expect actual |
| 519 | ' |
| 520 | |
| 521 | test_expect_success 'log grep (4)' ' |
| 522 | git log --author="frotz\.com>$" --pretty=tformat:%s >actual && |
| 523 | ( echo second ) >expect && |
| 524 | test_cmp expect actual |
| 525 | ' |
| 526 | |
| 527 | test_expect_success 'log grep (5)' ' |
Junio C Hamano | 80235ba | 2010-01-17 20:09:06 -0800 | [diff] [blame] | 528 | git log --author=Thor -F --pretty=tformat:%s >actual && |
Junio C Hamano | a4d7d2c | 2008-09-04 22:15:02 -0700 | [diff] [blame] | 529 | ( echo third ; echo initial ) >expect && |
| 530 | test_cmp expect actual |
| 531 | ' |
| 532 | |
| 533 | test_expect_success 'log grep (6)' ' |
| 534 | git log --author=-0700 --pretty=tformat:%s >actual && |
| 535 | >expect && |
| 536 | test_cmp expect actual |
Nguyễn Thái Ngọc Duy | 57d4346 | 2008-12-27 15:21:03 +0700 | [diff] [blame] | 537 | ' |
Junio C Hamano | a4d7d2c | 2008-09-04 22:15:02 -0700 | [diff] [blame] | 538 | |
Junio C Hamano | 80235ba | 2010-01-17 20:09:06 -0800 | [diff] [blame] | 539 | test_expect_success 'log --grep --author implicitly uses all-match' ' |
| 540 | # grep matches initial and second but not third |
| 541 | # author matches only initial and third |
| 542 | git log --author="A U Thor" --grep=s --grep=l --format=%s >actual && |
| 543 | echo initial >expect && |
| 544 | test_cmp expect actual |
| 545 | ' |
| 546 | |
Junio C Hamano | 5aaeb73 | 2010-09-12 22:15:35 -0700 | [diff] [blame] | 547 | test_expect_success 'log with multiple --author uses union' ' |
| 548 | git log --author="Thor" --author="Aster" --format=%s >actual && |
| 549 | { |
| 550 | echo third && echo second && echo initial |
| 551 | } >expect && |
| 552 | test_cmp expect actual |
| 553 | ' |
| 554 | |
| 555 | test_expect_success 'log with --grep and multiple --author uses all-match' ' |
| 556 | git log --author="Thor" --author="Night" --grep=i --format=%s >actual && |
| 557 | { |
| 558 | echo third && echo initial |
| 559 | } >expect && |
| 560 | test_cmp expect actual |
| 561 | ' |
| 562 | |
| 563 | test_expect_success 'log with --grep and multiple --author uses all-match' ' |
| 564 | git log --author="Thor" --author="Night" --grep=q --format=%s >actual && |
| 565 | >expect && |
| 566 | test_cmp expect actual |
| 567 | ' |
| 568 | |
Nguyễn Thái Ngọc Duy | 57d4346 | 2008-12-27 15:21:03 +0700 | [diff] [blame] | 569 | test_expect_success 'grep with CE_VALID file' ' |
| 570 | git update-index --assume-unchanged t/t && |
| 571 | rm t/t && |
Junio C Hamano | bbc09c2 | 2010-01-12 19:06:41 -0800 | [diff] [blame] | 572 | test "$(git grep test)" = "t/t:test" && |
Nguyễn Thái Ngọc Duy | 57d4346 | 2008-12-27 15:21:03 +0700 | [diff] [blame] | 573 | git update-index --no-assume-unchanged t/t && |
| 574 | git checkout t/t |
Junio C Hamano | a4d7d2c | 2008-09-04 22:15:02 -0700 | [diff] [blame] | 575 | ' |
| 576 | |
René Scharfe | 2944e4e | 2009-07-02 00:06:34 +0200 | [diff] [blame] | 577 | cat >expected <<EOF |
René Scharfe | 60ecac9 | 2009-07-02 00:07:24 +0200 | [diff] [blame] | 578 | hello.c=#include <stdio.h> |
| 579 | hello.c: return 0; |
| 580 | EOF |
| 581 | |
| 582 | test_expect_success 'grep -p with userdiff' ' |
| 583 | git config diff.custom.funcname "^#" && |
| 584 | echo "hello.c diff=custom" >.gitattributes && |
| 585 | git grep -p return >actual && |
| 586 | test_cmp expected actual |
| 587 | ' |
| 588 | |
| 589 | cat >expected <<EOF |
René Scharfe | 2944e4e | 2009-07-02 00:06:34 +0200 | [diff] [blame] | 590 | hello.c=int main(int argc, const char **argv) |
| 591 | hello.c: return 0; |
| 592 | EOF |
| 593 | |
| 594 | test_expect_success 'grep -p' ' |
René Scharfe | 60ecac9 | 2009-07-02 00:07:24 +0200 | [diff] [blame] | 595 | rm -f .gitattributes && |
René Scharfe | 2944e4e | 2009-07-02 00:06:34 +0200 | [diff] [blame] | 596 | git grep -p return >actual && |
| 597 | test_cmp expected actual |
| 598 | ' |
| 599 | |
| 600 | cat >expected <<EOF |
| 601 | hello.c-#include <stdio.h> |
| 602 | hello.c=int main(int argc, const char **argv) |
| 603 | hello.c-{ |
| 604 | hello.c- printf("Hello world.\n"); |
| 605 | hello.c: return 0; |
| 606 | EOF |
| 607 | |
| 608 | test_expect_success 'grep -p -B5' ' |
| 609 | git grep -p -B5 return >actual && |
| 610 | test_cmp expected actual |
| 611 | ' |
| 612 | |
René Scharfe | ba8ea74 | 2011-08-01 19:20:53 +0200 | [diff] [blame] | 613 | cat >expected <<EOF |
| 614 | hello.c=int main(int argc, const char **argv) |
| 615 | hello.c-{ |
| 616 | hello.c- printf("Hello world.\n"); |
| 617 | hello.c: return 0; |
| 618 | hello.c- /* char ?? */ |
| 619 | hello.c-} |
| 620 | EOF |
| 621 | |
| 622 | test_expect_success 'grep -W' ' |
| 623 | git grep -W return >actual && |
| 624 | test_cmp expected actual |
| 625 | ' |
| 626 | |
Thomas Rast | b8ffedc | 2011-12-12 22:16:06 +0100 | [diff] [blame] | 627 | cat >expected <<EOF |
| 628 | hello.c= printf("Hello world.\n"); |
| 629 | hello.c: return 0; |
| 630 | hello.c- /* char ?? */ |
| 631 | EOF |
| 632 | |
| 633 | test_expect_success 'grep -W with userdiff' ' |
| 634 | test_when_finished "rm -f .gitattributes" && |
| 635 | git config diff.custom.xfuncname "(printf.*|})$" && |
| 636 | echo "hello.c diff=custom" >.gitattributes && |
| 637 | git grep -W return >actual && |
| 638 | test_cmp expected actual |
| 639 | ' |
| 640 | |
Clemens Buchacher | 493b7a0 | 2009-09-05 14:31:17 +0200 | [diff] [blame] | 641 | test_expect_success 'grep from a subdirectory to search wider area (1)' ' |
| 642 | mkdir -p s && |
| 643 | ( |
| 644 | cd s && git grep "x x x" .. |
| 645 | ) |
| 646 | ' |
| 647 | |
| 648 | test_expect_success 'grep from a subdirectory to search wider area (2)' ' |
| 649 | mkdir -p s && |
| 650 | ( |
| 651 | cd s || exit 1 |
| 652 | ( git grep xxyyzz .. >out ; echo $? >status ) |
| 653 | ! test -s out && |
| 654 | test 1 = $(cat status) |
| 655 | ) |
| 656 | ' |
| 657 | |
Brian Collins | 5183bf6 | 2009-11-06 01:22:35 -0800 | [diff] [blame] | 658 | cat >expected <<EOF |
| 659 | hello.c:int main(int argc, const char **argv) |
| 660 | EOF |
| 661 | |
| 662 | test_expect_success 'grep -Fi' ' |
| 663 | git grep -Fi "CHAR *" >actual && |
| 664 | test_cmp expected actual |
| 665 | ' |
| 666 | |
Junio C Hamano | 59332d1 | 2010-02-06 10:40:08 -0800 | [diff] [blame] | 667 | test_expect_success 'outside of git repository' ' |
| 668 | rm -fr non && |
| 669 | mkdir -p non/git/sub && |
| 670 | echo hello >non/git/file1 && |
| 671 | echo world >non/git/sub/file2 && |
Junio C Hamano | 59332d1 | 2010-02-06 10:40:08 -0800 | [diff] [blame] | 672 | { |
| 673 | echo file1:hello && |
| 674 | echo sub/file2:world |
| 675 | } >non/expect.full && |
Jonathan Nieder | a48fcd8 | 2010-10-30 20:46:54 -0500 | [diff] [blame] | 676 | echo file2:world >non/expect.sub && |
Junio C Hamano | 59332d1 | 2010-02-06 10:40:08 -0800 | [diff] [blame] | 677 | ( |
| 678 | GIT_CEILING_DIRECTORIES="$(pwd)/non/git" && |
| 679 | export GIT_CEILING_DIRECTORIES && |
| 680 | cd non/git && |
| 681 | test_must_fail git grep o && |
| 682 | git grep --no-index o >../actual.full && |
| 683 | test_cmp ../expect.full ../actual.full |
| 684 | cd sub && |
| 685 | test_must_fail git grep o && |
| 686 | git grep --no-index o >../../actual.sub && |
| 687 | test_cmp ../../expect.sub ../../actual.sub |
Junio C Hamano | dbfae86 | 2011-10-04 18:40:41 -0700 | [diff] [blame] | 688 | ) && |
| 689 | |
| 690 | echo ".*o*" >non/git/.gitignore && |
| 691 | ( |
| 692 | GIT_CEILING_DIRECTORIES="$(pwd)/non/git" && |
| 693 | export GIT_CEILING_DIRECTORIES && |
| 694 | cd non/git && |
| 695 | test_must_fail git grep o && |
| 696 | git grep --no-index --exclude-standard o >../actual.full && |
| 697 | test_cmp ../expect.full ../actual.full && |
| 698 | |
| 699 | { |
| 700 | echo ".gitignore:.*o*" |
| 701 | cat ../expect.full |
| 702 | } >../expect.with.ignored && |
| 703 | git grep --no-index --no-exclude o >../actual.full && |
| 704 | test_cmp ../expect.with.ignored ../actual.full |
Junio C Hamano | 59332d1 | 2010-02-06 10:40:08 -0800 | [diff] [blame] | 705 | ) |
| 706 | ' |
| 707 | |
| 708 | test_expect_success 'inside git repository but with --no-index' ' |
| 709 | rm -fr is && |
| 710 | mkdir -p is/git/sub && |
| 711 | echo hello >is/git/file1 && |
| 712 | echo world >is/git/sub/file2 && |
| 713 | echo ".*o*" >is/git/.gitignore && |
| 714 | { |
| 715 | echo file1:hello && |
| 716 | echo sub/file2:world |
Junio C Hamano | dbfae86 | 2011-10-04 18:40:41 -0700 | [diff] [blame] | 717 | } >is/expect.unignored && |
| 718 | { |
| 719 | echo ".gitignore:.*o*" && |
| 720 | cat is/expect.unignored |
Junio C Hamano | 59332d1 | 2010-02-06 10:40:08 -0800 | [diff] [blame] | 721 | } >is/expect.full && |
| 722 | : >is/expect.empty && |
Jonathan Nieder | a48fcd8 | 2010-10-30 20:46:54 -0500 | [diff] [blame] | 723 | echo file2:world >is/expect.sub && |
Junio C Hamano | 59332d1 | 2010-02-06 10:40:08 -0800 | [diff] [blame] | 724 | ( |
| 725 | cd is/git && |
| 726 | git init && |
| 727 | test_must_fail git grep o >../actual.full && |
| 728 | test_cmp ../expect.empty ../actual.full && |
Junio C Hamano | dbfae86 | 2011-10-04 18:40:41 -0700 | [diff] [blame] | 729 | |
| 730 | git grep --untracked o >../actual.unignored && |
| 731 | test_cmp ../expect.unignored ../actual.unignored && |
| 732 | |
Junio C Hamano | 59332d1 | 2010-02-06 10:40:08 -0800 | [diff] [blame] | 733 | git grep --no-index o >../actual.full && |
| 734 | test_cmp ../expect.full ../actual.full && |
Junio C Hamano | dbfae86 | 2011-10-04 18:40:41 -0700 | [diff] [blame] | 735 | |
| 736 | git grep --no-index --exclude-standard o >../actual.unignored && |
| 737 | test_cmp ../expect.unignored ../actual.unignored && |
| 738 | |
Junio C Hamano | 59332d1 | 2010-02-06 10:40:08 -0800 | [diff] [blame] | 739 | cd sub && |
| 740 | test_must_fail git grep o >../../actual.sub && |
| 741 | test_cmp ../../expect.empty ../../actual.sub && |
Junio C Hamano | dbfae86 | 2011-10-04 18:40:41 -0700 | [diff] [blame] | 742 | |
Junio C Hamano | 59332d1 | 2010-02-06 10:40:08 -0800 | [diff] [blame] | 743 | git grep --no-index o >../../actual.sub && |
Junio C Hamano | dbfae86 | 2011-10-04 18:40:41 -0700 | [diff] [blame] | 744 | test_cmp ../../expect.sub ../../actual.sub && |
| 745 | |
| 746 | git grep --untracked o >../../actual.sub && |
Junio C Hamano | 59332d1 | 2010-02-06 10:40:08 -0800 | [diff] [blame] | 747 | test_cmp ../../expect.sub ../../actual.sub |
| 748 | ) |
| 749 | ' |
| 750 | |
Jeff King | 1123c67 | 2010-02-06 23:44:15 -0500 | [diff] [blame] | 751 | test_expect_success 'setup double-dash tests' ' |
| 752 | cat >double-dash <<EOF && |
| 753 | -- |
| 754 | -> |
| 755 | other |
| 756 | EOF |
| 757 | git add double-dash |
| 758 | ' |
| 759 | |
| 760 | cat >expected <<EOF |
| 761 | double-dash:-> |
| 762 | EOF |
| 763 | test_expect_success 'grep -- pattern' ' |
| 764 | git grep -- "->" >actual && |
| 765 | test_cmp expected actual |
| 766 | ' |
| 767 | test_expect_success 'grep -- pattern -- pathspec' ' |
| 768 | git grep -- "->" -- double-dash >actual && |
| 769 | test_cmp expected actual |
| 770 | ' |
| 771 | test_expect_success 'grep -e pattern -- path' ' |
| 772 | git grep -e "->" -- double-dash >actual && |
| 773 | test_cmp expected actual |
| 774 | ' |
| 775 | |
| 776 | cat >expected <<EOF |
| 777 | double-dash:-- |
| 778 | EOF |
| 779 | test_expect_success 'grep -e -- -- path' ' |
| 780 | git grep -e -- -- double-dash >actual && |
| 781 | test_cmp expected actual |
| 782 | ' |
| 783 | |
Michał Kiedrowicz | 8f852ce | 2011-05-09 23:52:07 +0200 | [diff] [blame] | 784 | cat >expected <<EOF |
| 785 | hello.c:int main(int argc, const char **argv) |
| 786 | hello.c: printf("Hello world.\n"); |
| 787 | EOF |
| 788 | |
| 789 | test_expect_success LIBPCRE 'grep --perl-regexp pattern' ' |
| 790 | git grep --perl-regexp "\p{Ps}.*?\p{Pe}" hello.c >actual && |
| 791 | test_cmp expected actual |
| 792 | ' |
| 793 | |
| 794 | test_expect_success LIBPCRE 'grep -P pattern' ' |
| 795 | git grep -P "\p{Ps}.*?\p{Pe}" hello.c >actual && |
| 796 | test_cmp expected actual |
| 797 | ' |
| 798 | |
Michał Kiedrowicz | f556e4a | 2011-05-22 13:37:28 +0200 | [diff] [blame] | 799 | test_expect_success 'grep pattern with grep.extendedRegexp=true' ' |
Michał Kiedrowicz | d0042ab | 2011-05-27 00:43:59 +0200 | [diff] [blame] | 800 | >empty && |
Michał Kiedrowicz | f556e4a | 2011-05-22 13:37:28 +0200 | [diff] [blame] | 801 | test_must_fail git -c grep.extendedregexp=true \ |
| 802 | grep "\p{Ps}.*?\p{Pe}" hello.c >actual && |
| 803 | test_cmp empty actual |
| 804 | ' |
| 805 | |
| 806 | test_expect_success LIBPCRE 'grep -P pattern with grep.extendedRegexp=true' ' |
| 807 | git -c grep.extendedregexp=true \ |
| 808 | grep -P "\p{Ps}.*?\p{Pe}" hello.c >actual && |
| 809 | test_cmp expected actual |
| 810 | ' |
| 811 | |
| 812 | test_expect_success LIBPCRE 'grep -P -v pattern' ' |
| 813 | { |
Michał Kiedrowicz | d0042ab | 2011-05-27 00:43:59 +0200 | [diff] [blame] | 814 | echo "ab:a+b*c" |
| 815 | echo "ab:a+bc" |
Michał Kiedrowicz | f556e4a | 2011-05-22 13:37:28 +0200 | [diff] [blame] | 816 | } >expected && |
Michał Kiedrowicz | d0042ab | 2011-05-27 00:43:59 +0200 | [diff] [blame] | 817 | git grep -P -v "abc" ab >actual && |
Michał Kiedrowicz | f556e4a | 2011-05-22 13:37:28 +0200 | [diff] [blame] | 818 | test_cmp expected actual |
| 819 | ' |
| 820 | |
Michał Kiedrowicz | 8f852ce | 2011-05-09 23:52:07 +0200 | [diff] [blame] | 821 | test_expect_success LIBPCRE 'grep -P -i pattern' ' |
Junio C Hamano | 93d5e0c | 2011-06-20 14:49:34 -0700 | [diff] [blame] | 822 | cat >expected <<-EOF && |
| 823 | hello.c: printf("Hello world.\n"); |
| 824 | EOF |
Michał Kiedrowicz | 8f852ce | 2011-05-09 23:52:07 +0200 | [diff] [blame] | 825 | git grep -P -i "PRINTF\([^\d]+\)" hello.c >actual && |
| 826 | test_cmp expected actual |
| 827 | ' |
| 828 | |
| 829 | test_expect_success LIBPCRE 'grep -P -w pattern' ' |
| 830 | { |
| 831 | echo "hello_world:Hello world" |
| 832 | echo "hello_world:HeLLo world" |
| 833 | } >expected && |
| 834 | git grep -P -w "He((?i)ll)o" hello_world >actual && |
| 835 | test_cmp expected actual |
| 836 | ' |
| 837 | |
Michał Kiedrowicz | f556e4a | 2011-05-22 13:37:28 +0200 | [diff] [blame] | 838 | test_expect_success 'grep -G invalidpattern properly dies ' ' |
| 839 | test_must_fail git grep -G "a[" |
| 840 | ' |
| 841 | |
J Smith | 84befcd | 2012-08-03 10:53:50 -0400 | [diff] [blame] | 842 | test_expect_success 'grep invalidpattern properly dies with grep.patternType=basic' ' |
| 843 | test_must_fail git -c grep.patterntype=basic grep "a[" |
| 844 | ' |
| 845 | |
Michał Kiedrowicz | f556e4a | 2011-05-22 13:37:28 +0200 | [diff] [blame] | 846 | test_expect_success 'grep -E invalidpattern properly dies ' ' |
| 847 | test_must_fail git grep -E "a[" |
| 848 | ' |
| 849 | |
J Smith | 84befcd | 2012-08-03 10:53:50 -0400 | [diff] [blame] | 850 | test_expect_success 'grep invalidpattern properly dies with grep.patternType=extended' ' |
| 851 | test_must_fail git -c grep.patterntype=extended grep "a[" |
| 852 | ' |
| 853 | |
Michał Kiedrowicz | f556e4a | 2011-05-22 13:37:28 +0200 | [diff] [blame] | 854 | test_expect_success LIBPCRE 'grep -P invalidpattern properly dies ' ' |
| 855 | test_must_fail git grep -P "a[" |
| 856 | ' |
| 857 | |
J Smith | 84befcd | 2012-08-03 10:53:50 -0400 | [diff] [blame] | 858 | test_expect_success LIBPCRE 'grep invalidpattern properly dies with grep.patternType=perl' ' |
| 859 | test_must_fail git -c grep.patterntype=perl grep "a[" |
| 860 | ' |
| 861 | |
Michał Kiedrowicz | d0042ab | 2011-05-27 00:43:59 +0200 | [diff] [blame] | 862 | test_expect_success 'grep -G -E -F pattern' ' |
| 863 | echo "ab:a+b*c" >expected && |
| 864 | git grep -G -E -F "a+b*c" ab >actual && |
Michał Kiedrowicz | f556e4a | 2011-05-22 13:37:28 +0200 | [diff] [blame] | 865 | test_cmp expected actual |
| 866 | ' |
| 867 | |
J Smith | 84befcd | 2012-08-03 10:53:50 -0400 | [diff] [blame] | 868 | test_expect_success 'grep pattern with grep.patternType=basic, =extended, =fixed' ' |
| 869 | echo "ab:a+b*c" >expected && |
| 870 | git \ |
| 871 | -c grep.patterntype=basic \ |
| 872 | -c grep.patterntype=extended \ |
| 873 | -c grep.patterntype=fixed \ |
| 874 | grep "a+b*c" ab >actual && |
| 875 | test_cmp expected actual |
| 876 | ' |
| 877 | |
Michał Kiedrowicz | f556e4a | 2011-05-22 13:37:28 +0200 | [diff] [blame] | 878 | test_expect_success 'grep -E -F -G pattern' ' |
Michał Kiedrowicz | d0042ab | 2011-05-27 00:43:59 +0200 | [diff] [blame] | 879 | echo "ab:a+bc" >expected && |
| 880 | git grep -E -F -G "a+b*c" ab >actual && |
Michał Kiedrowicz | f556e4a | 2011-05-22 13:37:28 +0200 | [diff] [blame] | 881 | test_cmp expected actual |
| 882 | ' |
| 883 | |
J Smith | 84befcd | 2012-08-03 10:53:50 -0400 | [diff] [blame] | 884 | test_expect_success 'grep pattern with grep.patternType=extended, =fixed, =basic' ' |
| 885 | echo "ab:a+bc" >expected && |
| 886 | git \ |
| 887 | -c grep.patterntype=extended \ |
| 888 | -c grep.patterntype=fixed \ |
| 889 | -c grep.patterntype=basic \ |
| 890 | grep "a+b*c" ab >actual && |
| 891 | test_cmp expected actual |
| 892 | ' |
| 893 | |
Michał Kiedrowicz | d0042ab | 2011-05-27 00:43:59 +0200 | [diff] [blame] | 894 | test_expect_success 'grep -F -G -E pattern' ' |
| 895 | echo "ab:abc" >expected && |
| 896 | git grep -F -G -E "a+b*c" ab >actual && |
Michał Kiedrowicz | f556e4a | 2011-05-22 13:37:28 +0200 | [diff] [blame] | 897 | test_cmp expected actual |
| 898 | ' |
| 899 | |
J Smith | 84befcd | 2012-08-03 10:53:50 -0400 | [diff] [blame] | 900 | test_expect_success 'grep pattern with grep.patternType=fixed, =basic, =extended' ' |
| 901 | echo "ab:abc" >expected && |
| 902 | git \ |
| 903 | -c grep.patterntype=fixed \ |
| 904 | -c grep.patterntype=basic \ |
| 905 | -c grep.patterntype=extended \ |
| 906 | grep "a+b*c" ab >actual && |
| 907 | test_cmp expected actual |
| 908 | ' |
| 909 | |
Michał Kiedrowicz | d0042ab | 2011-05-27 00:43:59 +0200 | [diff] [blame] | 910 | test_expect_success 'grep -G -F -P -E pattern' ' |
| 911 | >empty && |
| 912 | test_must_fail git grep -G -F -P -E "a\x{2b}b\x{2a}c" ab >actual && |
| 913 | test_cmp empty actual |
Michał Kiedrowicz | f556e4a | 2011-05-22 13:37:28 +0200 | [diff] [blame] | 914 | ' |
| 915 | |
J Smith | 84befcd | 2012-08-03 10:53:50 -0400 | [diff] [blame] | 916 | test_expect_success 'grep pattern with grep.patternType=fixed, =basic, =perl, =extended' ' |
| 917 | >empty && |
| 918 | test_must_fail git \ |
| 919 | -c grep.patterntype=fixed \ |
| 920 | -c grep.patterntype=basic \ |
| 921 | -c grep.patterntype=perl \ |
| 922 | -c grep.patterntype=extended \ |
| 923 | grep "a\x{2b}b\x{2a}c" ab >actual && |
| 924 | test_cmp empty actual |
| 925 | ' |
| 926 | |
Michał Kiedrowicz | d0042ab | 2011-05-27 00:43:59 +0200 | [diff] [blame] | 927 | test_expect_success LIBPCRE 'grep -G -F -E -P pattern' ' |
| 928 | echo "ab:a+b*c" >expected && |
| 929 | git grep -G -F -E -P "a\x{2b}b\x{2a}c" ab >actual && |
Michał Kiedrowicz | f556e4a | 2011-05-22 13:37:28 +0200 | [diff] [blame] | 930 | test_cmp expected actual |
| 931 | ' |
| 932 | |
J Smith | 84befcd | 2012-08-03 10:53:50 -0400 | [diff] [blame] | 933 | test_expect_success LIBPCRE 'grep pattern with grep.patternType=fixed, =basic, =extended, =perl' ' |
| 934 | echo "ab:a+b*c" >expected && |
| 935 | git \ |
| 936 | -c grep.patterntype=fixed \ |
| 937 | -c grep.patterntype=basic \ |
| 938 | -c grep.patterntype=extended \ |
| 939 | -c grep.patterntype=perl \ |
| 940 | grep "a\x{2b}b\x{2a}c" ab >actual && |
| 941 | test_cmp expected actual |
| 942 | ' |
| 943 | |
| 944 | test_expect_success LIBPCRE 'grep -P pattern with grep.patternType=fixed' ' |
| 945 | echo "ab:a+b*c" >expected && |
| 946 | git \ |
| 947 | -c grep.patterntype=fixed \ |
| 948 | grep -P "a\x{2b}b\x{2a}c" ab >actual && |
| 949 | test_cmp expected actual |
| 950 | ' |
| 951 | |
| 952 | test_expect_success 'grep -F pattern with grep.patternType=basic' ' |
| 953 | echo "ab:a+b*c" >expected && |
| 954 | git \ |
| 955 | -c grep.patterntype=basic \ |
| 956 | grep -F "*c" ab >actual && |
| 957 | test_cmp expected actual |
| 958 | ' |
| 959 | |
| 960 | test_expect_success 'grep -G pattern with grep.patternType=fixed' ' |
| 961 | { |
| 962 | echo "ab:a+b*c" |
| 963 | echo "ab:a+bc" |
| 964 | } >expected && |
| 965 | git \ |
| 966 | -c grep.patterntype=fixed \ |
| 967 | grep -G "a+b" ab >actual && |
| 968 | test_cmp expected actual |
| 969 | ' |
| 970 | |
| 971 | test_expect_success 'grep -E pattern with grep.patternType=fixed' ' |
| 972 | { |
| 973 | echo "ab:a+b*c" |
| 974 | echo "ab:a+bc" |
| 975 | echo "ab:abc" |
| 976 | } >expected && |
| 977 | git \ |
| 978 | -c grep.patterntype=fixed \ |
| 979 | grep -E "a+" ab >actual && |
| 980 | test_cmp expected actual |
| 981 | ' |
| 982 | |
René Scharfe | 08303c3 | 2011-06-05 17:24:15 +0200 | [diff] [blame] | 983 | test_config() { |
| 984 | git config "$1" "$2" && |
| 985 | test_when_finished "git config --unset $1" |
| 986 | } |
| 987 | |
| 988 | cat >expected <<EOF |
| 989 | hello.c<RED>:<RESET>int main(int argc, const char **argv) |
| 990 | hello.c<RED>-<RESET>{ |
| 991 | <RED>--<RESET> |
| 992 | hello.c<RED>:<RESET> /* char ?? */ |
| 993 | hello.c<RED>-<RESET>} |
| 994 | <RED>--<RESET> |
| 995 | hello_world<RED>:<RESET>Hello_world |
| 996 | hello_world<RED>-<RESET>HeLLo_world |
| 997 | EOF |
| 998 | |
| 999 | test_expect_success 'grep --color, separator' ' |
| 1000 | test_config color.grep.context normal && |
| 1001 | test_config color.grep.filename normal && |
| 1002 | test_config color.grep.function normal && |
| 1003 | test_config color.grep.linenumber normal && |
| 1004 | test_config color.grep.match normal && |
| 1005 | test_config color.grep.selected normal && |
| 1006 | test_config color.grep.separator red && |
| 1007 | |
| 1008 | git grep --color=always -A1 -e char -e lo_w hello.c hello_world | |
| 1009 | test_decode_color >actual && |
| 1010 | test_cmp expected actual |
| 1011 | ' |
| 1012 | |
René Scharfe | a8f0e76 | 2011-06-05 17:24:25 +0200 | [diff] [blame] | 1013 | cat >expected <<EOF |
| 1014 | hello.c:int main(int argc, const char **argv) |
| 1015 | hello.c: /* char ?? */ |
| 1016 | |
| 1017 | hello_world:Hello_world |
| 1018 | EOF |
| 1019 | |
| 1020 | test_expect_success 'grep --break' ' |
| 1021 | git grep --break -e char -e lo_w hello.c hello_world >actual && |
| 1022 | test_cmp expected actual |
| 1023 | ' |
| 1024 | |
| 1025 | cat >expected <<EOF |
| 1026 | hello.c:int main(int argc, const char **argv) |
| 1027 | hello.c-{ |
| 1028 | -- |
| 1029 | hello.c: /* char ?? */ |
| 1030 | hello.c-} |
| 1031 | |
| 1032 | hello_world:Hello_world |
| 1033 | hello_world-HeLLo_world |
| 1034 | EOF |
| 1035 | |
| 1036 | test_expect_success 'grep --break with context' ' |
| 1037 | git grep --break -A1 -e char -e lo_w hello.c hello_world >actual && |
| 1038 | test_cmp expected actual |
| 1039 | ' |
| 1040 | |
René Scharfe | 1d84f72 | 2011-06-05 17:24:36 +0200 | [diff] [blame] | 1041 | cat >expected <<EOF |
| 1042 | hello.c |
| 1043 | int main(int argc, const char **argv) |
| 1044 | /* char ?? */ |
| 1045 | hello_world |
| 1046 | Hello_world |
| 1047 | EOF |
| 1048 | |
| 1049 | test_expect_success 'grep --heading' ' |
| 1050 | git grep --heading -e char -e lo_w hello.c hello_world >actual && |
| 1051 | test_cmp expected actual |
| 1052 | ' |
| 1053 | |
| 1054 | cat >expected <<EOF |
| 1055 | <BOLD;GREEN>hello.c<RESET> |
| 1056 | 2:int main(int argc, const <BLACK;BYELLOW>char<RESET> **argv) |
| 1057 | 6: /* <BLACK;BYELLOW>char<RESET> ?? */ |
| 1058 | |
| 1059 | <BOLD;GREEN>hello_world<RESET> |
| 1060 | 3:Hel<BLACK;BYELLOW>lo_w<RESET>orld |
| 1061 | EOF |
| 1062 | |
| 1063 | test_expect_success 'mimic ack-grep --group' ' |
| 1064 | test_config color.grep.context normal && |
| 1065 | test_config color.grep.filename "bold green" && |
| 1066 | test_config color.grep.function normal && |
| 1067 | test_config color.grep.linenumber normal && |
| 1068 | test_config color.grep.match "black yellow" && |
| 1069 | test_config color.grep.selected normal && |
| 1070 | test_config color.grep.separator normal && |
| 1071 | |
| 1072 | git grep --break --heading -n --color \ |
| 1073 | -e char -e lo_w hello.c hello_world | |
| 1074 | test_decode_color >actual && |
| 1075 | test_cmp expected actual |
| 1076 | ' |
| 1077 | |
Michał Kiedrowicz | d29d787 | 2012-02-27 17:45:49 +0100 | [diff] [blame] | 1078 | cat >expected <<EOF |
| 1079 | space: line with leading space1 |
| 1080 | space: line with leading space2 |
| 1081 | space: line with leading space3 |
| 1082 | EOF |
| 1083 | |
| 1084 | test_expect_success LIBPCRE 'grep -E "^ "' ' |
| 1085 | git grep -E "^ " space >actual && |
| 1086 | test_cmp expected actual |
| 1087 | ' |
| 1088 | |
| 1089 | test_expect_success LIBPCRE 'grep -P "^ "' ' |
| 1090 | git grep -P "^ " space >actual && |
| 1091 | test_cmp expected actual |
| 1092 | ' |
| 1093 | |
Junio C Hamano | f25b793 | 2006-08-04 22:16:42 -0700 | [diff] [blame] | 1094 | test_done |