Documentation/SubmittingPatches: What's Acked-by and Tested-by?
[git/dscho.git] / t / t7002-grep.sh
blobc8b4f65f380f3941c75bd6ed52975777d2b28d67
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 x x xx x >x &&
20 echo y yy >y &&
21 echo zzz > z &&
22 mkdir t &&
23 echo test >t/t &&
24 git add file x y z t/t &&
25 git commit -m initial
28 for H in HEAD ''
30 case "$H" in
31 HEAD) HC='HEAD:' L='HEAD' ;;
32 '') HC= L='in working tree' ;;
33 esac
35 test_expect_success "grep -w $L" '
37 echo ${HC}file:1:foo mmap bar
38 echo ${HC}file:3:foo_mmap bar mmap
39 echo ${HC}file:4:foo mmap bar_mmap
40 echo ${HC}file:5:foo_mmap bar mmap baz
41 } >expected &&
42 git grep -n -w -e mmap $H >actual &&
43 diff expected actual
46 test_expect_success "grep -w $L (x)" '
48 echo ${HC}x:1:x x xx x
49 } >expected &&
50 git grep -n -w -e "x xx* x" $H >actual &&
51 diff expected actual
54 test_expect_success "grep -w $L (y-1)" '
56 echo ${HC}y:1:y yy
57 } >expected &&
58 git grep -n -w -e "^y" $H >actual &&
59 diff expected actual
62 test_expect_success "grep -w $L (y-2)" '
63 : >expected &&
64 if git grep -n -w -e "^y y" $H >actual
65 then
66 echo should not have matched
67 cat actual
68 false
69 else
70 diff expected actual
74 test_expect_success "grep -w $L (z)" '
75 : >expected &&
76 if git grep -n -w -e "^z" $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 $L (t-1)" '
87 echo "${HC}t/t:1:test" >expected &&
88 git grep -n -e test $H >actual &&
89 diff expected actual
92 test_expect_success "grep $L (t-2)" '
93 echo "${HC}t:1:test" >expected &&
95 cd t &&
96 git grep -n -e test $H
97 ) >actual &&
98 diff expected actual
101 test_expect_success "grep $L (t-3)" '
102 echo "${HC}t/t:1:test" >expected &&
104 cd t &&
105 git grep --full-name -n -e test $H
106 ) >actual &&
107 diff expected actual
110 test_expect_success "grep -c $L (no /dev/null)" '
111 ! git grep -c test $H | grep -q /dev/null
114 done
116 test_done