1 # $NetBSD: t_awk.sh,v 1.5 2012/12/10 20:30:06 christos Exp $
3 # Copyright (c) 2012 The NetBSD Foundation, Inc.
6 # This code is derived from software contributed to The NetBSD Foundation
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions
12 # 1. Redistributions of source code must retain the above copyright
13 # notice, this list of conditions and the following disclaimer.
14 # 2. Redistributions in binary form must reproduce the above copyright
15 # notice, this list of conditions and the following disclaimer in the
16 # documentation and/or other materials provided with the distribution.
18 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 # POSSIBILITY OF SUCH DAMAGE.
36 for sfx
in in out
awk; do
37 cp -r $
(atf_get_srcdir
)/$fname.
$sfx .
40 atf_check
-o file:$fname.out
-x "awk $@ -f $fname.awk < $fname.in"
43 atf_test_case big_regexp
46 atf_set
"descr" "Checks matching long regular expressions (PR/33392)"
56 atf_set
"descr" "Checks that the last line of the input" \
57 "is available under END pattern (PR/29659)"
68 atf_set
"descr" "Checks escaping newlines in string literals"
72 for sfx
in out
awk; do
73 cp -r $
(atf_get_srcdir
)/d_string1.
$sfx .
75 atf_check
-o file:d_string1.out
awk -f d_string1.
awk
78 atf_test_case multibyte
81 atf_set
"descr" "Checks multibyte charsets support" \
82 "in tolower and toupper (PR/36394)"
86 export LANG
=en_US.UTF-8
95 atf_set
"descr" "Checks that the period character is recognised" \
96 "in awk program regardless of locale (bin/42320)"
100 export LANG
=ru_RU.KOI8-R
102 h_check period
-v x
=0.5
105 atf_test_case assign_NF
108 atf_set
"descr" 'Checks that assign to NF changes $0 and $n (PR/44063)'
115 atf_test_case single_char_rs
117 single_char_rs_head
() {
118 atf_set
"descr" "Test awk(1) with single character RS"
121 single_char_rs_body
() {
123 -o "inline:1\n2\n\n3\n\n\n4\n\n" \
124 -x "echo 1a2aa3aaa4 | $awk 1 RS=a"
127 atf_test_case two_char_rs
130 atf_set
"descr" "Test awk(1) with two characters RS"
135 -o "inline:1\n2\n3\n4\n\n" \
136 -x "echo 1ab2ab3ab4 | $awk 1 RS=ab"
139 atf_test_case single_char_regex_group_rs
141 single_char_regex_group_rs_head
() {
142 atf_set
"descr" "Test awk(1) with single character regex group RS"
145 single_char_regex_group_rs_body
() {
147 -o "inline:1\n2\n\n3\n\n\n4\n\n" \
148 -x "echo 1a2aa3aaa4 | $awk 1 RS='[a]'"
151 atf_test_case two_char_regex_group_rs
153 two_char_regex_group_rs_head
() {
154 atf_set
"descr" "Test awk(1) with two characters regex group RS"
157 two_char_regex_group_rs_body
() {
159 -o "inline:1\n2\n\n3\n\n\n4\n\n" \
160 -x "echo 1a2ab3aba4 | $awk 1 RS='[ab]'"
163 atf_test_case single_char_regex_star_rs
165 single_char_regex_star_rs_head
() {
166 atf_set
"descr" "Test awk(1) with single character regex star RS"
169 single_char_regex_star_rs_body
() {
171 -o "inline:1\n2\n3\n4\n\n" \
172 -x "echo 1a2aa3aaa4 | $awk 1 RS='a*'"
175 atf_test_case two_char_regex_star_rs
177 two_char_regex_star_rs_head
() {
178 atf_set
"descr" "Test awk(1) with two characters regex star RS"
181 two_char_regex_star_rs_body
() {
183 -o "inline:1\n2\n3\n4\n\n" \
184 -x "echo 1a2aa3aaa4 | $awk 1 RS='aa*'"
187 atf_test_case regex_two_star_rs
189 regex_two_star_rs_head
() {
190 atf_set
"descr" "Test awk(1) with regex two star RS"
193 regex_two_star_rs_body
() {
195 -o "inline:1\n2\n3\n4\n\n" \
196 -x "echo 1a2ab3aab4 | $awk 1 RS='aa*b*'"
199 atf_test_case regex_or_1_rs
201 regex_or_1_rs_head
() {
202 atf_set
"descr" "Test awk(1) with regex | case 1 RS"
205 regex_or_1_rs_body
() {
207 -o "inline:1a\nc\n\n" \
208 -x "echo 1abc | $awk 1 RS='abcde|b'"
211 atf_test_case regex_or_2_rs
213 regex_or_2_rs_head
() {
214 atf_set
"descr" "Test awk(1) with regex | case 2 RS"
217 regex_or_2_rs_body
() {
219 -o "inline:1a\ncdf2\n\n" \
220 -x "echo 1abcdf2 | $awk 1 RS='abcde|b'"
223 atf_test_case regex_or_3_rs
225 regex_or_3_rs_head
() {
226 atf_set
"descr" "Test awk(1) with regex | case 3 RS"
229 regex_or_3_rs_body
() {
231 -o "inline:1\n\nf2\n\n" \
232 -x "echo 1abcdebf2 | $awk 1 RS='abcde|b'"
235 atf_test_case regex_or_4_rs
237 regex_or_4_rs_head
() {
238 atf_set
"descr" "Test awk(1) with regex | case 4 RS"
241 regex_or_4_rs_body
() {
243 -o "inline:1\nbcdf2\n\n" \
244 -x "echo 1abcdf2 | $awk 1 RS='abcde|a'"
248 atf_test_case regex_caret_1_rs
250 regex_caret_1_rs_head
() {
251 atf_set
"descr" "Test awk(1) with regex ^ case 1 RS"
254 regex_caret_1_rs_body
() {
256 -o "inline:\n1a2a3a\n\n" \
257 -x "echo a1a2a3a | $awk 1 RS='^a'"
261 atf_test_case regex_caret_2_rs
263 regex_caret_2_rs_head
() {
264 atf_set
"descr" "Test awk(1) with regex ^ case 2 RS"
267 regex_caret_2_rs_body
() {
269 -o "inline:\naa1a2a\n\n" \
270 -x "echo aaa1a2a | $awk 1 RS='^a'"
274 atf_test_case regex_dollar_1_rs
276 regex_dollar_1_rs_head
() {
277 atf_set
"descr" "Test awk(1) with regex $ case 1 RS"
280 regex_dollar_1_rs_body
() {
282 -o "inline:a1a2a3a\n\n" \
283 -x "echo a1a2a3a | $awk 1 RS='a$'"
287 atf_test_case regex_dollar_2_rs
289 regex_dollar_2_rs_head
() {
290 atf_set
"descr" "Test awk(1) with regex $ case 2 RS"
293 regex_dollar_2_rs_body
() {
295 -o "inline:a1a2aaa\n\n" \
296 -x "echo a1a2aaa | $awk 1 RS='a$'"
300 atf_test_case regex_reallocation_rs
302 regex_reallocation_rs_head
() {
303 atf_set
"descr" "Test awk(1) with regex reallocation RS"
306 regex_reallocation_rs_body
() {
308 -o "inline:a\na\na\na\na\na\na\na\na\na10000\n\n" \
309 -x "jot -s a 10000 | $awk 'NR>1' RS='999[0-9]'"
313 atf_test_case empty_rs
316 atf_set
"descr" "Test awk(1) with empty RS"
322 -x "echo foo | $awk 1 RS=''"
326 atf_test_case newline_rs
329 atf_set
"descr" "Test awk(1) with newline RS"
334 -o "inline:r1f1:r1f2\nr2f1:r2f2\n" \
335 -x "printf '\n\n\nr1f1\nr1f2\n\nr2f1\nr2f2\n\n\n' | $awk '{\$1=\$1}1' RS= OFS=:"
338 atf_test_case modify_subsep
340 modify_subsep_head
() {
341 atf_set
"descr" "Test awk(1) SUPSEP modification (PR/47306)"
344 modify_subsep_body
() {
346 -o "inline:1\n1\n1\n" \
347 -x "printf '1\n1 2\n' | \
348 $awk '1{ arr[\$1 SUBSEP \$2 SUBSEP ++cnt[\$1]]=1} {for (f in arr) print arr[f];}'"
351 atf_init_test_cases
() {
353 atf_add_test_case big_regexp
354 atf_add_test_case end
355 atf_add_test_case string1
356 atf_add_test_case multibyte
357 atf_add_test_case period
358 atf_add_test_case assign_NF
360 atf_add_test_case single_char_rs
361 atf_add_test_case two_char_rs
362 atf_add_test_case single_char_regex_group_rs
363 atf_add_test_case two_char_regex_group_rs
364 atf_add_test_case two_char_regex_star_rs
365 atf_add_test_case single_char_regex_star_rs
366 atf_add_test_case regex_two_star_rs
367 atf_add_test_case regex_or_1_rs
368 atf_add_test_case regex_or_2_rs
369 atf_add_test_case regex_or_3_rs
370 atf_add_test_case regex_caret_1_rs
371 atf_add_test_case regex_caret_2_rs
372 atf_add_test_case regex_dollar_1_rs
373 atf_add_test_case regex_dollar_2_rs
374 atf_add_test_case regex_reallocation_rs
375 atf_add_test_case empty_rs
376 atf_add_test_case newline_rs
377 atf_add_test_case modify_subsep