summaryrefslogtreecommitdiff
path: root/shell/hush_test/hush-arith
diff options
context:
space:
mode:
authorDenys Vlasenko2023-06-14 11:33:59 +0200
committerDenys Vlasenko2023-06-14 11:33:59 +0200
commit3df885abe340c5feaed212536139ee24d60e40a2 (patch)
tree18416785d09ee3f19a3effea7a75b170588ae447 /shell/hush_test/hush-arith
parent5febdb122357dbe39e236c9e93d06dab328edb45 (diff)
downloadbusybox-3df885abe340c5feaed212536139ee24d60e40a2.zip
busybox-3df885abe340c5feaed212536139ee24d60e40a2.tar.gz
shell/math: fix the order of variable resolution in binops
function old new delta arith_apply 1134 1143 +9 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell/hush_test/hush-arith')
-rw-r--r--shell/hush_test/hush-arith/arith-assign-in-varexp.right3
-rwxr-xr-xshell/hush_test/hush-arith/arith-assign-in-varexp.tests8
-rw-r--r--shell/hush_test/hush-arith/arith-comma1.right3
-rwxr-xr-xshell/hush_test/hush-arith/arith-comma1.tests6
-rw-r--r--shell/hush_test/hush-arith/arith-ternary2.right3
-rwxr-xr-xshell/hush_test/hush-arith/arith-ternary2.tests7
-rw-r--r--shell/hush_test/hush-arith/arith-ternary_nested.right1
-rwxr-xr-xshell/hush_test/hush-arith/arith-ternary_nested.tests2
8 files changed, 33 insertions, 0 deletions
diff --git a/shell/hush_test/hush-arith/arith-assign-in-varexp.right b/shell/hush_test/hush-arith/arith-assign-in-varexp.right
new file mode 100644
index 0000000..06ac80a
--- /dev/null
+++ b/shell/hush_test/hush-arith/arith-assign-in-varexp.right
@@ -0,0 +1,3 @@
+20:20
+a=b=10
+b=10
diff --git a/shell/hush_test/hush-arith/arith-assign-in-varexp.tests b/shell/hush_test/hush-arith/arith-assign-in-varexp.tests
new file mode 100755
index 0000000..920aaa7
--- /dev/null
+++ b/shell/hush_test/hush-arith/arith-assign-in-varexp.tests
@@ -0,0 +1,8 @@
+exec 2>&1
+a='b=10'
+b=3
+# The variables should evaluate left-to-right,
+# thus b is set to 10 _before_ addition
+echo 20:$((a + b))
+echo "a=$a"
+echo "b=$b"
diff --git a/shell/hush_test/hush-arith/arith-comma1.right b/shell/hush_test/hush-arith/arith-comma1.right
new file mode 100644
index 0000000..be1264c
--- /dev/null
+++ b/shell/hush_test/hush-arith/arith-comma1.right
@@ -0,0 +1,3 @@
+10:10
+a=b=10
+b=10
diff --git a/shell/hush_test/hush-arith/arith-comma1.tests b/shell/hush_test/hush-arith/arith-comma1.tests
new file mode 100755
index 0000000..f863043
--- /dev/null
+++ b/shell/hush_test/hush-arith/arith-comma1.tests
@@ -0,0 +1,6 @@
+exec 2>&1
+a='b=10'
+b=3
+echo 10:$((a,b))
+echo "a=$a"
+echo "b=$b"
diff --git a/shell/hush_test/hush-arith/arith-ternary2.right b/shell/hush_test/hush-arith/arith-ternary2.right
new file mode 100644
index 0000000..a549b1b
--- /dev/null
+++ b/shell/hush_test/hush-arith/arith-ternary2.right
@@ -0,0 +1,3 @@
+6:6
+a=b=+err+
+b=6
diff --git a/shell/hush_test/hush-arith/arith-ternary2.tests b/shell/hush_test/hush-arith/arith-ternary2.tests
new file mode 100755
index 0000000..cb31639
--- /dev/null
+++ b/shell/hush_test/hush-arith/arith-ternary2.tests
@@ -0,0 +1,7 @@
+exec 2>&1
+a='b=+err+'
+b=5
+# The not-taken branch should not parse variables
+echo 6:$((0 ? a : ++b))
+echo "a=$a"
+echo "b=$b"
diff --git a/shell/hush_test/hush-arith/arith-ternary_nested.right b/shell/hush_test/hush-arith/arith-ternary_nested.right
new file mode 100644
index 0000000..aa54bd9
--- /dev/null
+++ b/shell/hush_test/hush-arith/arith-ternary_nested.right
@@ -0,0 +1 @@
+5:5
diff --git a/shell/hush_test/hush-arith/arith-ternary_nested.tests b/shell/hush_test/hush-arith/arith-ternary_nested.tests
new file mode 100755
index 0000000..eefc8e7
--- /dev/null
+++ b/shell/hush_test/hush-arith/arith-ternary_nested.tests
@@ -0,0 +1,2 @@
+exec 2>&1
+echo 5:$((1?2?3?4?5:6:7:8:9))