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