OILS / spec / assign-deferred.test.sh View on Github | oilshell.org

107 lines, 51 significant
1## compare_shells: bash mksh
2## our_shell: -
3
4# Corner cases for assignment that we're not handling now.
5
6#### typeset a[3]=4
7typeset a[3]=4 a[5]=6
8echo status=$?
9argv.py "${!a[@]}" "${a[@]}"
10## STDOUT:
11status=0
12['3', '5', '4', '6']
13## END
14
15#### typeset -a a[1]=a a[3]=c
16# declare works the same way in bash, but not mksh.
17# spaces are NOT allowed here.
18typeset -a a[1*1]=x a[1+2]=z
19argv.py "${a[@]}"
20## stdout: ['x', 'z']
21
22#### local a[3]=4
23f() {
24 local a[3]=4 a[5]=6
25 echo status=$?
26 argv.py "${!a[@]}" "${a[@]}"
27}
28f
29## STDOUT:
30status=0
31['3', '5', '4', '6']
32## END
33
34#### readonly a[7]=8
35readonly b[7]=8
36echo status=$?
37argv.py "${!b[@]}" "${b[@]}"
38## STDOUT:
39status=0
40['7', '8']
41## END
42
43# bash doesn't like this variable name!
44## N-I bash STDOUT:
45status=1
46[]
47## END
48
49#### export a[7]=8
50export a[7]=8
51echo status=$?
52argv.py "${!a[@]}" "${a[@]}"
53printenv.py a
54## STDOUT:
55status=1
56[]
57None
58## END
59## OK osh STDOUT:
60status=2
61[]
62None
63## END
64## BUG mksh STDOUT:
65status=0
66['7', '8']
67None
68## END
69
70#### 'builtin' prefix is allowed on assignments
71builtin export e='E'
72echo e=$e
73## STDOUT:
74e=E
75## END
76## N-I dash STDOUT:
77e=
78## END
79
80#### 'command' prefix is allowed on assignments
81readonly r1='R1' # zsh has this
82command readonly r2='R2' # but not this
83echo r1=$r1
84echo r2=$r2
85## STDOUT:
86r1=R1
87r2=R2
88## END
89## N-I zsh STDOUT:
90r1=R1
91r2=
92## END
93
94#### 'builtin' prefix and array is a parse error
95builtin typeset a=(1 2 3)
96echo len=${#a[@]}
97## stdout-json: ""
98## status: 2
99## OK mksh status: 1
100
101#### 'command' prefix and array is a parse error
102command typeset a=(1 2 3)
103echo len=${#a[@]}
104## stdout-json: ""
105## status: 2
106## OK mksh status: 1
107