t_grep.sh revision 1.3 1 1.3 christos # $NetBSD: t_grep.sh,v 1.3 2017/01/14 20:43:52 christos Exp $
2 1.1 jruoho #
3 1.1 jruoho # Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
4 1.1 jruoho # All rights reserved.
5 1.1 jruoho #
6 1.1 jruoho # Redistribution and use in source and binary forms, with or without
7 1.1 jruoho # modification, are permitted provided that the following conditions
8 1.1 jruoho # are met:
9 1.1 jruoho # 1. Redistributions of source code must retain the above copyright
10 1.1 jruoho # notice, this list of conditions and the following disclaimer.
11 1.1 jruoho # 2. Redistributions in binary form must reproduce the above copyright
12 1.1 jruoho # notice, this list of conditions and the following disclaimer in the
13 1.1 jruoho # documentation and/or other materials provided with the distribution.
14 1.1 jruoho #
15 1.1 jruoho # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 1.1 jruoho # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 1.1 jruoho # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 1.1 jruoho # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 1.1 jruoho # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 1.1 jruoho # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 1.1 jruoho # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 1.1 jruoho # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 1.1 jruoho # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 1.1 jruoho # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 1.1 jruoho # POSSIBILITY OF SUCH DAMAGE.
26 1.1 jruoho #
27 1.1 jruoho
28 1.1 jruoho atf_test_case basic
29 1.1 jruoho basic_head()
30 1.1 jruoho {
31 1.1 jruoho atf_set "descr" "Checks basic functionality"
32 1.1 jruoho }
33 1.1 jruoho basic_body()
34 1.1 jruoho {
35 1.1 jruoho atf_check -o file:"$(atf_get_srcdir)/d_basic.out" -x \
36 1.1 jruoho 'jot 10000 | grep 123'
37 1.1 jruoho }
38 1.1 jruoho
39 1.1 jruoho atf_test_case binary
40 1.1 jruoho binary_head()
41 1.1 jruoho {
42 1.1 jruoho atf_set "descr" "Checks handling of binary files"
43 1.1 jruoho }
44 1.1 jruoho binary_body()
45 1.1 jruoho {
46 1.3 christos dd if=/dev/zero count=1 of=test.file
47 1.3 christos echo -n "foobar" >> test.file
48 1.3 christos atf_check -o file:"$(atf_get_srcdir)/d_binary.out" grep foobar test.file
49 1.1 jruoho }
50 1.1 jruoho
51 1.1 jruoho atf_test_case recurse
52 1.1 jruoho recurse_head()
53 1.1 jruoho {
54 1.1 jruoho atf_set "descr" "Checks recursive searching"
55 1.1 jruoho }
56 1.1 jruoho recurse_body()
57 1.1 jruoho {
58 1.1 jruoho mkdir -p recurse/a/f recurse/d
59 1.1 jruoho echo -e "cod\ndover sole\nhaddock\nhalibut\npilchard" > recurse/d/fish
60 1.1 jruoho echo -e "cod\nhaddock\nplaice" > recurse/a/f/favourite-fish
61 1.1 jruoho
62 1.3 christos atf_check -o file:"$(atf_get_srcdir)/d_recurse.out" -x "grep -r haddock recurse | sort"
63 1.1 jruoho }
64 1.1 jruoho
65 1.1 jruoho atf_test_case recurse_symlink
66 1.1 jruoho recurse_symlink_head()
67 1.1 jruoho {
68 1.1 jruoho atf_set "descr" "Checks symbolic link recursion"
69 1.1 jruoho }
70 1.1 jruoho recurse_symlink_body()
71 1.1 jruoho {
72 1.1 jruoho mkdir -p test/c/d
73 1.1 jruoho (cd test/c/d && ln -s ../d .)
74 1.1 jruoho echo "Test string" > test/c/match
75 1.1 jruoho
76 1.1 jruoho atf_check -o file:"$(atf_get_srcdir)/d_recurse_symlink.out" \
77 1.1 jruoho -e file:"$(atf_get_srcdir)/d_recurse_symlink.err" \
78 1.1 jruoho grep -r string test
79 1.1 jruoho }
80 1.1 jruoho
81 1.1 jruoho atf_test_case word_regexps
82 1.1 jruoho word_regexps_head()
83 1.1 jruoho {
84 1.1 jruoho atf_set "descr" "Checks word-regexps"
85 1.1 jruoho }
86 1.1 jruoho word_regexps_body()
87 1.1 jruoho {
88 1.1 jruoho atf_check -o file:"$(atf_get_srcdir)/d_word_regexps.out" \
89 1.1 jruoho grep -w separated $(atf_get_srcdir)/d_input
90 1.1 jruoho }
91 1.1 jruoho
92 1.1 jruoho atf_test_case begin_end
93 1.1 jruoho begin_end_head()
94 1.1 jruoho {
95 1.1 jruoho atf_set "descr" "Checks handling of line beginnings and ends"
96 1.1 jruoho }
97 1.1 jruoho begin_end_body()
98 1.1 jruoho {
99 1.1 jruoho atf_check -o file:"$(atf_get_srcdir)/d_begin_end_a.out" \
100 1.1 jruoho grep ^Front "$(atf_get_srcdir)/d_input"
101 1.1 jruoho
102 1.1 jruoho atf_check -o file:"$(atf_get_srcdir)/d_begin_end_b.out" \
103 1.1 jruoho grep ending$ "$(atf_get_srcdir)/d_input"
104 1.1 jruoho }
105 1.1 jruoho
106 1.1 jruoho atf_test_case ignore_case
107 1.1 jruoho ignore_case_head()
108 1.1 jruoho {
109 1.1 jruoho atf_set "descr" "Checks ignore-case option"
110 1.1 jruoho }
111 1.1 jruoho ignore_case_body()
112 1.1 jruoho {
113 1.1 jruoho atf_check -o file:"$(atf_get_srcdir)/d_ignore_case.out" \
114 1.1 jruoho grep -i Upper "$(atf_get_srcdir)/d_input"
115 1.1 jruoho }
116 1.1 jruoho
117 1.1 jruoho atf_test_case invert
118 1.1 jruoho invert_head()
119 1.1 jruoho {
120 1.1 jruoho atf_set "descr" "Checks selecting non-matching lines with -v option"
121 1.1 jruoho }
122 1.1 jruoho invert_body()
123 1.1 jruoho {
124 1.1 jruoho atf_check -o file:"$(atf_get_srcdir)/d_invert.out" \
125 1.1 jruoho grep -v fish "$(atf_get_srcdir)/d_invert.in"
126 1.1 jruoho }
127 1.1 jruoho
128 1.1 jruoho atf_test_case whole_line
129 1.1 jruoho whole_line_head()
130 1.1 jruoho {
131 1.1 jruoho atf_set "descr" "Checks whole-line matching with -x flag"
132 1.1 jruoho }
133 1.1 jruoho whole_line_body()
134 1.1 jruoho {
135 1.1 jruoho atf_check -o file:"$(atf_get_srcdir)/d_whole_line.out" \
136 1.1 jruoho grep -x matchme "$(atf_get_srcdir)/d_input"
137 1.1 jruoho }
138 1.1 jruoho
139 1.1 jruoho atf_test_case negative
140 1.1 jruoho negative_head()
141 1.1 jruoho {
142 1.1 jruoho atf_set "descr" "Checks handling of files with no matches"
143 1.1 jruoho }
144 1.1 jruoho negative_body()
145 1.1 jruoho {
146 1.1 jruoho atf_check -s ne:0 grep "not a hope in hell" "$(atf_get_srcdir)/d_input"
147 1.1 jruoho }
148 1.1 jruoho
149 1.1 jruoho atf_test_case context
150 1.1 jruoho context_head()
151 1.1 jruoho {
152 1.1 jruoho atf_set "descr" "Checks displaying context with -A, -B and -C flags"
153 1.1 jruoho }
154 1.1 jruoho context_body()
155 1.1 jruoho {
156 1.1 jruoho cp $(atf_get_srcdir)/d_context_*.* .
157 1.1 jruoho
158 1.1 jruoho atf_check -o file:d_context_a.out grep -C2 bamboo d_context_a.in
159 1.1 jruoho atf_check -o file:d_context_b.out grep -A3 tilt d_context_a.in
160 1.1 jruoho atf_check -o file:d_context_c.out grep -B4 Whig d_context_a.in
161 1.1 jruoho atf_check -o file:d_context_d.out grep -C1 pig d_context_a.in d_context_b.in
162 1.1 jruoho }
163 1.1 jruoho
164 1.1 jruoho atf_test_case file_exp
165 1.1 jruoho file_exp_head()
166 1.1 jruoho {
167 1.1 jruoho atf_set "descr" "Checks reading expressions from file"
168 1.1 jruoho }
169 1.1 jruoho file_exp_body()
170 1.1 jruoho {
171 1.1 jruoho atf_check -o file:"$(atf_get_srcdir)/d_file_exp.out" -x \
172 1.1 jruoho 'jot 21 -1 1.00 | grep -f '"$(atf_get_srcdir)"'/d_file_exp.in'
173 1.1 jruoho }
174 1.1 jruoho
175 1.1 jruoho atf_test_case egrep
176 1.1 jruoho egrep_head()
177 1.1 jruoho {
178 1.1 jruoho atf_set "descr" "Checks matching special characters with egrep"
179 1.1 jruoho }
180 1.1 jruoho egrep_body()
181 1.1 jruoho {
182 1.1 jruoho atf_check -o file:"$(atf_get_srcdir)/d_egrep.out" \
183 1.1 jruoho egrep '\?|\*$$' "$(atf_get_srcdir)/d_input"
184 1.1 jruoho }
185 1.1 jruoho
186 1.1 jruoho atf_test_case zgrep
187 1.1 jruoho zgrep_head()
188 1.1 jruoho {
189 1.1 jruoho atf_set "descr" "Checks handling of gzipped files with zgrep"
190 1.1 jruoho }
191 1.1 jruoho zgrep_body()
192 1.1 jruoho {
193 1.1 jruoho cp "$(atf_get_srcdir)/d_input" .
194 1.1 jruoho gzip d_input || atf_fail "gzip failed"
195 1.1 jruoho
196 1.1 jruoho atf_check -o file:"$(atf_get_srcdir)/d_zgrep.out" zgrep -h line d_input.gz
197 1.1 jruoho }
198 1.1 jruoho
199 1.1 jruoho atf_test_case nonexistent
200 1.1 jruoho nonexistent_head()
201 1.1 jruoho {
202 1.1 jruoho atf_set "descr" "Checks that -s flag suppresses error" \
203 1.1 jruoho "messages about nonexistent files"
204 1.1 jruoho }
205 1.1 jruoho nonexistent_body()
206 1.1 jruoho {
207 1.1 jruoho atf_check -s ne:0 grep -s foobar nonexistent
208 1.1 jruoho }
209 1.1 jruoho
210 1.1 jruoho atf_test_case context2
211 1.1 jruoho context2_head()
212 1.1 jruoho {
213 1.1 jruoho atf_set "descr" "Checks displaying context with -z flag"
214 1.1 jruoho }
215 1.1 jruoho context2_body()
216 1.1 jruoho {
217 1.1 jruoho printf "haddock\000cod\000plaice\000" > test1
218 1.1 jruoho printf "mackeral\000cod\000crab\000" > test2
219 1.1 jruoho
220 1.1 jruoho atf_check -o file:"$(atf_get_srcdir)/d_context2_a.out" \
221 1.1 jruoho grep -z -A1 cod test1 test2
222 1.1 jruoho
223 1.1 jruoho atf_check -o file:"$(atf_get_srcdir)/d_context2_b.out" \
224 1.1 jruoho grep -z -B1 cod test1 test2
225 1.1 jruoho
226 1.1 jruoho atf_check -o file:"$(atf_get_srcdir)/d_context2_c.out" \
227 1.1 jruoho grep -z -C1 cod test1 test2
228 1.1 jruoho }
229 1.1 jruoho
230 1.1 jruoho atf_init_test_cases()
231 1.1 jruoho {
232 1.1 jruoho atf_add_test_case basic
233 1.1 jruoho atf_add_test_case binary
234 1.1 jruoho atf_add_test_case recurse
235 1.1 jruoho atf_add_test_case recurse_symlink
236 1.1 jruoho atf_add_test_case word_regexps
237 1.1 jruoho atf_add_test_case begin_end
238 1.1 jruoho atf_add_test_case ignore_case
239 1.1 jruoho atf_add_test_case invert
240 1.1 jruoho atf_add_test_case whole_line
241 1.1 jruoho atf_add_test_case negative
242 1.1 jruoho atf_add_test_case context
243 1.1 jruoho atf_add_test_case file_exp
244 1.1 jruoho atf_add_test_case egrep
245 1.1 jruoho atf_add_test_case zgrep
246 1.1 jruoho atf_add_test_case nonexistent
247 1.1 jruoho atf_add_test_case context2
248 1.1 jruoho }
249