Expand PMF_FN_* macros.
[netbsd-mini2440.git] / tests / util / grep / t_grep.sh
blob375a434697ec6804c7c789692cb4760dec3d04bc
1 # $NetBSD$
3 # Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
4 # All rights reserved.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
15 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 # POSSIBILITY OF SUCH DAMAGE.
28 words="/usr/share/dict/words"
30 atf_test_case basic
31 basic_head()
33 atf_set "descr" "Checks basic functionality"
35 basic_body()
37 atf_check -o file:"$(atf_get_srcdir)/d_basic.out" grep aa "${words}"
40 atf_test_case binary
41 binary_head()
43 atf_set "descr" "Checks handling of binary files"
45 binary_body()
47 atf_check -o file:"$(atf_get_srcdir)/d_binary.out" grep NetBSD /bin/sh
50 atf_test_case recurse
51 recurse_head()
53 atf_set "descr" "Checks recursive searching"
55 recurse_body()
57 mkdir -p recurse/a/f recurse/d
58 echo -e "cod\ndover sole\nhaddock\nhalibut\npilchard" > recurse/d/fish
59 echo -e "cod\nhaddock\nplaice" > recurse/a/f/favourite-fish
61 atf_check -o file:"$(atf_get_srcdir)/d_recurse.out" grep -r haddock recurse
64 atf_test_case recurse_symlink
65 recurse_symlink_head()
67 atf_set "descr" "Checks symbolic link recursion"
69 recurse_symlink_body()
71 mkdir -p test/c/d
72 (cd test/c/d && ln -s ../d .)
73 echo "Test string" > test/c/match
75 atf_check -o file:"$(atf_get_srcdir)/d_recurse_symlink.out" \
76 -e file:"$(atf_get_srcdir)/d_recurse_symlink.err" \
77 grep -r string test
80 atf_test_case word_regexps
81 word_regexps_head()
83 atf_set "descr" "Checks word-regexps"
85 word_regexps_body()
87 atf_check -o file:"$(atf_get_srcdir)/d_word_regexps.out" \
88 grep -w separated $(atf_get_srcdir)/d_input
91 atf_test_case begin_end
92 begin_end_head()
94 atf_set "descr" "Checks handling of line beginnings and ends"
96 begin_end_body()
98 atf_check -o file:"$(atf_get_srcdir)/d_begin_end_a.out" \
99 grep ^Front "$(atf_get_srcdir)/d_input"
101 atf_check -o file:"$(atf_get_srcdir)/d_begin_end_b.out" \
102 grep ending$ "$(atf_get_srcdir)/d_input"
105 atf_test_case ignore_case
106 ignore_case_head()
108 atf_set "descr" "Checks ignore-case option"
110 ignore_case_body()
112 atf_check -o file:"$(atf_get_srcdir)/d_ignore_case.out" \
113 grep -i Upper "$(atf_get_srcdir)/d_input"
116 atf_test_case invert
117 invert_head()
119 atf_set "descr" "Checks selecting non-matching lines with -v option"
121 invert_body()
123 atf_check -o file:"$(atf_get_srcdir)/d_invert.out" \
124 grep -v fish "$(atf_get_srcdir)/d_invert.in"
127 atf_test_case whole_line
128 whole_line_head()
130 atf_set "descr" "Checks whole-line matching with -x flag"
132 whole_line_body()
134 atf_check -o file:"$(atf_get_srcdir)/d_whole_line.out" \
135 grep -x matchme "$(atf_get_srcdir)/d_input"
138 atf_test_case negative
139 negative_head()
141 atf_set "descr" "Checks handling of files with no matches"
143 negative_body()
145 atf_check -s ne:0 grep "not a hope in hell" "$(atf_get_srcdir)/d_input"
148 atf_test_case context
149 context_head()
151 atf_set "descr" "Checks displaying context with -A, -B and -C flags"
153 context_body()
155 cp $(atf_get_srcdir)/d_context_*.* .
157 atf_check -o file:d_context_a.out grep -C2 bamboo d_context_a.in
158 atf_check -o file:d_context_b.out grep -A3 tilt d_context_a.in
159 atf_check -o file:d_context_c.out grep -B4 Whig d_context_a.in
160 atf_check -o file:d_context_d.out grep -C1 pig d_context_a.in d_context_b.in
163 atf_test_case file_exp
164 file_exp_head()
166 atf_set "descr" "Checks reading expressions from file"
168 file_exp_body()
170 atf_check -o file:"$(atf_get_srcdir)/d_file_exp.inout" \
171 grep -f "$(atf_get_srcdir)/d_file_exp.inout" "${words}"
174 atf_test_case egrep
175 egrep_head()
177 atf_set "descr" "Checks matching special characters with egrep"
179 egrep_body()
181 atf_check -o file:"$(atf_get_srcdir)/d_egrep.out" \
182 egrep '\?|\*$$' "$(atf_get_srcdir)/d_input"
185 atf_test_case zgrep
186 zgrep_head()
188 atf_set "descr" "Checks handling of gzipped files with zgrep"
190 zgrep_body()
192 cp "$(atf_get_srcdir)/d_input" .
193 gzip d_input || atf_fail "gzip failed"
195 atf_check -o file:"$(atf_get_srcdir)/d_zgrep.out" zgrep -h line d_input.gz
198 atf_test_case nonexistent
199 nonexistent_head()
201 atf_set "descr" "Checks that -s flag suppresses error" \
202 "messages about nonexistent files"
204 nonexistent_body()
206 atf_check -s ne:0 grep -s foobar nonexistent
209 atf_test_case context2
210 context2_head()
212 atf_set "descr" "Checks displaying context with -z flag"
214 context2_body()
216 printf "haddock\000cod\000plaice\000" > test1
217 printf "mackeral\000cod\000crab\000" > test2
219 atf_check -o file:"$(atf_get_srcdir)/d_context2_a.out" \
220 grep -z -A1 cod test1 test2
222 atf_check -o file:"$(atf_get_srcdir)/d_context2_b.out" \
223 grep -z -B1 cod test1 test2
225 atf_check -o file:"$(atf_get_srcdir)/d_context2_c.out" \
226 grep -z -C1 cod test1 test2
229 atf_init_test_cases()
231 atf_add_test_case basic
232 atf_add_test_case binary
233 atf_add_test_case recurse
234 atf_add_test_case recurse_symlink
235 atf_add_test_case word_regexps
236 atf_add_test_case begin_end
237 atf_add_test_case ignore_case
238 atf_add_test_case invert
239 atf_add_test_case whole_line
240 atf_add_test_case negative
241 atf_add_test_case context
242 atf_add_test_case file_exp
243 atf_add_test_case egrep
244 atf_add_test_case zgrep
245 atf_add_test_case nonexistent
246 atf_add_test_case context2