OILS / spec / arith-dynamic.test.sh View on Github | oilshell.org

95 lines, 32 significant
1## compare_shells: bash dash mksh zsh
2## oils_failures_allowed: 3
3
4# Various tests for dynamic parsing of arithmetic substitutions.
5
6#### Double quotes
7echo $(( "1 + 2" * 3 ))
8echo $(( "1+2" * 3 ))
9## STDOUT:
107
117
12## END
13
14## N-I dash status: 2
15## N-I dash STDOUT:
16## END
17
18## N-I mksh status: 1
19## N-I mksh STDOUT:
20## END
21
22## N-I zsh status: 1
23## N-I zsh STDOUT:
24## END
25
26#### Single quotes
27echo $(( '1' + '2' * 3 ))
28echo status=$?
29
30echo $(( '1 + 2' * 3 ))
31echo status=$?
32## STDOUT:
33status=1
34status=1
35## END
36
37## N-I dash status: 2
38## N-I dash STDOUT:
39## END
40
41## BUG mksh status: 1
42## BUG mksh STDOUT:
43199
44status=0
45## END
46
47## N-I zsh status: 1
48## N-I zsh STDOUT:
49## END
50
51#### Substitutions
52x='1 + 2'
53echo $(( $x * 3 ))
54echo $(( "$x" * 3 ))
55## STDOUT:
567
577
58## END
59
60## N-I dash status: 2
61## N-I dash STDOUT:
627
63## END
64
65## N-I mksh status: 1
66## N-I mksh STDOUT:
677
68## END
69
70## N-I zsh status: 1
71## N-I zsh STDOUT:
727
73## END
74
75#### Variable references
76x='1'
77echo $(( x + 2 * 3 ))
78echo status=$?
79
80# Expression like values are evaluated first (this is unlike double quotes)
81x='1 + 2'
82echo $(( x * 3 ))
83echo status=$?
84## STDOUT:
857
86status=0
879
88status=0
89## END
90
91## N-I dash status: 2
92## N-I dash STDOUT:
937
94status=0
95## END