aboutsummaryrefslogtreecommitdiff
path: root/testsuite
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2024-07-09 15:30:46 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2024-07-09 15:30:46 +0200
commit38335df9e9f45378c3407defd38b5b610578bdda (patch)
treee543513248930c41a99b55cbdd6cdbb3532e1d66 /testsuite
parent49340d93edc778b193cb40b59cf94dbe38650013 (diff)
downloadbusybox-w32-38335df9e9f45378c3407defd38b5b610578bdda.tar.gz
busybox-w32-38335df9e9f45378c3407defd38b5b610578bdda.tar.bz2
busybox-w32-38335df9e9f45378c3407defd38b5b610578bdda.zip
awk: restore assignment precedence to be lower than ternary ?:
Something is fishy with constrcts like "3==v=3" in gawk, they should not work, but do. Ignore those for now. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'testsuite')
-rwxr-xr-xtestsuite/awk.tests31
1 files changed, 20 insertions, 11 deletions
diff --git a/testsuite/awk.tests b/testsuite/awk.tests
index 063084a1c..be25f6696 100755
--- a/testsuite/awk.tests
+++ b/testsuite/awk.tests
@@ -5,6 +5,7 @@
5 5
6. ./testing.sh 6. ./testing.sh
7 7
8sq="'"
8# testing "description" "command" "result" "infile" "stdin" 9# testing "description" "command" "result" "infile" "stdin"
9 10
10testing "awk -F case 0" "awk -F '[#]' '{ print NF }'" "" "" "" 11testing "awk -F case 0" "awk -F '[#]' '{ print NF }'" "" "" ""
@@ -479,12 +480,6 @@ testing 'awk backslash+newline eaten with no trace' \
479 "Hello world\n" \ 480 "Hello world\n" \
480 '' '' 481 '' ''
481 482
482testing 'awk assign while test' \
483 "awk '\$1==\$1=\"foo\" {print \$1}'" \
484 "foo\n" \
485 "" \
486 "foo"
487
488# User-supplied bug (SEGV) example, was causing use-after-realloc 483# User-supplied bug (SEGV) example, was causing use-after-realloc
489testing 'awk assign while assign' \ 484testing 'awk assign while assign' \
490 "awk '\$5=\$\$5=\$0'; echo \$?" \ 485 "awk '\$5=\$\$5=\$0'; echo \$?" \
@@ -543,16 +538,30 @@ testing 'awk assign while assign' \
543# If field separator FS=' ' (default), fields are split only on 538# If field separator FS=' ' (default), fields are split only on
544# space or tab or linefeed, NOT other whitespace. 539# space or tab or linefeed, NOT other whitespace.
545testing 'awk does not split on CR (char 13)' \ 540testing 'awk does not split on CR (char 13)' \
546 "awk '{ \$1=\$0; print }'" \ 541 'awk '$sq'{ $1=$0; print }'$sq \
547 'word1 word2 word3\r word2 word3\r\n' \ 542 'word1 word2 word3\r word2 word3\r\n' \
548 '' 'word1 word2 word3\r' 543 '' 'word1 word2 word3\r'
549 544
550testing "awk = has higher precedence than == (despite what gawk manpage claims)" \ 545# No, it seems a bug in gawk parser.
551 "awk 'BEGIN { v=1; print 2==v; print 2==v=2; print v; print v=3==3; print v}'" \ 546#testing "awk = has higher precedence than == (despite what gawk manpage claims)" \
552 '0\n1\n2\n1\n3\n' \ 547# "awk 'BEGIN { v=1; print 2==v; print 2==v=2; print v; print v=3==3; print v}'" \
548# '0\n1\n2\n1\n3\n' \
549# '' ''
550#
551#testing 'awk assign while test' \
552# 'awk '$sq'$1==$1="foo" {print $1}'$sq \
553# "foo\n" \
554# "" \
555# "foo"
556
557testing "awk = and ?: precedence" \
558 'awk '$sq'BEGIN { a=0?"bug":"ok"; print a}'$sq \
559 'ok\n' \
553 '' '' 560 '' ''
554 561
555sq="'" 562# TODO: gawk can do this: awk 'BEGIN { u=v=w=1; print u=0?v=4:w=5; print u,v,w}'
563# and even this: u=0?v=4?5:6:w=7?8:9
564
556testing 'awk gensub backslashes \' \ 565testing 'awk gensub backslashes \' \
557 'awk '$sq'BEGIN { s="\\"; print "s=" s; print gensub("a", s, "g", "a|a") }'$sq \ 566 'awk '$sq'BEGIN { s="\\"; print "s=" s; print gensub("a", s, "g", "a|a") }'$sq \
558 's=\\ 567 's=\\