diff options
Diffstat (limited to 'usr.bin/awk')
| -rw-r--r-- | usr.bin/awk/Makefile | 34 | ||||
| -rw-r--r-- | usr.bin/awk/d_assign_NF.awk | 16 | ||||
| -rw-r--r-- | usr.bin/awk/d_assign_NF.in | 1 | ||||
| -rw-r--r-- | usr.bin/awk/d_assign_NF.out | 9 | ||||
| -rw-r--r-- | usr.bin/awk/d_big_regexp.awk | 3 | ||||
| -rw-r--r-- | usr.bin/awk/d_big_regexp.in | 1 | ||||
| -rw-r--r-- | usr.bin/awk/d_big_regexp.out | 1 | ||||
| -rw-r--r-- | usr.bin/awk/d_end1.awk | 5 | ||||
| -rw-r--r-- | usr.bin/awk/d_end1.in | 1 | ||||
| -rw-r--r-- | usr.bin/awk/d_end1.out | 1 | ||||
| -rw-r--r-- | usr.bin/awk/d_end2.awk | 5 | ||||
| -rw-r--r-- | usr.bin/awk/d_end2.in | 1 | ||||
| -rw-r--r-- | usr.bin/awk/d_end2.out | 1 | ||||
| -rw-r--r-- | usr.bin/awk/d_period.awk | 1 | ||||
| -rw-r--r-- | usr.bin/awk/d_period.in | 1 | ||||
| -rw-r--r-- | usr.bin/awk/d_period.out | 1 | ||||
| -rw-r--r-- | usr.bin/awk/d_string1.awk | 7 | ||||
| -rw-r--r-- | usr.bin/awk/d_string1.out | 2 | ||||
| -rw-r--r-- | usr.bin/awk/d_tolower.awk | 5 | ||||
| -rw-r--r-- | usr.bin/awk/d_tolower.in | 1 | ||||
| -rw-r--r-- | usr.bin/awk/d_tolower.out | 1 | ||||
| -rw-r--r-- | usr.bin/awk/d_toupper.awk | 5 | ||||
| -rw-r--r-- | usr.bin/awk/d_toupper.in | 1 | ||||
| -rw-r--r-- | usr.bin/awk/d_toupper.out | 1 | ||||
| -rwxr-xr-x | usr.bin/awk/t_awk.sh | 378 |
25 files changed, 483 insertions, 0 deletions
diff --git a/usr.bin/awk/Makefile b/usr.bin/awk/Makefile new file mode 100644 index 000000000000..8a3a43f5421b --- /dev/null +++ b/usr.bin/awk/Makefile @@ -0,0 +1,34 @@ +# $NetBSD: Makefile,v 1.2 2012/03/11 18:35:59 jruoho Exp $ + +.include <bsd.own.mk> + +TESTSDIR= ${TESTSBASE}/usr.bin/awk +TESTS_SH= t_awk +NOMAN= # defined + +FILESDIR= ${TESTSDIR} +FILES= d_big_regexp.awk +FILES+= d_big_regexp.in +FILES+= d_big_regexp.out +FILES+= d_end1.awk +FILES+= d_end1.in +FILES+= d_end1.out +FILES+= d_end2.awk +FILES+= d_end2.in +FILES+= d_end2.out +FILES+= d_period.awk +FILES+= d_period.in +FILES+= d_period.out +FILES+= d_string1.awk +FILES+= d_string1.out +FILES+= d_tolower.awk +FILES+= d_tolower.in +FILES+= d_tolower.out +FILES+= d_toupper.awk +FILES+= d_toupper.in +FILES+= d_toupper.out +FILES+= d_assign_NF.awk +FILES+= d_assign_NF.in +FILES+= d_assign_NF.out + +.include <bsd.test.mk>
\ No newline at end of file diff --git a/usr.bin/awk/d_assign_NF.awk b/usr.bin/awk/d_assign_NF.awk new file mode 100644 index 000000000000..52c39124cbf6 --- /dev/null +++ b/usr.bin/awk/d_assign_NF.awk @@ -0,0 +1,16 @@ +# $NetBSD: d_assign_NF.awk,v 1.1 2012/03/11 18:35:59 jruoho Exp $ + +{ + NF = 2 + print "$0=`" $0 "`" + print "$3=`" $3 "`" + print "$4=`" $4 "`" + NF = 3 + print "$0=`" $0 "`" + print "$3=`" $3 "`" + print "$4=`" $4 "`" + NF = 4 + print "$0=`" $0 "`" + print "$3=`" $3 "`" + print "$4=`" $4 "`" +} diff --git a/usr.bin/awk/d_assign_NF.in b/usr.bin/awk/d_assign_NF.in new file mode 100644 index 000000000000..1245b922123b --- /dev/null +++ b/usr.bin/awk/d_assign_NF.in @@ -0,0 +1 @@ + 1 2 3 diff --git a/usr.bin/awk/d_assign_NF.out b/usr.bin/awk/d_assign_NF.out new file mode 100644 index 000000000000..2631a7a92db8 --- /dev/null +++ b/usr.bin/awk/d_assign_NF.out @@ -0,0 +1,9 @@ +$0=`1 2` +$3=`` +$4=`` +$0=`1 2 ` +$3=`` +$4=`` +$0=`1 2 ` +$3=`` +$4=`` diff --git a/usr.bin/awk/d_big_regexp.awk b/usr.bin/awk/d_big_regexp.awk new file mode 100644 index 000000000000..1502b5e75462 --- /dev/null +++ b/usr.bin/awk/d_big_regexp.awk @@ -0,0 +1,3 @@ +# $NetBSD: d_big_regexp.awk,v 1.1 2012/03/11 18:36:00 jruoho Exp $ + +/^[^_][^ ]*_NNIFO([ ]+[^_]+[^ ]*_(CC|INR|JJFO|JJMA|JJPG|NNIFG|NNIFO|NNIMPG|NNIMR|NNING|PP3FD|PQINO|PQMO|PSFR|RQ|TC|VIIR3|VPIPN|VPLIPF|NOTAG|RQR))*$/ diff --git a/usr.bin/awk/d_big_regexp.in b/usr.bin/awk/d_big_regexp.in new file mode 100644 index 000000000000..ad82078afc0d --- /dev/null +++ b/usr.bin/awk/d_big_regexp.in @@ -0,0 +1 @@ +1_NNIFO 1_PSFR 1_JJFO 1_NNIFO 1_INR 1_NNIMR 1_CC 1_NNING 1_RQ 1_VPLIPF 1_NNIFG 1_JJPG 1_NNIMPG 1_PQINO 1_VPIPN 1_PP3FD 1_JJMA 1_PQMO 1_TC 1_VIIR3 diff --git a/usr.bin/awk/d_big_regexp.out b/usr.bin/awk/d_big_regexp.out new file mode 100644 index 000000000000..ad82078afc0d --- /dev/null +++ b/usr.bin/awk/d_big_regexp.out @@ -0,0 +1 @@ +1_NNIFO 1_PSFR 1_JJFO 1_NNIFO 1_INR 1_NNIMR 1_CC 1_NNING 1_RQ 1_VPLIPF 1_NNIFG 1_JJPG 1_NNIMPG 1_PQINO 1_VPIPN 1_PP3FD 1_JJMA 1_PQMO 1_TC 1_VIIR3 diff --git a/usr.bin/awk/d_end1.awk b/usr.bin/awk/d_end1.awk new file mode 100644 index 000000000000..cb8b0d0ed208 --- /dev/null +++ b/usr.bin/awk/d_end1.awk @@ -0,0 +1,5 @@ +# $NetBSD: d_end1.awk,v 1.1 2012/03/11 18:36:00 jruoho Exp $ + +END { + print NF; +} diff --git a/usr.bin/awk/d_end1.in b/usr.bin/awk/d_end1.in new file mode 100644 index 000000000000..8e13e468a002 --- /dev/null +++ b/usr.bin/awk/d_end1.in @@ -0,0 +1 @@ +a b c d diff --git a/usr.bin/awk/d_end1.out b/usr.bin/awk/d_end1.out new file mode 100644 index 000000000000..b8626c4cff28 --- /dev/null +++ b/usr.bin/awk/d_end1.out @@ -0,0 +1 @@ +4 diff --git a/usr.bin/awk/d_end2.awk b/usr.bin/awk/d_end2.awk new file mode 100644 index 000000000000..8b10b828779c --- /dev/null +++ b/usr.bin/awk/d_end2.awk @@ -0,0 +1,5 @@ +# $NetBSD: d_end2.awk,v 1.1 2012/03/11 18:36:00 jruoho Exp $ + +END { + print $0; +} diff --git a/usr.bin/awk/d_end2.in b/usr.bin/awk/d_end2.in new file mode 100644 index 000000000000..8e13e468a002 --- /dev/null +++ b/usr.bin/awk/d_end2.in @@ -0,0 +1 @@ +a b c d diff --git a/usr.bin/awk/d_end2.out b/usr.bin/awk/d_end2.out new file mode 100644 index 000000000000..8e13e468a002 --- /dev/null +++ b/usr.bin/awk/d_end2.out @@ -0,0 +1 @@ +a b c d diff --git a/usr.bin/awk/d_period.awk b/usr.bin/awk/d_period.awk new file mode 100644 index 000000000000..d1dabf751304 --- /dev/null +++ b/usr.bin/awk/d_period.awk @@ -0,0 +1 @@ +{print x + $1 + 0.125} diff --git a/usr.bin/awk/d_period.in b/usr.bin/awk/d_period.in new file mode 100644 index 000000000000..d10c0e2f9d08 --- /dev/null +++ b/usr.bin/awk/d_period.in @@ -0,0 +1 @@ +0,25 diff --git a/usr.bin/awk/d_period.out b/usr.bin/awk/d_period.out new file mode 100644 index 000000000000..3382aa6e35b8 --- /dev/null +++ b/usr.bin/awk/d_period.out @@ -0,0 +1 @@ +0.625 diff --git a/usr.bin/awk/d_string1.awk b/usr.bin/awk/d_string1.awk new file mode 100644 index 000000000000..d690240fa17b --- /dev/null +++ b/usr.bin/awk/d_string1.awk @@ -0,0 +1,7 @@ +# $NetBSD: d_string1.awk,v 1.1 2012/03/11 18:36:00 jruoho Exp $ + +BEGIN { + print "A\ +B"; + print "CD" +} diff --git a/usr.bin/awk/d_string1.out b/usr.bin/awk/d_string1.out new file mode 100644 index 000000000000..96c017b97b70 --- /dev/null +++ b/usr.bin/awk/d_string1.out @@ -0,0 +1,2 @@ +AB +CD diff --git a/usr.bin/awk/d_tolower.awk b/usr.bin/awk/d_tolower.awk new file mode 100644 index 000000000000..258d181ce30b --- /dev/null +++ b/usr.bin/awk/d_tolower.awk @@ -0,0 +1,5 @@ +# $NetBSD: d_tolower.awk,v 1.1 2012/03/11 18:36:00 jruoho Exp $ + +END { + print tolower($0); +} diff --git a/usr.bin/awk/d_tolower.in b/usr.bin/awk/d_tolower.in new file mode 100644 index 000000000000..66ed03c2d27a --- /dev/null +++ b/usr.bin/awk/d_tolower.in @@ -0,0 +1 @@ +ABCÆØÅ diff --git a/usr.bin/awk/d_tolower.out b/usr.bin/awk/d_tolower.out new file mode 100644 index 000000000000..83b2bf51cdf4 --- /dev/null +++ b/usr.bin/awk/d_tolower.out @@ -0,0 +1 @@ +abcæøå diff --git a/usr.bin/awk/d_toupper.awk b/usr.bin/awk/d_toupper.awk new file mode 100644 index 000000000000..0719aa9b86e9 --- /dev/null +++ b/usr.bin/awk/d_toupper.awk @@ -0,0 +1,5 @@ +# $NetBSD: d_toupper.awk,v 1.1 2012/03/11 18:36:01 jruoho Exp $ + +END { + print toupper($0); +} diff --git a/usr.bin/awk/d_toupper.in b/usr.bin/awk/d_toupper.in new file mode 100644 index 000000000000..83b2bf51cdf4 --- /dev/null +++ b/usr.bin/awk/d_toupper.in @@ -0,0 +1 @@ +abcæøå diff --git a/usr.bin/awk/d_toupper.out b/usr.bin/awk/d_toupper.out new file mode 100644 index 000000000000..66ed03c2d27a --- /dev/null +++ b/usr.bin/awk/d_toupper.out @@ -0,0 +1 @@ +ABCÆØÅ diff --git a/usr.bin/awk/t_awk.sh b/usr.bin/awk/t_awk.sh new file mode 100755 index 000000000000..77cb5f86df01 --- /dev/null +++ b/usr.bin/awk/t_awk.sh @@ -0,0 +1,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 +} |
