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