grep: fix word-regexp at the beginning of lines
[git/raj.git] / t / t7002-grep.sh
blobf275af82403dc0f1de4c584074c0eb63e61a6704
1 #!/bin/sh
3 # Copyright (c) 2006 Junio C Hamano
6 test_description='git grep various.
9 . ./test-lib.sh
11 test_expect_success setup '
13 echo foo mmap bar
14 echo foo_mmap bar
15 echo foo_mmap bar mmap
16 echo foo mmap bar_mmap
17 echo foo_mmap bar mmap baz
18 } >file &&
19 echo ww w >w &&
20 echo x x xx x >x &&
21 echo y yy >y &&
22 echo zzz > z &&
23 mkdir t &&
24 echo test >t/t &&
25 git add file w x y z t/t &&
26 test_tick &&
27 git commit -m initial
30 test_expect_success 'grep should not segfault with a bad input' '
31 test_must_fail git grep "("
34 for H in HEAD ''
36 case "$H" in
37 HEAD) HC='HEAD:' L='HEAD' ;;
38 '') HC= L='in working tree' ;;
39 esac
41 test_expect_success "grep -w $L" '
43 echo ${HC}file:1:foo mmap bar
44 echo ${HC}file:3:foo_mmap bar mmap
45 echo ${HC}file:4:foo mmap bar_mmap
46 echo ${HC}file:5:foo_mmap bar mmap baz
47 } >expected &&
48 git grep -n -w -e mmap $H >actual &&
49 diff expected actual
52 test_expect_success "grep -w $L (w)" '
53 : >expected &&
54 ! git grep -n -w -e "^w" >actual &&
55 test_cmp expected actual
58 test_expect_success "grep -w $L (x)" '
60 echo ${HC}x:1:x x xx x
61 } >expected &&
62 git grep -n -w -e "x xx* x" $H >actual &&
63 diff expected actual
66 test_expect_success "grep -w $L (y-1)" '
68 echo ${HC}y:1:y yy
69 } >expected &&
70 git grep -n -w -e "^y" $H >actual &&
71 diff expected actual
74 test_expect_success "grep -w $L (y-2)" '
75 : >expected &&
76 if git grep -n -w -e "^y y" $H >actual
77 then
78 echo should not have matched
79 cat actual
80 false
81 else
82 diff expected actual
86 test_expect_success "grep -w $L (z)" '
87 : >expected &&
88 if git grep -n -w -e "^z" $H >actual
89 then
90 echo should not have matched
91 cat actual
92 false
93 else
94 diff expected actual
98 test_expect_success "grep $L (t-1)" '
99 echo "${HC}t/t:1:test" >expected &&
100 git grep -n -e test $H >actual &&
101 diff expected actual
104 test_expect_success "grep $L (t-2)" '
105 echo "${HC}t:1:test" >expected &&
107 cd t &&
108 git grep -n -e test $H
109 ) >actual &&
110 diff expected actual
113 test_expect_success "grep $L (t-3)" '
114 echo "${HC}t/t:1:test" >expected &&
116 cd t &&
117 git grep --full-name -n -e test $H
118 ) >actual &&
119 diff expected actual
122 test_expect_success "grep -c $L (no /dev/null)" '
123 ! git grep -c test $H | grep /dev/null
126 done
128 test_expect_success 'log grep setup' '
129 echo a >>file &&
130 test_tick &&
131 GIT_AUTHOR_NAME="With * Asterisk" \
132 GIT_AUTHOR_EMAIL="xyzzy@frotz.com" \
133 git commit -a -m "second" &&
135 echo a >>file &&
136 test_tick &&
137 git commit -a -m "third"
141 test_expect_success 'log grep (1)' '
142 git log --author=author --pretty=tformat:%s >actual &&
143 ( echo third ; echo initial ) >expect &&
144 test_cmp expect actual
147 test_expect_success 'log grep (2)' '
148 git log --author=" * " -F --pretty=tformat:%s >actual &&
149 ( echo second ) >expect &&
150 test_cmp expect actual
153 test_expect_success 'log grep (3)' '
154 git log --author="^A U" --pretty=tformat:%s >actual &&
155 ( echo third ; echo initial ) >expect &&
156 test_cmp expect actual
159 test_expect_success 'log grep (4)' '
160 git log --author="frotz\.com>$" --pretty=tformat:%s >actual &&
161 ( echo second ) >expect &&
162 test_cmp expect actual
165 test_expect_success 'log grep (5)' '
166 git log --author=Thor -F --grep=Thu --pretty=tformat:%s >actual &&
167 ( echo third ; echo initial ) >expect &&
168 test_cmp expect actual
171 test_expect_success 'log grep (6)' '
172 git log --author=-0700 --pretty=tformat:%s >actual &&
173 >expect &&
174 test_cmp expect actual
177 test_expect_success 'grep with CE_VALID file' '
178 git update-index --assume-unchanged t/t &&
179 rm t/t &&
180 test "$(git grep --no-ext-grep t)" = "t/t:test" &&
181 git update-index --no-assume-unchanged t/t &&
182 git checkout t/t
185 test_done