Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/bin/sh Add tests for the $(( )) assignment operators ...
details: https://anonhg.NetBSD.org/src/rev/38de9e26b4d7
branches: trunk
changeset: 352187:38de9e26b4d7
user: kre <kre%NetBSD.org@localhost>
date: Mon Mar 20 11:32:51 2017 +0000
description:
Add tests for the $(( )) assignment operators PR bin/50958
diffstat:
tests/bin/sh/t_arith.sh | 61 +++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 59 insertions(+), 2 deletions(-)
diffs (81 lines):
diff -r 6fa37d2d6461 -r 38de9e26b4d7 tests/bin/sh/t_arith.sh
--- a/tests/bin/sh/t_arith.sh Mon Mar 20 11:31:00 2017 +0000
+++ b/tests/bin/sh/t_arith.sh Mon Mar 20 11:32:51 2017 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: t_arith.sh,v 1.5 2016/05/12 14:25:11 kre Exp $
+# $NetBSD: t_arith.sh,v 1.6 2017/03/20 11:32:51 kre Exp $
#
# Copyright (c) 2016 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -980,6 +980,63 @@
'echo $(( (0xfD & 0xF) == 0xF ))'
}
+atf_test_case var_assign
+var_assign_head()
+{
+ atf_set "descr" "Test assignment operators in arithmetic expressions"
+}
+var_assign_body()
+{
+ atf_check -s exit:0 -o inline:'3\n3\n' -e empty ${TEST_SH} -c \
+ 'unset x; echo $(( x = 3 )); echo $x'
+ atf_check -s exit:0 -o inline:'3\n3\n' -e empty ${TEST_SH} -c \
+ 'unset x; echo $((x=3)); echo $x'
+ atf_check -s exit:0 -o inline:'3\n3\n' -e empty ${TEST_SH} -c \
+ 'x=5; echo $((x=3)); echo $x'
+
+ atf_check -s exit:0 -o inline:'3\n3\n' -e empty ${TEST_SH} -c \
+ 'set +u;unset x; echo $((x+=3)); echo $x'
+ atf_check -s exit:0 -o inline:'3\n3\n' -e empty ${TEST_SH} -c \
+ 'x=2; echo $((x+=1)); echo $x'
+ atf_check -s exit:0 -o inline:'3\n3\n' -e empty ${TEST_SH} -c \
+ 'x=4; echo $((x-=1)); echo $x'
+ atf_check -s exit:0 -o inline:'3\n3\n' -e empty ${TEST_SH} -c \
+ 'x=3; echo $((x*=1)); echo $x'
+ atf_check -s exit:0 -o inline:'3\n3\n' -e empty ${TEST_SH} -c \
+ 'x=3; echo $((x/=1)); echo $x'
+ atf_check -s exit:0 -o inline:'3\n3\n' -e empty ${TEST_SH} -c \
+ 'x=28; echo $((x%=5)); echo $x'
+ atf_check -s exit:0 -o inline:'3\n3\n' -e empty ${TEST_SH} -c \
+ 'x=7; echo $((x&=3)); echo $x'
+ atf_check -s exit:0 -o inline:'3\n3\n' -e empty ${TEST_SH} -c \
+ 'x=2; echo $((x|=1)); echo $x'
+ atf_check -s exit:0 -o inline:'3\n3\n' -e empty ${TEST_SH} -c \
+ 'x=6; echo $((x^=5)); echo $x'
+ atf_check -s exit:0 -o inline:'3\n3\n' -e empty ${TEST_SH} -c \
+ 'x=7; echo $((x>>=1)); echo $x'
+ atf_check -s exit:0 -o inline:'2\n2\n' -e empty ${TEST_SH} -c \
+ 'x=1; echo $((x<<=1)); echo $x'
+
+ atf_check -s exit:0 -o inline:'2\n3\n' -e empty ${TEST_SH} -c \
+ 'x=2; echo $(( (x+=1)-1 )); echo $x'
+ atf_check -s exit:0 -o inline:'4\n3\n' -e empty ${TEST_SH} -c \
+ 'x=4; echo $(( (x-=1)+1 )); echo $x'
+
+ atf_check -s exit:0 -o inline:'36\n5 7\n' -e empty ${TEST_SH} -c \
+ 'unset x y; echo $(( (x=5) * (y=7) + 1 )); echo $x $y'
+ atf_check -s exit:0 -o inline:'36\n5 7\n' -e empty ${TEST_SH} -c \
+ 'x=99; y=17; echo $(( (x=5) * (y=7) + 1 )); echo $x $y'
+ atf_check -s exit:0 -o inline:'36\n5 7\n' -e empty ${TEST_SH} -c \
+ 'x=4; y=9; echo $(( (x+=1) * (y-=2) + 1 )); echo $x $y'
+
+ atf_check -s exit:0 -o inline:'3\n3\n' -e empty ${TEST_SH} -c \
+ 'set -u; unset x; echo $(( x = 3 )); echo $x'
+ atf_check -s not-exit:0 -o ignore -e not-empty ${TEST_SH} -c \
+ 'set -u; unset x; echo $(( x + 3 )); echo $x'
+ atf_check -s not-exit:0 -o ignore -e not-empty ${TEST_SH} -c \
+ 'set -u; unset x; echo $(( x+=3 )); echo $x'
+}
+
atf_test_case arithmetic_fails
arithmetic_fails_head()
{
@@ -1030,6 +1087,6 @@
# atf_add_test_case progressive # build up big expr
# atf_add_test_case test_errors # erroneous input
# atf_add_test_case torture # hard stuff (if there is any)
- # atf_add_test_case var_assign # assignment ops
+ atf_add_test_case var_assign # assignment ops
# atf_add_test_case vulgarity # truly evil inputs (syntax in vars...)
}
Home |
Main Index |
Thread Index |
Old Index