t_awk.sh revision 1.3 1 1.3 jruoho # $NetBSD: t_awk.sh,v 1.3 2012/03/11 18:36:01 jruoho Exp $
2 1.1 christos #
3 1.1 christos # Copyright (c) 2012 The NetBSD Foundation, Inc.
4 1.1 christos # All rights reserved.
5 1.1 christos #
6 1.1 christos # This code is derived from software contributed to The NetBSD Foundation
7 1.1 christos # by Christos Zoulas
8 1.1 christos #
9 1.1 christos # Redistribution and use in source and binary forms, with or without
10 1.1 christos # modification, are permitted provided that the following conditions
11 1.1 christos # are met:
12 1.1 christos # 1. Redistributions of source code must retain the above copyright
13 1.1 christos # notice, this list of conditions and the following disclaimer.
14 1.1 christos # 2. Redistributions in binary form must reproduce the above copyright
15 1.1 christos # notice, this list of conditions and the following disclaimer in the
16 1.1 christos # documentation and/or other materials provided with the distribution.
17 1.1 christos #
18 1.1 christos # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 1.1 christos # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 1.1 christos # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 1.1 christos # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 1.1 christos # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 1.1 christos # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 1.1 christos # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 1.1 christos # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 1.1 christos # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 1.1 christos # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 1.1 christos # POSSIBILITY OF SUCH DAMAGE.
29 1.1 christos #
30 1.1 christos
31 1.1 christos awk=awk
32 1.1 christos
33 1.3 jruoho h_check()
34 1.3 jruoho {
35 1.3 jruoho local fname=d_$1
36 1.3 jruoho for sfx in in out awk; do
37 1.3 jruoho cp -r $(atf_get_srcdir)/$fname.$sfx .
38 1.3 jruoho done
39 1.3 jruoho shift 1
40 1.3 jruoho atf_check -o file:$fname.out -x "awk $@ -f $fname.awk < $fname.in"
41 1.3 jruoho }
42 1.3 jruoho
43 1.3 jruoho atf_test_case big_regexp
44 1.3 jruoho
45 1.3 jruoho big_regexp_head() {
46 1.3 jruoho atf_set "descr" "Checks matching long regular expressions (PR/33392)"
47 1.3 jruoho }
48 1.3 jruoho
49 1.3 jruoho big_regexp_body() {
50 1.3 jruoho h_check big_regexp
51 1.3 jruoho }
52 1.3 jruoho
53 1.3 jruoho atf_test_case end
54 1.3 jruoho
55 1.3 jruoho end_head() {
56 1.3 jruoho atf_set "descr" "Checks that the last line of the input" \
57 1.3 jruoho "is available under END pattern (PR/29659)"
58 1.3 jruoho }
59 1.3 jruoho
60 1.3 jruoho end_body() {
61 1.3 jruoho h_check end1
62 1.3 jruoho h_check end2
63 1.3 jruoho }
64 1.3 jruoho
65 1.3 jruoho atf_test_case string1
66 1.3 jruoho
67 1.3 jruoho string1_head() {
68 1.3 jruoho atf_set "descr" "Checks escaping newlines in string literals"
69 1.3 jruoho }
70 1.3 jruoho
71 1.3 jruoho string1_body() {
72 1.3 jruoho for sfx in out awk; do
73 1.3 jruoho cp -r $(atf_get_srcdir)/d_string1.$sfx .
74 1.3 jruoho done
75 1.3 jruoho atf_check -o file:d_string1.out awk -f d_string1.awk
76 1.3 jruoho }
77 1.3 jruoho
78 1.3 jruoho atf_test_case multibyte
79 1.3 jruoho
80 1.3 jruoho multibyte_head() {
81 1.3 jruoho atf_set "descr" "Checks multibyte charsets support" \
82 1.3 jruoho "in tolower and toupper (PR/36394)"
83 1.3 jruoho }
84 1.3 jruoho
85 1.3 jruoho multibyte_body() {
86 1.3 jruoho export LANG=en_US.UTF-8
87 1.3 jruoho
88 1.3 jruoho h_check tolower
89 1.3 jruoho h_check toupper
90 1.3 jruoho }
91 1.3 jruoho
92 1.3 jruoho atf_test_case period
93 1.3 jruoho
94 1.3 jruoho period_head() {
95 1.3 jruoho atf_set "descr" "Checks that the period character is recognised" \
96 1.3 jruoho "in awk program regardless of locale (bin/42320)"
97 1.3 jruoho }
98 1.3 jruoho
99 1.3 jruoho period_body() {
100 1.3 jruoho export LANG=ru_RU.KOI8-R
101 1.3 jruoho
102 1.3 jruoho atf_expect_fail "PR bin/42320"
103 1.3 jruoho h_check period -v x=0.5
104 1.3 jruoho }
105 1.3 jruoho
106 1.3 jruoho atf_test_case assign_NF
107 1.3 jruoho
108 1.3 jruoho assign_NF_head() {
109 1.3 jruoho atf_set "descr" 'Checks that assign to NF changes $0 and $n (PR/44063)'
110 1.3 jruoho }
111 1.3 jruoho
112 1.3 jruoho assign_NF_body() {
113 1.3 jruoho h_check assign_NF
114 1.3 jruoho }
115 1.3 jruoho
116 1.1 christos atf_test_case single_char_rs
117 1.1 christos
118 1.1 christos single_char_rs_head() {
119 1.1 christos atf_set "descr" "Test awk(1) with single character RS"
120 1.1 christos }
121 1.1 christos
122 1.1 christos single_char_rs_body() {
123 1.1 christos atf_check \
124 1.1 christos -o "inline:1\n2\n\n3\n\n\n4\n\n" \
125 1.1 christos -x "echo 1a2aa3aaa4 | $awk 1 RS=a"
126 1.1 christos }
127 1.1 christos
128 1.1 christos atf_test_case two_char_rs
129 1.1 christos
130 1.1 christos two_char_rs_head() {
131 1.1 christos atf_set "descr" "Test awk(1) with two characters RS"
132 1.1 christos }
133 1.1 christos
134 1.1 christos two_char_rs_body() {
135 1.1 christos atf_check \
136 1.1 christos -o "inline:1\n2\n3\n4\n\n" \
137 1.1 christos -x "echo 1ab2ab3ab4 | $awk 1 RS=ab"
138 1.1 christos }
139 1.1 christos
140 1.1 christos atf_test_case single_char_regex_group_rs
141 1.1 christos
142 1.1 christos single_char_regex_group_rs_head() {
143 1.1 christos atf_set "descr" "Test awk(1) with single character regex group RS"
144 1.1 christos }
145 1.1 christos
146 1.1 christos single_char_regex_group_rs_body() {
147 1.1 christos atf_check \
148 1.1 christos -o "inline:1\n2\n\n3\n\n\n4\n\n" \
149 1.1 christos -x "echo 1a2aa3aaa4 | $awk 1 RS='[a]'"
150 1.1 christos }
151 1.1 christos
152 1.1 christos atf_test_case two_char_regex_group_rs
153 1.1 christos
154 1.1 christos two_char_regex_group_rs_head() {
155 1.1 christos atf_set "descr" "Test awk(1) with two characters regex group RS"
156 1.1 christos }
157 1.1 christos
158 1.1 christos two_char_regex_group_rs_body() {
159 1.1 christos atf_check \
160 1.1 christos -o "inline:1\n2\n\n3\n\n\n4\n\n" \
161 1.1 christos -x "echo 1a2ab3aba4 | $awk 1 RS='[ab]'"
162 1.1 christos }
163 1.1 christos
164 1.1 christos atf_test_case single_char_regex_star_rs
165 1.1 christos
166 1.1 christos single_char_regex_star_rs_head() {
167 1.1 christos atf_set "descr" "Test awk(1) with single character regex star RS"
168 1.1 christos }
169 1.1 christos
170 1.1 christos single_char_regex_star_rs_body() {
171 1.1 christos atf_check \
172 1.1 christos -o "inline:1\n2\n3\n4\n\n" \
173 1.1 christos -x "echo 1a2aa3aaa4 | $awk 1 RS='a*'"
174 1.1 christos }
175 1.1 christos
176 1.1 christos atf_test_case two_char_regex_star_rs
177 1.1 christos
178 1.1 christos two_char_regex_star_rs_head() {
179 1.1 christos atf_set "descr" "Test awk(1) with two characters regex star RS"
180 1.1 christos }
181 1.1 christos
182 1.1 christos two_char_regex_star_rs_body() {
183 1.1 christos atf_check \
184 1.1 christos -o "inline:1\n2\n3\n4\n\n" \
185 1.1 christos -x "echo 1a2aa3aaa4 | $awk 1 RS='aa*'"
186 1.1 christos }
187 1.1 christos
188 1.1 christos atf_test_case regex_two_star_rs
189 1.1 christos
190 1.1 christos regex_two_star_rs_head() {
191 1.1 christos atf_set "descr" "Test awk(1) with regex two star RS"
192 1.1 christos }
193 1.1 christos
194 1.1 christos regex_two_star_rs_body() {
195 1.1 christos atf_check \
196 1.1 christos -o "inline:1\n2\n3\n4\n\n" \
197 1.1 christos -x "echo 1a2ab3aab4 | $awk 1 RS='aa*b*'"
198 1.1 christos }
199 1.1 christos
200 1.1 christos atf_test_case regex_or_1_rs
201 1.1 christos
202 1.1 christos regex_or_1_rs_head() {
203 1.1 christos atf_set "descr" "Test awk(1) with regex | case 1 RS"
204 1.1 christos }
205 1.1 christos
206 1.1 christos regex_or_1_rs_body() {
207 1.1 christos atf_check \
208 1.1 christos -o "inline:1a\nc\n\n" \
209 1.1 christos -x "echo 1abc | $awk 1 RS='abcde|b'"
210 1.1 christos }
211 1.1 christos
212 1.1 christos atf_test_case regex_or_2_rs
213 1.1 christos
214 1.1 christos regex_or_2_rs_head() {
215 1.1 christos atf_set "descr" "Test awk(1) with regex | case 2 RS"
216 1.1 christos }
217 1.1 christos
218 1.1 christos regex_or_2_rs_body() {
219 1.1 christos atf_check \
220 1.1 christos -o "inline:1a\ncdf2\n\n" \
221 1.1 christos -x "echo 1abcdf2 | $awk 1 RS='abcde|b'"
222 1.1 christos }
223 1.1 christos
224 1.1 christos atf_test_case regex_or_3_rs
225 1.1 christos
226 1.1 christos regex_or_3_rs_head() {
227 1.1 christos atf_set "descr" "Test awk(1) with regex | case 3 RS"
228 1.1 christos }
229 1.1 christos
230 1.1 christos regex_or_3_rs_body() {
231 1.1 christos atf_check \
232 1.1 christos -o "inline:1\n\nf2\n\n" \
233 1.1 christos -x "echo 1abcdebf2 | $awk 1 RS='abcde|b'"
234 1.1 christos }
235 1.1 christos
236 1.1 christos atf_test_case regex_or_4_rs
237 1.1 christos
238 1.1 christos regex_or_4_rs_head() {
239 1.1 christos atf_set "descr" "Test awk(1) with regex | case 4 RS"
240 1.1 christos }
241 1.1 christos
242 1.1 christos regex_or_4_rs_body() {
243 1.1 christos atf_check \
244 1.1 christos -o "inline:1\nbcdf2\n\n" \
245 1.1 christos -x "echo 1abcdf2 | $awk 1 RS='abcde|a'"
246 1.1 christos
247 1.1 christos }
248 1.1 christos
249 1.1 christos atf_test_case regex_caret_1_rs
250 1.1 christos
251 1.1 christos regex_caret_1_rs_head() {
252 1.1 christos atf_set "descr" "Test awk(1) with regex ^ case 1 RS"
253 1.1 christos }
254 1.1 christos
255 1.1 christos regex_caret_1_rs_body() {
256 1.1 christos atf_check \
257 1.1 christos -o "inline:\n1a2a3a\n\n" \
258 1.1 christos -x "echo a1a2a3a | $awk 1 RS='^a'"
259 1.1 christos
260 1.1 christos }
261 1.1 christos
262 1.1 christos atf_test_case regex_caret_2_rs
263 1.1 christos
264 1.1 christos regex_caret_2_rs_head() {
265 1.1 christos atf_set "descr" "Test awk(1) with regex ^ case 2 RS"
266 1.1 christos }
267 1.1 christos
268 1.1 christos regex_caret_2_rs_body() {
269 1.1 christos atf_check \
270 1.2 christos -o "inline:\naa1a2a\n\n" \
271 1.1 christos -x "echo aaa1a2a | $awk 1 RS='^a'"
272 1.1 christos
273 1.1 christos }
274 1.1 christos
275 1.1 christos atf_test_case regex_dollar_1_rs
276 1.1 christos
277 1.1 christos regex_dollar_1_rs_head() {
278 1.1 christos atf_set "descr" "Test awk(1) with regex $ case 1 RS"
279 1.1 christos }
280 1.1 christos
281 1.1 christos regex_dollar_1_rs_body() {
282 1.1 christos atf_check \
283 1.1 christos -o "inline:a1a2a3a\n\n" \
284 1.1 christos -x "echo a1a2a3a | $awk 1 RS='a$'"
285 1.1 christos
286 1.1 christos }
287 1.1 christos
288 1.1 christos atf_test_case regex_dollar_2_rs
289 1.1 christos
290 1.1 christos regex_dollar_2_rs_head() {
291 1.1 christos atf_set "descr" "Test awk(1) with regex $ case 2 RS"
292 1.1 christos }
293 1.1 christos
294 1.1 christos regex_dollar_2_rs_body() {
295 1.1 christos atf_check \
296 1.2 christos -o "inline:a1a2aaa\n\n" \
297 1.1 christos -x "echo a1a2aaa | $awk 1 RS='a$'"
298 1.1 christos
299 1.1 christos }
300 1.1 christos
301 1.1 christos atf_test_case regex_reallocation_rs
302 1.1 christos
303 1.1 christos regex_reallocation_rs_head() {
304 1.1 christos atf_set "descr" "Test awk(1) with regex reallocation RS"
305 1.1 christos }
306 1.1 christos
307 1.1 christos regex_reallocation_rs_body() {
308 1.1 christos atf_check \
309 1.1 christos -o "inline:a\na\na\na\na\na\na\na\na\na10000\n\n" \
310 1.1 christos -x "jot -s a 10000 | $awk 'NR>1' RS='999[0-9]'"
311 1.1 christos
312 1.1 christos }
313 1.1 christos
314 1.1 christos atf_test_case empty_rs
315 1.1 christos
316 1.1 christos empty_rs_head() {
317 1.1 christos atf_set "descr" "Test awk(1) with empty RS"
318 1.1 christos }
319 1.1 christos
320 1.1 christos empty_rs_body() {
321 1.1 christos atf_check \
322 1.1 christos -o "inline:foo\n" \
323 1.2 christos -x "echo foo | $awk 1 RS=''"
324 1.1 christos
325 1.1 christos }
326 1.1 christos
327 1.1 christos atf_test_case newline_rs
328 1.1 christos
329 1.1 christos newline_rs_head() {
330 1.1 christos atf_set "descr" "Test awk(1) with newline RS"
331 1.1 christos }
332 1.1 christos
333 1.1 christos newline_rs_body() {
334 1.1 christos atf_check \
335 1.1 christos -o "inline:r1f1:r1f2\nr2f1:r2f2\n" \
336 1.2 christos -x "printf '\n\n\nr1f1\nr1f2\n\nr2f1\nr2f2\n\n\n' | $awk '{\$1=\$1}1' RS= OFS=:"
337 1.1 christos }
338 1.1 christos
339 1.1 christos atf_init_test_cases() {
340 1.3 jruoho
341 1.3 jruoho atf_add_test_case big_regexp
342 1.3 jruoho atf_add_test_case end
343 1.3 jruoho atf_add_test_case string1
344 1.3 jruoho atf_add_test_case multibyte
345 1.3 jruoho atf_add_test_case period
346 1.3 jruoho atf_add_test_case assign_NF
347 1.3 jruoho
348 1.1 christos atf_add_test_case single_char_rs
349 1.1 christos atf_add_test_case two_char_rs
350 1.1 christos atf_add_test_case single_char_regex_group_rs
351 1.1 christos atf_add_test_case two_char_regex_group_rs
352 1.1 christos atf_add_test_case two_char_regex_star_rs
353 1.1 christos atf_add_test_case single_char_regex_star_rs
354 1.1 christos atf_add_test_case regex_two_star_rs
355 1.1 christos atf_add_test_case regex_or_1_rs
356 1.1 christos atf_add_test_case regex_or_2_rs
357 1.1 christos atf_add_test_case regex_or_3_rs
358 1.1 christos atf_add_test_case regex_caret_1_rs
359 1.1 christos atf_add_test_case regex_caret_2_rs
360 1.1 christos atf_add_test_case regex_dollar_1_rs
361 1.1 christos atf_add_test_case regex_dollar_2_rs
362 1.1 christos atf_add_test_case regex_reallocation_rs
363 1.1 christos atf_add_test_case empty_rs
364 1.1 christos atf_add_test_case newline_rs
365 1.1 christos }
366