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

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