xref: /aosp_15_r20/external/toybox/tests/grep.test (revision cf5a6c84e2b8763fc1a7db14496fd4742913b199)
1*cf5a6c84SAndroid Build Coastguard Worker#!/bin/bash
2*cf5a6c84SAndroid Build Coastguard Worker
3*cf5a6c84SAndroid Build Coastguard Worker# TODO: several tests need to check both fast and slow paths
4*cf5a6c84SAndroid Build Coastguard Worker
5*cf5a6c84SAndroid Build Coastguard Worker[ -f testing.sh ] && . testing.sh
6*cf5a6c84SAndroid Build Coastguard Worker
7*cf5a6c84SAndroid Build Coastguard Worker# Copyright 2013 by Kyungsu Kim <[email protected]>
8*cf5a6c84SAndroid Build Coastguard Worker# Copyright 2013 by Kyungwan Han <[email protected]>
9*cf5a6c84SAndroid Build Coastguard Worker
10*cf5a6c84SAndroid Build Coastguard Worker#testing "name" "command" "result" "infile" "stdin"
11*cf5a6c84SAndroid Build Coastguard Worker
12*cf5a6c84SAndroid Build Coastguard Workertestcmd 'simple' 'two' 'two\n' '' 'one\ntwo\nthree\n'
13*cf5a6c84SAndroid Build Coastguard Workertestcmd 'negative' 'a' '' '' '\n'
14*cf5a6c84SAndroid Build Coastguard Workertestcmd 'empty' "''" '\n' '' '\n'
15*cf5a6c84SAndroid Build Coastguard Worker
16*cf5a6c84SAndroid Build Coastguard Workertestcmd "-c" "-c 123 input" "3\n" "123\ncount 123\n123\nfasdfasdf" ""
17*cf5a6c84SAndroid Build Coastguard Worker
18*cf5a6c84SAndroid Build Coastguard Workerecho -e "this is test" > file
19*cf5a6c84SAndroid Build Coastguard Workerecho -e "this is test2" > file2
20*cf5a6c84SAndroid Build Coastguard Workerecho -e "this is number3" > file3
21*cf5a6c84SAndroid Build Coastguard Workertestcmd "-l" "-l test file file2 file3" "file\nfile2\n" "" ""
22*cf5a6c84SAndroid Build Coastguard Workertestcmd "-L" "-L test file file2 file3" "file3\n" "" ""
23*cf5a6c84SAndroid Build Coastguard Workerrm file file2 file3
24*cf5a6c84SAndroid Build Coastguard Worker
25*cf5a6c84SAndroid Build Coastguard Workertestcmd "-q" "-q test input && echo yes" "yes\n" "this is a test\n" ""
26*cf5a6c84SAndroid Build Coastguard Workertestcmd "-E" "-E '[0-9]' input" "1234123asdfas123123\n1\n" \
27*cf5a6c84SAndroid Build Coastguard Worker  "1234123asdfas123123\nabc\n1\nabcde" ""
28*cf5a6c84SAndroid Build Coastguard Workertestcmd "-e" "-e '[0-9]' input" "1234123asdfas123123\n1\n" \
29*cf5a6c84SAndroid Build Coastguard Worker  "1234123asdfas123123\nabc\n1\nabcde" ""
30*cf5a6c84SAndroid Build Coastguard Workertestcmd "-e -e" "-e one -e two -e three input" \
31*cf5a6c84SAndroid Build Coastguard Worker  "two\ntwo\nthree\none\n" "two\ntwo\nthree\nand\none\n" ""
32*cf5a6c84SAndroid Build Coastguard Workertestcmd "-F" "-F is input" "this is test\nthis is test2\n" \
33*cf5a6c84SAndroid Build Coastguard Worker  "this is test\nthis is test2\ntest case" ""
34*cf5a6c84SAndroid Build Coastguard Workertestcmd "-Fo ''" "-Fo ''" "" "" "hello\n"
35*cf5a6c84SAndroid Build Coastguard Workertestcmd "-Fw ''" "-Fw ''" "" "" "hello\n"
36*cf5a6c84SAndroid Build Coastguard Workertestcmd "-Fw '' 2" "-Fw ''" "\n" "" "\n"
37*cf5a6c84SAndroid Build Coastguard Workertestcmd "-F is really fixed" "-F '.[x]'" "c.[x]d\n" "" "axb\nc.[x]d\n"
38*cf5a6c84SAndroid Build Coastguard Worker
39*cf5a6c84SAndroid Build Coastguard Workerecho -e "this is test\nthis is test2\ntest case" > foo
40*cf5a6c84SAndroid Build Coastguard Workerecho -e "hello this is test" > foo2
41*cf5a6c84SAndroid Build Coastguard Workerecho -e "hi hello" > foo3
42*cf5a6c84SAndroid Build Coastguard Workertestcmd "-H" "-H is foo foo2 foo3" \
43*cf5a6c84SAndroid Build Coastguard Worker  "foo:this is test\nfoo:this is test2\nfoo2:hello this is test\n" "" ""
44*cf5a6c84SAndroid Build Coastguard Workerrm foo foo2 foo3
45*cf5a6c84SAndroid Build Coastguard Worker
46*cf5a6c84SAndroid Build Coastguard Workertestcmd "-b" "-b is input" "0:this is test\n13:this is test2\n" \
47*cf5a6c84SAndroid Build Coastguard Worker  "this is test\nthis is test2\ntest case" ""
48*cf5a6c84SAndroid Build Coastguard Workertestcmd "-i" "-i is input" "thisIs test\nthis is test2\n" \
49*cf5a6c84SAndroid Build Coastguard Worker  "thisIs test\nthis is test2\ntest case" ""
50*cf5a6c84SAndroid Build Coastguard Workertestcmd "-n" "-n is input" "1:this is test\n2:this is test2\n" \
51*cf5a6c84SAndroid Build Coastguard Worker  "this is test\nthis is test2\ntest case" ""
52*cf5a6c84SAndroid Build Coastguard Workertestcmd "-o" "-o is input" "is\nis\nis\nis\n" \
53*cf5a6c84SAndroid Build Coastguard Worker  "this is test\nthis is test2\ntest case" ""
54*cf5a6c84SAndroid Build Coastguard Workertestcmd "-s" "-hs hello asdf input 2>&1" "hello\n" "hello\n" ""
55*cf5a6c84SAndroid Build Coastguard Workertestcmd "-v" "-v abc input" "1234123asdfas123123\n1ABa\n" \
56*cf5a6c84SAndroid Build Coastguard Worker  "1234123asdfas123123\n1ABabc\nabc\n1ABa\nabcde" ""
57*cf5a6c84SAndroid Build Coastguard Workertestcmd "-w" "-w abc input" "abc\n123 abc\nabc 123\n123 abc 456\n" \
58*cf5a6c84SAndroid Build Coastguard Worker  "1234123asdfas123123\n1ABabc\nabc\n1ABa\nabcde\n123 abc\nabc 123\n123 abc 456\n" ""
59*cf5a6c84SAndroid Build Coastguard Workertestcmd "-x" "-x abc input" "abc\n" "aabcc\nabc\n" ""
60*cf5a6c84SAndroid Build Coastguard Worker
61*cf5a6c84SAndroid Build Coastguard Workertestcmd "-H (standard input)" "-H abc" "(standard input):abc\n" "" "abc\n"
62*cf5a6c84SAndroid Build Coastguard Workertestcmd "-l (standard input)" "-l abc" "(standard input)\n" "" "abc\n"
63*cf5a6c84SAndroid Build Coastguard Workertestcmd "-n two inputs" "-hn def - input" "2:def\n2:def\n" \
64*cf5a6c84SAndroid Build Coastguard Worker  "abc\ndef\n" "abc\ndef\n"
65*cf5a6c84SAndroid Build Coastguard Worker
66*cf5a6c84SAndroid Build Coastguard Workertestcmd "pattern with newline" $'"abc\ndef" input' "aabcc\nddeff\n" \
67*cf5a6c84SAndroid Build Coastguard Worker  "aaaa\naabcc\n\dddd\nddeff\nffff\n" ""
68*cf5a6c84SAndroid Build Coastguard Worker
69*cf5a6c84SAndroid Build Coastguard Workertestcmd "-lH" "-lH abc input" "input\n" "abc\n" ""
70*cf5a6c84SAndroid Build Coastguard Workertestcmd "-cn" "-cn abc input" "1\n" "abc\n" ""
71*cf5a6c84SAndroid Build Coastguard Workertestcmd "-cH" "-cH abc input" "input:1\n" "abc\n" ""
72*cf5a6c84SAndroid Build Coastguard Workertestcmd "-qs" "-qs abc none input && echo yes" "yes\n" "abc\n" ""
73*cf5a6c84SAndroid Build Coastguard Workertestcmd "-hl" "-hl abc input" "input\n" "abc\n" ""
74*cf5a6c84SAndroid Build Coastguard Workertestcmd "-b stdin" "-b one" "0:one\n4:one\n8:one\n" "" "one\none\none\n"
75*cf5a6c84SAndroid Build Coastguard Workertestcmd "-o overlap" "-bo aaa" "1:aaa\n" "" "baaaa\n"
76*cf5a6c84SAndroid Build Coastguard Worker# nonobvious: -co counts lines, not matches
77*cf5a6c84SAndroid Build Coastguard Workertestcmd "-co" "-co one input" "1\n" "one one one\n" ""
78*cf5a6c84SAndroid Build Coastguard Workertestcmd "-nom" "-nom 2 one" "1:one\n1:one\n1:one\n2:one\n2:one\n" \
79*cf5a6c84SAndroid Build Coastguard Worker  "" "one one one\none one\none"
80*cf5a6c84SAndroid Build Coastguard Workertoyonly testcmd "-vo" "-vo one input" "two\nthree\n" "onetwoonethreeone\n" ""
81*cf5a6c84SAndroid Build Coastguard Workertestcmd "no newline" "-h one input -" \
82*cf5a6c84SAndroid Build Coastguard Worker  "hello one\nthere one\n" "hello one" "there one"
83*cf5a6c84SAndroid Build Coastguard Worker
84*cf5a6c84SAndroid Build Coastguard Workertestcmd "-e multi" "-e one -ethree input" "three\none\n" "three\ntwo\none\n" ""
85*cf5a6c84SAndroid Build Coastguard Worker# Suppress filenames for recursive test because dunno order they'd occur in
86*cf5a6c84SAndroid Build Coastguard Workermkdir sub
87*cf5a6c84SAndroid Build Coastguard Workerecho -e "one\ntwo\nthree" > sub/one
88*cf5a6c84SAndroid Build Coastguard Workerecho -e "three\ntwo\none" > sub/two
89*cf5a6c84SAndroid Build Coastguard Workertestcmd "-hr" "-hr one sub" "one\none\n" "" ""
90*cf5a6c84SAndroid Build Coastguard Workertestcmd "-r file" "-r three sub/two" "three\n" "" ""
91*cf5a6c84SAndroid Build Coastguard Workertestcmd "-r dir" "-r one sub | sort" "sub/one:one\nsub/two:one\n" \
92*cf5a6c84SAndroid Build Coastguard Worker  "" ""
93*cf5a6c84SAndroid Build Coastguard Workerrm -rf sub
94*cf5a6c84SAndroid Build Coastguard Worker
95*cf5a6c84SAndroid Build Coastguard Worker# -x exact match overrides -F's "empty string matches whole line" behavior
96*cf5a6c84SAndroid Build Coastguard Workertestcmd "-Fx ''" "-Fx '' input" "" "one one one\n" ""
97*cf5a6c84SAndroid Build Coastguard Workertestcmd "-F ''" "-F '' input" "one one one\n" "one one one\n" ""
98*cf5a6c84SAndroid Build Coastguard Workertestcmd "-F -e blah -e ''" "-F -e blah -e '' input" "one one one\n" \
99*cf5a6c84SAndroid Build Coastguard Worker  "one one one\n" ""
100*cf5a6c84SAndroid Build Coastguard Workertestcmd "-Fxv -e subset" "-Fxv -e bbswitch-dkms -e dkms" "" "" "bbswitch-dkms\n"
101*cf5a6c84SAndroid Build Coastguard Workertestcmd "-e blah -e ''" "-e blah -e '' input" "one one one\n" "one one one\n" ""
102*cf5a6c84SAndroid Build Coastguard Workertestcmd "-w ''" "-w '' input" "" "one one one\n" ""
103*cf5a6c84SAndroid Build Coastguard Workertestcmd "-w '' 2" "-w '' input" "one  two\n" "one  two\n" ""
104*cf5a6c84SAndroid Build Coastguard Worker#testcmd "-w '' 3" "-w ''" "one  two\n" "one  two\n" ""
105*cf5a6c84SAndroid Build Coastguard Workertestcmd "'$' is ''" "'\$'" 'potato\n' '' 'potato\n'
106*cf5a6c84SAndroid Build Coastguard Workertestcmd "'$' is '' 2" "'x*\$'" 'potato\n' '' 'potato\n'
107*cf5a6c84SAndroid Build Coastguard Workertestcmd "-w '$'" "-w '\$'" '' '' 'abc  abc\n'
108*cf5a6c84SAndroid Build Coastguard Workertestcmd "-w '$' 2" "-w '\$'" 'abc \n' '' 'abc \n'
109*cf5a6c84SAndroid Build Coastguard Workertestcmd "'^' is ''" "'^'" 'potato\n' '' 'potato\n'
110*cf5a6c84SAndroid Build Coastguard Workertestcmd "'^' is '' 2" "'^x*'" 'potato\n' '' 'potato\n'
111*cf5a6c84SAndroid Build Coastguard Workertestcmd "-w '^'" "-w '^'" '' '' 'abc  abc\n'
112*cf5a6c84SAndroid Build Coastguard Workertestcmd "-w '^' 2" "-w '^'" ' abc\n' '' ' abc\n'
113*cf5a6c84SAndroid Build Coastguard Workertestcmd "-w \\1" "-wo '\\(x\\)\\1'" "xx\n" "" "xx"
114*cf5a6c84SAndroid Build Coastguard Workertestcmd '' "-nw ''" '1:\n3: \n4:a \n5: a\n7:a  a\n' '' \
115*cf5a6c84SAndroid Build Coastguard Worker  '\na\n \na \n a\na a\na  a'
116*cf5a6c84SAndroid Build Coastguard Workertestcmd '' "-nw '^'" '1:\n3: \n5: a\n' '' '\na\n \na \n a\na a\na  a'
117*cf5a6c84SAndroid Build Coastguard Workertestcmd '' "-nw '\$'" '1:\n3: \n4:a \n' '' '\na\n \na \n a\na a\na  a'
118*cf5a6c84SAndroid Build Coastguard Workertestcmd '' "-nw '^\$'" '1:\n' '' '\na\n \na \n a\na a\na  a'
119*cf5a6c84SAndroid Build Coastguard Workertestcmd "-o ''" "-o '' input" "" "one one one\n" ""
120*cf5a6c84SAndroid Build Coastguard Workertestcmd "backref" '-e "a\(b\)" -e "b\(c\)\1"' "bcc\nab\n" "" "bcc\nbcb\nab\n"
121*cf5a6c84SAndroid Build Coastguard Worker
122*cf5a6c84SAndroid Build Coastguard Workertestcmd "-A" "-A 2 yes" "yes\nno\nno\n--\nyes\nno\nno\nyes\nno\n" \
123*cf5a6c84SAndroid Build Coastguard Worker  "" "yes\nno\nno\nno\nyes\nno\nno\nyes\nno"
124*cf5a6c84SAndroid Build Coastguard Workertestcmd "-B" "-B 1 yes" "no\nyes\n--\nno\nyes\nno\nyes\n" \
125*cf5a6c84SAndroid Build Coastguard Worker  "" "no\nno\nno\nyes\nno\nno\nyes\nno\nyes"
126*cf5a6c84SAndroid Build Coastguard Workertestcmd "-C" "-C 1 yes" "yes\nno\n--\nno\nyes\nno\nno\nyes\nno\nyes\nno\n" \
127*cf5a6c84SAndroid Build Coastguard Worker  "" "yes\nno\nno\nno\nyes\nno\nno\nyes\nno\nyes\nno\nno"
128*cf5a6c84SAndroid Build Coastguard Workertestcmd "-HnC" "-HnC1 two" \
129*cf5a6c84SAndroid Build Coastguard Worker  "(standard input)-1-one\n(standard input):2:two\n(standard input)-3-three\n" \
130*cf5a6c84SAndroid Build Coastguard Worker  "" "one\ntwo\nthree"
131*cf5a6c84SAndroid Build Coastguard Worker
132*cf5a6c84SAndroid Build Coastguard Worker# Context lines weren't showing -b
133*cf5a6c84SAndroid Build Coastguard Workertestcmd "-HnbB1" "-HnbB1 f input" \
134*cf5a6c84SAndroid Build Coastguard Worker  "input-3-8-three\ninput:4:14:four\ninput:5:19:five\n" \
135*cf5a6c84SAndroid Build Coastguard Worker  "one\ntwo\nthree\nfour\nfive\n" ""
136*cf5a6c84SAndroid Build Coastguard Worker
137*cf5a6c84SAndroid Build Coastguard Workertestcmd "-q match overrides error" \
138*cf5a6c84SAndroid Build Coastguard Worker  "-q hello missing input 2>/dev/null && echo yes" "yes\n" "hello\n" ""
139*cf5a6c84SAndroid Build Coastguard Workertestcmd "-q not found is 1" '-q hello input || echo $?' "1\n" "x" ""
140*cf5a6c84SAndroid Build Coastguard Workertestcmd "-q missing is 2" \
141*cf5a6c84SAndroid Build Coastguard Worker  '-q hello missing missing 2>/dev/null || echo $?' "2\n" "" ""
142*cf5a6c84SAndroid Build Coastguard Workertestcmd "-q missing survives exists but not found" \
143*cf5a6c84SAndroid Build Coastguard Worker  '-q hello missing missing input 2>/dev/null || echo $?' "2\n" "" ""
144*cf5a6c84SAndroid Build Coastguard Workertestcmd "not found retained past match" \
145*cf5a6c84SAndroid Build Coastguard Worker  'hello missing input 2>/dev/null || echo $?' "input:hello\n2\n" "hello\n" ""
146*cf5a6c84SAndroid Build Coastguard Workertouch empty
147*cf5a6c84SAndroid Build Coastguard Workertestcmd "one match good enough for 0" \
148*cf5a6c84SAndroid Build Coastguard Worker  'hello input empty && echo $?' 'input:hello\n0\n' 'hello\n' ''
149*cf5a6c84SAndroid Build Coastguard Workerrm empty
150*cf5a6c84SAndroid Build Coastguard Worker
151*cf5a6c84SAndroid Build Coastguard Workertestcmd "-o ''" "-o ''" "" "" "one two three\none two\none\n"
152*cf5a6c84SAndroid Build Coastguard Workertestcmd '' "-o -e '' -e two" "two\ntwo\n" "" "one two three\none two\none\n"
153*cf5a6c84SAndroid Build Coastguard Worker
154*cf5a6c84SAndroid Build Coastguard Workerecho "one\ntwo\nthree" > test
155*cf5a6c84SAndroid Build Coastguard Workertestcmd "-l overrides -C" "-l -C1 two test input" "test\ninput\n" \
156*cf5a6c84SAndroid Build Coastguard Worker  "three\ntwo\none\n" ""
157*cf5a6c84SAndroid Build Coastguard Workerrm test
158*cf5a6c84SAndroid Build Coastguard Worker
159*cf5a6c84SAndroid Build Coastguard Worker# match after NUL byte
160*cf5a6c84SAndroid Build Coastguard Workertestcmd "match after NUL byte" "-a two" "one\0and two three\n" \
161*cf5a6c84SAndroid Build Coastguard Worker  "" 'one\0and two three'
162*cf5a6c84SAndroid Build Coastguard Worker
163*cf5a6c84SAndroid Build Coastguard Worker# BREs versus EREs
164*cf5a6c84SAndroid Build Coastguard Workertestcmd "implicit BRE |" "'uno|dos'" "uno|dos\n" "" "uno\ndos\nuno|dos\n"
165*cf5a6c84SAndroid Build Coastguard Workertestcmd "explicit BRE |" "-e 'uno|dos'" "uno|dos\n" "" "uno\ndos\nuno|dos\n"
166*cf5a6c84SAndroid Build Coastguard Workertestcmd "explicit ERE |" "-E 'uno|dos'" "uno\ndos\nuno|dos\n" \
167*cf5a6c84SAndroid Build Coastguard Worker  "" "uno\ndos\nuno|dos\n"
168*cf5a6c84SAndroid Build Coastguard Worker
169*cf5a6c84SAndroid Build Coastguard Workertestcmd "" "-o -e iss -e ipp" "iss\niss\nipp\n" "" "mississippi"
170*cf5a6c84SAndroid Build Coastguard Workertestcmd "" "-o -e gum -e rgu" "rgu\n" "" "argument"
171*cf5a6c84SAndroid Build Coastguard Worker
172*cf5a6c84SAndroid Build Coastguard Workertestcmd "early failure" '--what 2>/dev/null || echo $?' "2\n" "" ""
173*cf5a6c84SAndroid Build Coastguard Worker
174*cf5a6c84SAndroid Build Coastguard Workertestcmd "" 'abc ; echo $?' "abcdef\n0\n" "" "abcdef\n"
175*cf5a6c84SAndroid Build Coastguard Workertestcmd "" 'abc doesnotexist input 2>/dev/null; echo $?' \
176*cf5a6c84SAndroid Build Coastguard Worker  "input:abcdef\n2\n" "abcdef\n" ""
177*cf5a6c84SAndroid Build Coastguard Workermkdir sub
178*cf5a6c84SAndroid Build Coastguard Workerln -s nope sub/link
179*cf5a6c84SAndroid Build Coastguard Workertestcmd "" '-r walrus sub 2>/dev/null; echo $?' "1\n" "" ""
180*cf5a6c84SAndroid Build Coastguard Workerrm -rf sub
181*cf5a6c84SAndroid Build Coastguard Worker
182*cf5a6c84SAndroid Build Coastguard Worker# --exclude-dir
183*cf5a6c84SAndroid Build Coastguard Workermkdir -p sub/yes
184*cf5a6c84SAndroid Build Coastguard Workerecho "hello world" > sub/yes/test
185*cf5a6c84SAndroid Build Coastguard Workermkdir sub/no
186*cf5a6c84SAndroid Build Coastguard Workerecho "hello world" > sub/no/test
187*cf5a6c84SAndroid Build Coastguard Workertestcmd "--exclude-dir" '--exclude-dir=no -r world sub' \
188*cf5a6c84SAndroid Build Coastguard Worker  "sub/yes/test:hello world\n" "" ""
189*cf5a6c84SAndroid Build Coastguard Workerrm -rf sub
190*cf5a6c84SAndroid Build Coastguard Worker
191*cf5a6c84SAndroid Build Coastguard Worker# -r and -R differ in that -R will dereference symlinks to directories.
192*cf5a6c84SAndroid Build Coastguard Workermkdir dir
193*cf5a6c84SAndroid Build Coastguard Workerecho "hello" > dir/f
194*cf5a6c84SAndroid Build Coastguard Workermkdir sub
195*cf5a6c84SAndroid Build Coastguard Workerln -s ../dir sub/link
196*cf5a6c84SAndroid Build Coastguard Workertestcmd "" "-rh hello sub 2>/dev/null || echo err" "err\n" "" ""
197*cf5a6c84SAndroid Build Coastguard Workertestcmd "" "-Rh hello sub" "hello\n" "" ""
198*cf5a6c84SAndroid Build Coastguard Workerrm -rf sub real
199*cf5a6c84SAndroid Build Coastguard Worker
200*cf5a6c84SAndroid Build Coastguard Worker# -F multiple matches
201*cf5a6c84SAndroid Build Coastguard Workertestcmd "-F multiple" "-F h input" "this is hello\nthis is world\n" \
202*cf5a6c84SAndroid Build Coastguard Worker  "missing\nthis is hello\nthis is world\nmissing" ""
203*cf5a6c84SAndroid Build Coastguard Workertestcmd "-Fi multiple" "-Fi h input" "this is HELLO\nthis is WORLD\n" \
204*cf5a6c84SAndroid Build Coastguard Worker  "missing\nthis is HELLO\nthis is WORLD\nmissing" ""
205*cf5a6c84SAndroid Build Coastguard Workertestcmd "-F empty multiple" "-Fi '' input" \
206*cf5a6c84SAndroid Build Coastguard Worker  "missing\nthis is HELLO\nthis is WORLD\nmissing\n" \
207*cf5a6c84SAndroid Build Coastguard Worker  "missing\nthis is HELLO\nthis is WORLD\nmissing" ""
208*cf5a6c84SAndroid Build Coastguard Workertestcmd "-Fx" "-Fx h input" "h\n" \
209*cf5a6c84SAndroid Build Coastguard Worker  "missing\nH\nthis is hello\nthis is world\nh\nmissing" ""
210*cf5a6c84SAndroid Build Coastguard Workertestcmd "-Fix" "-Fix h input" "H\nh\n" \
211*cf5a6c84SAndroid Build Coastguard Worker  "missing\nH\nthis is HELLO\nthis is WORLD\nh\nmissing" ""
212*cf5a6c84SAndroid Build Coastguard Workertestcmd "-F bucket sort" "-F '\.zip'" '\\.zip\n' '' '\\.zip\n'
213*cf5a6c84SAndroid Build Coastguard Workertestcmd "-f /dev/null" "-f /dev/null" "" "" "hello\n"
214*cf5a6c84SAndroid Build Coastguard Worker
215*cf5a6c84SAndroid Build Coastguard Worker# -z doesn't apply to the \n in -e or -f patterns
216*cf5a6c84SAndroid Build Coastguard Worker# Because x\n becomes "x" and "" the second of which matches every line.
217*cf5a6c84SAndroid Build Coastguard Workertestcmd '-z patter\n' "-ze $'x\n' | xxd -pc0" \
218*cf5a6c84SAndroid Build Coastguard Worker  '6f6e650a74776f0a74687265650a00\n' '' 'one\ntwo\nthree\n'
219*cf5a6c84SAndroid Build Coastguard Workertestcmd "-z patter\n 2" "-zof input | xxd -pc0" "69007400\n" "i\nt" "hi\nthere"
220*cf5a6c84SAndroid Build Coastguard Workertestcmd '-lZ' '-lZ ^t input' 'input\0' 'one\ntwo' ''
221*cf5a6c84SAndroid Build Coastguard Worker
222*cf5a6c84SAndroid Build Coastguard Worker# other implementations get this wrong without -a, but right with -a???
223*cf5a6c84SAndroid Build Coastguard Workertoyonly testcmd '-l ^ after \0' '-l ^t' '' 'one\0two' ''
224*cf5a6c84SAndroid Build Coastguard Worker
225*cf5a6c84SAndroid Build Coastguard Workertestcmd "print zero length match" "'[0-9]*'" "abc\n" "" "abc\n"
226*cf5a6c84SAndroid Build Coastguard Workertestcmd "-o skip zero length match" "-o '[0-9]*'" "1234\n" "" "a1234b"
227*cf5a6c84SAndroid Build Coastguard Worker# Bit of a hack, but other greps insert gratuitous \e[K clear-to-EOL
228*cf5a6c84SAndroid Build Coastguard Workertestcmd "--color highlights all matches" \
229*cf5a6c84SAndroid Build Coastguard Worker  "--color=always def | grep -o '[[][0-9;]*[Km]def.[[]m' | wc -l" \
230*cf5a6c84SAndroid Build Coastguard Worker  "2\n" "" "abcdefghidefjkl\n"
231*cf5a6c84SAndroid Build Coastguard Workerseq 1 100002 | base64 > testfile
232*cf5a6c84SAndroid Build Coastguard Workertesting "speed" "timeout 5 grep -f testfile testfile 2>/dev/null | wc -l" \
233*cf5a6c84SAndroid Build Coastguard Worker  "10332\n" "" ""
234*cf5a6c84SAndroid Build Coastguard Workerrm -f testfile
235*cf5a6c84SAndroid Build Coastguard Worker
236*cf5a6c84SAndroid Build Coastguard Worker# Fast path tests
237*cf5a6c84SAndroid Build Coastguard Worker
238*cf5a6c84SAndroid Build Coastguard Workertestcmd 'initial \' '\\.jar' 'bell.jar\n' '' 'bell.jar\n'
239*cf5a6c84SAndroid Build Coastguard Workertestcmd '^$' '^\$' '\n' '' 'one\n\ntwo\n'
240*cf5a6c84SAndroid Build Coastguard Workertestcmd 'middle ^ not special' 'a^' 'a^b\n' '' 'a^b\nb^a\n'
241*cf5a6c84SAndroid Build Coastguard Worker# Quoted to protect it from the shell, grep should just see '$b'
242*cf5a6c84SAndroid Build Coastguard Workertestcmd 'middle $ not special' "'\$b'" 'a$b\n' '' 'a$b\nb$a\n'
243*cf5a6c84SAndroid Build Coastguard Worker
244*cf5a6c84SAndroid Build Coastguard Workertestcmd 'grep -of' '-of input' 'abc\n' 'a.c\n' 'abcdef\n'
245*cf5a6c84SAndroid Build Coastguard Worker
246*cf5a6c84SAndroid Build Coastguard Workertestcmd '-A with -m' '-A1 -m2 match' 'match\n1\nmatch\n2\n' '' \
247*cf5a6c84SAndroid Build Coastguard Worker  'match\n1\nmatch\n2\nmatch\n3\n'
248*cf5a6c84SAndroid Build Coastguard Worker
249*cf5a6c84SAndroid Build Coastguard Workermkdir sub
250*cf5a6c84SAndroid Build Coastguard Workermkfifo -m 600 sub/blah
251*cf5a6c84SAndroid Build Coastguard Workerecho found > sub/found
252*cf5a6c84SAndroid Build Coastguard Workertestcmd "don't block on FIFO" '-rh found sub && echo done' 'found\ndone\n' '' ''
253*cf5a6c84SAndroid Build Coastguard Workerrm -rf sub
254