t_grep.sh revision 1.1 1 1.1 jruoho # $NetBSD: t_grep.sh,v 1.1 2012/03/17 16:33:13 jruoho 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.1 jruoho atf_check -o file:"$(atf_get_srcdir)/d_binary.out" grep NetBSD /bin/sh
47 1.1 jruoho }
48 1.1 jruoho
49 1.1 jruoho atf_test_case recurse
50 1.1 jruoho recurse_head()
51 1.1 jruoho {
52 1.1 jruoho atf_set "descr" "Checks recursive searching"
53 1.1 jruoho }
54 1.1 jruoho recurse_body()
55 1.1 jruoho {
56 1.1 jruoho mkdir -p recurse/a/f recurse/d
57 1.1 jruoho echo -e "cod\ndover sole\nhaddock\nhalibut\npilchard" > recurse/d/fish
58 1.1 jruoho echo -e "cod\nhaddock\nplaice" > recurse/a/f/favourite-fish
59 1.1 jruoho
60 1.1 jruoho atf_check -o file:"$(atf_get_srcdir)/d_recurse.out" grep -r haddock recurse
61 1.1 jruoho }
62 1.1 jruoho
63 1.1 jruoho atf_test_case recurse_symlink
64 1.1 jruoho recurse_symlink_head()
65 1.1 jruoho {
66 1.1 jruoho atf_set "descr" "Checks symbolic link recursion"
67 1.1 jruoho }
68 1.1 jruoho recurse_symlink_body()
69 1.1 jruoho {
70 1.1 jruoho mkdir -p test/c/d
71 1.1 jruoho (cd test/c/d && ln -s ../d .)
72 1.1 jruoho echo "Test string" > test/c/match
73 1.1 jruoho
74 1.1 jruoho atf_check -o file:"$(atf_get_srcdir)/d_recurse_symlink.out" \
75 1.1 jruoho -e file:"$(atf_get_srcdir)/d_recurse_symlink.err" \
76 1.1 jruoho grep -r string test
77 1.1 jruoho }
78 1.1 jruoho
79 1.1 jruoho atf_test_case word_regexps
80 1.1 jruoho word_regexps_head()
81 1.1 jruoho {
82 1.1 jruoho atf_set "descr" "Checks word-regexps"
83 1.1 jruoho }
84 1.1 jruoho word_regexps_body()
85 1.1 jruoho {
86 1.1 jruoho atf_check -o file:"$(atf_get_srcdir)/d_word_regexps.out" \
87 1.1 jruoho grep -w separated $(atf_get_srcdir)/d_input
88 1.1 jruoho }
89 1.1 jruoho
90 1.1 jruoho atf_test_case begin_end
91 1.1 jruoho begin_end_head()
92 1.1 jruoho {
93 1.1 jruoho atf_set "descr" "Checks handling of line beginnings and ends"
94 1.1 jruoho }
95 1.1 jruoho begin_end_body()
96 1.1 jruoho {
97 1.1 jruoho atf_check -o file:"$(atf_get_srcdir)/d_begin_end_a.out" \
98 1.1 jruoho grep ^Front "$(atf_get_srcdir)/d_input"
99 1.1 jruoho
100 1.1 jruoho atf_check -o file:"$(atf_get_srcdir)/d_begin_end_b.out" \
101 1.1 jruoho grep ending$ "$(atf_get_srcdir)/d_input"
102 1.1 jruoho }
103 1.1 jruoho
104 1.1 jruoho atf_test_case ignore_case
105 1.1 jruoho ignore_case_head()
106 1.1 jruoho {
107 1.1 jruoho atf_set "descr" "Checks ignore-case option"
108 1.1 jruoho }
109 1.1 jruoho ignore_case_body()
110 1.1 jruoho {
111 1.1 jruoho atf_check -o file:"$(atf_get_srcdir)/d_ignore_case.out" \
112 1.1 jruoho grep -i Upper "$(atf_get_srcdir)/d_input"
113 1.1 jruoho }
114 1.1 jruoho
115 1.1 jruoho atf_test_case invert
116 1.1 jruoho invert_head()
117 1.1 jruoho {
118 1.1 jruoho atf_set "descr" "Checks selecting non-matching lines with -v option"
119 1.1 jruoho }
120 1.1 jruoho invert_body()
121 1.1 jruoho {
122 1.1 jruoho atf_check -o file:"$(atf_get_srcdir)/d_invert.out" \
123 1.1 jruoho grep -v fish "$(atf_get_srcdir)/d_invert.in"
124 1.1 jruoho }
125 1.1 jruoho
126 1.1 jruoho atf_test_case whole_line
127 1.1 jruoho whole_line_head()
128 1.1 jruoho {
129 1.1 jruoho atf_set "descr" "Checks whole-line matching with -x flag"
130 1.1 jruoho }
131 1.1 jruoho whole_line_body()
132 1.1 jruoho {
133 1.1 jruoho atf_check -o file:"$(atf_get_srcdir)/d_whole_line.out" \
134 1.1 jruoho grep -x matchme "$(atf_get_srcdir)/d_input"
135 1.1 jruoho }
136 1.1 jruoho
137 1.1 jruoho atf_test_case negative
138 1.1 jruoho negative_head()
139 1.1 jruoho {
140 1.1 jruoho atf_set "descr" "Checks handling of files with no matches"
141 1.1 jruoho }
142 1.1 jruoho negative_body()
143 1.1 jruoho {
144 1.1 jruoho atf_check -s ne:0 grep "not a hope in hell" "$(atf_get_srcdir)/d_input"
145 1.1 jruoho }
146 1.1 jruoho
147 1.1 jruoho atf_test_case context
148 1.1 jruoho context_head()
149 1.1 jruoho {
150 1.1 jruoho atf_set "descr" "Checks displaying context with -A, -B and -C flags"
151 1.1 jruoho }
152 1.1 jruoho context_body()
153 1.1 jruoho {
154 1.1 jruoho cp $(atf_get_srcdir)/d_context_*.* .
155 1.1 jruoho
156 1.1 jruoho atf_check -o file:d_context_a.out grep -C2 bamboo d_context_a.in
157 1.1 jruoho atf_check -o file:d_context_b.out grep -A3 tilt d_context_a.in
158 1.1 jruoho atf_check -o file:d_context_c.out grep -B4 Whig d_context_a.in
159 1.1 jruoho atf_check -o file:d_context_d.out grep -C1 pig d_context_a.in d_context_b.in
160 1.1 jruoho }
161 1.1 jruoho
162 1.1 jruoho atf_test_case file_exp
163 1.1 jruoho file_exp_head()
164 1.1 jruoho {
165 1.1 jruoho atf_set "descr" "Checks reading expressions from file"
166 1.1 jruoho }
167 1.1 jruoho file_exp_body()
168 1.1 jruoho {
169 1.1 jruoho atf_check -o file:"$(atf_get_srcdir)/d_file_exp.out" -x \
170 1.1 jruoho 'jot 21 -1 1.00 | grep -f '"$(atf_get_srcdir)"'/d_file_exp.in'
171 1.1 jruoho }
172 1.1 jruoho
173 1.1 jruoho atf_test_case egrep
174 1.1 jruoho egrep_head()
175 1.1 jruoho {
176 1.1 jruoho atf_set "descr" "Checks matching special characters with egrep"
177 1.1 jruoho }
178 1.1 jruoho egrep_body()
179 1.1 jruoho {
180 1.1 jruoho atf_check -o file:"$(atf_get_srcdir)/d_egrep.out" \
181 1.1 jruoho egrep '\?|\*$$' "$(atf_get_srcdir)/d_input"
182 1.1 jruoho }
183 1.1 jruoho
184 1.1 jruoho atf_test_case zgrep
185 1.1 jruoho zgrep_head()
186 1.1 jruoho {
187 1.1 jruoho atf_set "descr" "Checks handling of gzipped files with zgrep"
188 1.1 jruoho }
189 1.1 jruoho zgrep_body()
190 1.1 jruoho {
191 1.1 jruoho cp "$(atf_get_srcdir)/d_input" .
192 1.1 jruoho gzip d_input || atf_fail "gzip failed"
193 1.1 jruoho
194 1.1 jruoho atf_check -o file:"$(atf_get_srcdir)/d_zgrep.out" zgrep -h line d_input.gz
195 1.1 jruoho }
196 1.1 jruoho
197 1.1 jruoho atf_test_case nonexistent
198 1.1 jruoho nonexistent_head()
199 1.1 jruoho {
200 1.1 jruoho atf_set "descr" "Checks that -s flag suppresses error" \
201 1.1 jruoho "messages about nonexistent files"
202 1.1 jruoho }
203 1.1 jruoho nonexistent_body()
204 1.1 jruoho {
205 1.1 jruoho atf_check -s ne:0 grep -s foobar nonexistent
206 1.1 jruoho }
207 1.1 jruoho
208 1.1 jruoho atf_test_case context2
209 1.1 jruoho context2_head()
210 1.1 jruoho {
211 1.1 jruoho atf_set "descr" "Checks displaying context with -z flag"
212 1.1 jruoho }
213 1.1 jruoho context2_body()
214 1.1 jruoho {
215 1.1 jruoho printf "haddock\000cod\000plaice\000" > test1
216 1.1 jruoho printf "mackeral\000cod\000crab\000" > test2
217 1.1 jruoho
218 1.1 jruoho atf_check -o file:"$(atf_get_srcdir)/d_context2_a.out" \
219 1.1 jruoho grep -z -A1 cod test1 test2
220 1.1 jruoho
221 1.1 jruoho atf_check -o file:"$(atf_get_srcdir)/d_context2_b.out" \
222 1.1 jruoho grep -z -B1 cod test1 test2
223 1.1 jruoho
224 1.1 jruoho atf_check -o file:"$(atf_get_srcdir)/d_context2_c.out" \
225 1.1 jruoho grep -z -C1 cod test1 test2
226 1.1 jruoho }
227 1.1 jruoho
228 1.1 jruoho atf_init_test_cases()
229 1.1 jruoho {
230 1.1 jruoho atf_add_test_case basic
231 1.1 jruoho atf_add_test_case binary
232 1.1 jruoho atf_add_test_case recurse
233 1.1 jruoho atf_add_test_case recurse_symlink
234 1.1 jruoho atf_add_test_case word_regexps
235 1.1 jruoho atf_add_test_case begin_end
236 1.1 jruoho atf_add_test_case ignore_case
237 1.1 jruoho atf_add_test_case invert
238 1.1 jruoho atf_add_test_case whole_line
239 1.1 jruoho atf_add_test_case negative
240 1.1 jruoho atf_add_test_case context
241 1.1 jruoho atf_add_test_case file_exp
242 1.1 jruoho atf_add_test_case egrep
243 1.1 jruoho atf_add_test_case zgrep
244 1.1 jruoho atf_add_test_case nonexistent
245 1.1 jruoho atf_add_test_case context2
246 1.1 jruoho }
247