summaryrefslogtreecommitdiffstats
path: root/contrib/netbsd-tests/usr.bin/awk/t_awk.sh
blob: 77cb5f86df01affcea8ece126014d0418a4e7f39 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
# $NetBSD: t_awk.sh,v 1.5 2012/12/10 20:30:06 christos Exp $
#
# Copyright (c) 2012 The NetBSD Foundation, Inc.
# All rights reserved.
#
# This code is derived from software contributed to The NetBSD Foundation
# by Christos Zoulas
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#

awk=awk

h_check()
{
	local fname=d_$1
	for sfx in in out awk; do
		cp -r $(atf_get_srcdir)/$fname.$sfx .
	done
	shift 1
	atf_check -o file:$fname.out -x "awk $@ -f $fname.awk < $fname.in"
}

atf_test_case big_regexp

big_regexp_head() {
	atf_set "descr" "Checks matching long regular expressions (PR/33392)"
}

big_regexp_body() {
	h_check big_regexp
}

atf_test_case end

end_head() {
	atf_set "descr" "Checks that the last line of the input" \
	                "is available under END pattern (PR/29659)"
}

end_body() {
	h_check end1
	h_check end2
}

atf_test_case string1

string1_head() {
	atf_set "descr" "Checks escaping newlines in string literals"
}

string1_body() {
	for sfx in out awk; do
		cp -r $(atf_get_srcdir)/d_string1.$sfx .
	done
	atf_check -o file:d_string1.out awk -f d_string1.awk
}

atf_test_case multibyte

multibyte_head() {
	atf_set "descr" "Checks multibyte charsets support" \
	                "in tolower and toupper (PR/36394)"
}

multibyte_body() {
	export LANG=en_US.UTF-8

	h_check tolower
	h_check toupper
}

atf_test_case period

period_head() {
	atf_set "descr" "Checks that the period character is recognised" \
	                "in awk program regardless of locale (bin/42320)"
}

period_body() {
	export LANG=ru_RU.KOI8-R

	h_check period -v x=0.5
}

atf_test_case assign_NF

assign_NF_head() {
	atf_set "descr" 'Checks that assign to NF changes $0 and $n (PR/44063)'
}

assign_NF_body() {
	h_check assign_NF
}

atf_test_case single_char_rs

single_char_rs_head() {
	atf_set "descr" "Test awk(1) with single character RS"
}

single_char_rs_body() {
	atf_check \
		-o "inline:1\n2\n\n3\n\n\n4\n\n" \
		-x "echo 1a2aa3aaa4 | $awk 1 RS=a"
}

atf_test_case two_char_rs

two_char_rs_head() {
	atf_set "descr" "Test awk(1) with two characters RS"
}

two_char_rs_body() {
	atf_check \
		-o "inline:1\n2\n3\n4\n\n" \
		-x "echo 1ab2ab3ab4 | $awk 1 RS=ab"
}

atf_test_case single_char_regex_group_rs

single_char_regex_group_rs_head() {
	atf_set "descr" "Test awk(1) with single character regex group RS"
}

single_char_regex_group_rs_body() {
	atf_check \
		-o "inline:1\n2\n\n3\n\n\n4\n\n" \
		-x "echo 1a2aa3aaa4 | $awk 1 RS='[a]'"
}

atf_test_case two_char_regex_group_rs

two_char_regex_group_rs_head() {
	atf_set "descr" "Test awk(1) with two characters regex group RS"
}

two_char_regex_group_rs_body() {
	atf_check \
		-o "inline:1\n2\n\n3\n\n\n4\n\n" \
		-x "echo 1a2ab3aba4 | $awk 1 RS='[ab]'"
}

atf_test_case single_char_regex_star_rs

single_char_regex_star_rs_head() {
	atf_set "descr" "Test awk(1) with single character regex star RS"
}

single_char_regex_star_rs_body() {
	atf_check \
		-o "inline:1\n2\n3\n4\n\n" \
		-x "echo 1a2aa3aaa4 | $awk 1 RS='a*'"
}

atf_test_case two_char_regex_star_rs

two_char_regex_star_rs_head() {
	atf_set "descr" "Test awk(1) with two characters regex star RS"
}

two_char_regex_star_rs_body() {
	atf_check \
		-o "inline:1\n2\n3\n4\n\n" \
		-x "echo 1a2aa3aaa4 | $awk 1 RS='aa*'"
}

atf_test_case regex_two_star_rs

regex_two_star_rs_head() {
	atf_set "descr" "Test awk(1) with regex two star RS"
}

regex_two_star_rs_body() {
	atf_check \
		-o "inline:1\n2\n3\n4\n\n" \
		-x "echo 1a2ab3aab4 | $awk 1 RS='aa*b*'"
}

atf_test_case regex_or_1_rs

regex_or_1_rs_head() {
	atf_set "descr" "Test awk(1) with regex | case 1 RS"
}

regex_or_1_rs_body() {
	atf_check \
		-o "inline:1a\nc\n\n" \
		-x "echo 1abc | $awk 1 RS='abcde|b'"
}

atf_test_case regex_or_2_rs

regex_or_2_rs_head() {
	atf_set "descr" "Test awk(1) with regex | case 2 RS"
}

regex_or_2_rs_body() {
	atf_check \
		-o "inline:1a\ncdf2\n\n" \
		-x "echo 1abcdf2 | $awk 1 RS='abcde|b'"
}

atf_test_case regex_or_3_rs

regex_or_3_rs_head() {
	atf_set "descr" "Test awk(1) with regex | case 3 RS"
}

regex_or_3_rs_body() {
	atf_check \
		-o "inline:1\n\nf2\n\n" \
		-x "echo 1abcdebf2 | $awk 1 RS='abcde|b'"
}

atf_test_case regex_or_4_rs

regex_or_4_rs_head() {
	atf_set "descr" "Test awk(1) with regex | case 4 RS"
}

regex_or_4_rs_body() {
	atf_check \
		-o "inline:1\nbcdf2\n\n" \
		-x "echo 1abcdf2 | $awk 1 RS='abcde|a'"

}

atf_test_case regex_caret_1_rs

regex_caret_1_rs_head() {
	atf_set "descr" "Test awk(1) with regex ^ case 1 RS"
}

regex_caret_1_rs_body() {
	atf_check \
		-o "inline:\n1a2a3a\n\n" \
		-x "echo a1a2a3a | $awk 1 RS='^a'"

}

atf_test_case regex_caret_2_rs

regex_caret_2_rs_head() {
	atf_set "descr" "Test awk(1) with regex ^ case 2 RS"
}

regex_caret_2_rs_body() {
	atf_check \
		-o "inline:\naa1a2a\n\n" \
		-x "echo aaa1a2a | $awk 1 RS='^a'"

}

atf_test_case regex_dollar_1_rs

regex_dollar_1_rs_head() {
	atf_set "descr" "Test awk(1) with regex $ case 1 RS"
}

regex_dollar_1_rs_body() {
	atf_check \
		-o "inline:a1a2a3a\n\n" \
		-x "echo a1a2a3a | $awk 1 RS='a$'"

}

atf_test_case regex_dollar_2_rs

regex_dollar_2_rs_head() {
	atf_set "descr" "Test awk(1) with regex $ case 2 RS"
}

regex_dollar_2_rs_body() {
	atf_check \
		-o "inline:a1a2aaa\n\n" \
		-x "echo a1a2aaa | $awk 1 RS='a$'"

}

atf_test_case regex_reallocation_rs

regex_reallocation_rs_head() {
	atf_set "descr" "Test awk(1) with regex reallocation RS"
}

regex_reallocation_rs_body() {
	atf_check \
		-o "inline:a\na\na\na\na\na\na\na\na\na10000\n\n" \
		-x "jot -s a 10000 | $awk 'NR>1' RS='999[0-9]'"

}

atf_test_case empty_rs

empty_rs_head() {
	atf_set "descr" "Test awk(1) with empty RS"
}

empty_rs_body() {
	atf_check \
		-o "inline:foo\n" \
		-x "echo foo | $awk 1 RS=''"

}

atf_test_case newline_rs

newline_rs_head() {
	atf_set "descr" "Test awk(1) with newline RS"
}

newline_rs_body() {
	atf_check \
		-o "inline:r1f1:r1f2\nr2f1:r2f2\n" \
		-x "printf '\n\n\nr1f1\nr1f2\n\nr2f1\nr2f2\n\n\n' | $awk '{\$1=\$1}1' RS= OFS=:"
}

atf_test_case modify_subsep

modify_subsep_head() {
	atf_set "descr" "Test awk(1) SUPSEP modification (PR/47306)"
}

modify_subsep_body() {
	atf_check \
		-o "inline:1\n1\n1\n" \
		-x "printf '1\n1 2\n' | \
		$awk '1{ arr[\$1 SUBSEP \$2 SUBSEP ++cnt[\$1]]=1} {for (f in arr) print arr[f];}'"
}

atf_init_test_cases() {

	atf_add_test_case big_regexp
	atf_add_test_case end
	atf_add_test_case string1
	atf_add_test_case multibyte
	atf_add_test_case period
	atf_add_test_case assign_NF

	atf_add_test_case single_char_rs
	atf_add_test_case two_char_rs
	atf_add_test_case single_char_regex_group_rs
	atf_add_test_case two_char_regex_group_rs
	atf_add_test_case two_char_regex_star_rs
	atf_add_test_case single_char_regex_star_rs
	atf_add_test_case regex_two_star_rs
	atf_add_test_case regex_or_1_rs
	atf_add_test_case regex_or_2_rs
	atf_add_test_case regex_or_3_rs
	atf_add_test_case regex_caret_1_rs
	atf_add_test_case regex_caret_2_rs
	atf_add_test_case regex_dollar_1_rs
	atf_add_test_case regex_dollar_2_rs
	atf_add_test_case regex_reallocation_rs
	atf_add_test_case empty_rs
	atf_add_test_case newline_rs
	atf_add_test_case modify_subsep
}
OpenPOWER on IntegriCloud