1 |
## compare_shells: dash bash mksh zsh
|
2 |
|
3 |
# Test the length oeprator, which dash supports. Dash doesn't support most
|
4 |
# other ops.
|
5 |
|
6 |
|
7 |
v=foo
|
8 |
echo ${#v}
|
9 |
## stdout: 3
|
10 |
|
11 |
|
12 |
v=$'_\u03bc_'
|
13 |
echo ${#v}
|
14 |
## stdout: 3
|
15 |
## N-I dash stdout: 9
|
16 |
## N-I mksh stdout: 4
|
17 |
|
18 |
|
19 |
v=$(cat $REPO_ROOT/spec/testdata/utf8-chars.txt)
|
20 |
echo ${#v}
|
21 |
## stdout: 7
|
22 |
## N-I dash stdout: 13
|
23 |
## N-I mksh stdout: 13
|
24 |
|
25 |
|
26 |
for num_bytes in 0 1 2 3 4 5 6 7 8 9 10 11 12 13; do
|
27 |
s=$(head -c $num_bytes $REPO_ROOT/spec/testdata/utf8-chars.txt)
|
28 |
echo ${#s}
|
29 |
done 2> $TMP/err.txt
|
30 |
|
31 |
grep 'warning:' $TMP/err.txt
|
32 |
true # exit 0
|
33 |
|
34 |
## STDOUT:
|
35 |
0
|
36 |
1
|
37 |
2
|
38 |
-1
|
39 |
3
|
40 |
4
|
41 |
-1
|
42 |
-1
|
43 |
5
|
44 |
6
|
45 |
-1
|
46 |
-1
|
47 |
-1
|
48 |
7
|
49 |
[ stdin ]:3: warning: UTF-8 decode: Truncated bytes at offset 2 in string of 3 bytes
|
50 |
[ stdin ]:3: warning: UTF-8 decode: Truncated bytes at offset 5 in string of 6 bytes
|
51 |
[ stdin ]:3: warning: UTF-8 decode: Truncated bytes at offset 5 in string of 7 bytes
|
52 |
[ stdin ]:3: warning: UTF-8 decode: Truncated bytes at offset 9 in string of 10 bytes
|
53 |
[ stdin ]:3: warning: UTF-8 decode: Truncated bytes at offset 9 in string of 11 bytes
|
54 |
[ stdin ]:3: warning: UTF-8 decode: Truncated bytes at offset 9 in string of 12 bytes
|
55 |
## END
|
56 |
# zsh behavior actually matches bash!
|
57 |
## BUG bash/zsh stderr-json: ""
|
58 |
## BUG bash/zsh STDOUT:
|
59 |
0
|
60 |
1
|
61 |
2
|
62 |
3
|
63 |
3
|
64 |
4
|
65 |
5
|
66 |
6
|
67 |
5
|
68 |
6
|
69 |
7
|
70 |
8
|
71 |
9
|
72 |
7
|
73 |
## END
|
74 |
## N-I dash/mksh stderr-json: ""
|
75 |
## N-I dash/mksh STDOUT:
|
76 |
0
|
77 |
1
|
78 |
2
|
79 |
3
|
80 |
4
|
81 |
5
|
82 |
6
|
83 |
7
|
84 |
8
|
85 |
9
|
86 |
10
|
87 |
11
|
88 |
12
|
89 |
13
|
90 |
## END
|
91 |
|
92 |
|
93 |
for num_bytes in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14; do
|
94 |
s=$(head -c $num_bytes $REPO_ROOT/spec/testdata/utf8-chars.txt)$(echo -e "\xFF")
|
95 |
echo ${#s}
|
96 |
done 2> $TMP/err.txt
|
97 |
|
98 |
grep 'warning:' $TMP/err.txt
|
99 |
true
|
100 |
|
101 |
## STDOUT:
|
102 |
-1
|
103 |
-1
|
104 |
-1
|
105 |
-1
|
106 |
-1
|
107 |
-1
|
108 |
-1
|
109 |
-1
|
110 |
-1
|
111 |
-1
|
112 |
-1
|
113 |
-1
|
114 |
-1
|
115 |
-1
|
116 |
-1
|
117 |
[ stdin ]:3: warning: UTF-8 decode: Bad encoding at offset 0 in string of 1 bytes
|
118 |
[ stdin ]:3: warning: UTF-8 decode: Bad encoding at offset 1 in string of 2 bytes
|
119 |
[ stdin ]:3: warning: UTF-8 decode: Bad encoding at offset 2 in string of 3 bytes
|
120 |
[ stdin ]:3: warning: UTF-8 decode: Bad encoding at offset 2 in string of 4 bytes
|
121 |
[ stdin ]:3: warning: UTF-8 decode: Bad encoding at offset 4 in string of 5 bytes
|
122 |
[ stdin ]:3: warning: UTF-8 decode: Bad encoding at offset 5 in string of 6 bytes
|
123 |
[ stdin ]:3: warning: UTF-8 decode: Bad encoding at offset 5 in string of 7 bytes
|
124 |
[ stdin ]:3: warning: UTF-8 decode: Bad encoding at offset 5 in string of 8 bytes
|
125 |
[ stdin ]:3: warning: UTF-8 decode: Bad encoding at offset 8 in string of 9 bytes
|
126 |
[ stdin ]:3: warning: UTF-8 decode: Bad encoding at offset 9 in string of 10 bytes
|
127 |
[ stdin ]:3: warning: UTF-8 decode: Bad encoding at offset 9 in string of 11 bytes
|
128 |
[ stdin ]:3: warning: UTF-8 decode: Bad encoding at offset 9 in string of 12 bytes
|
129 |
[ stdin ]:3: warning: UTF-8 decode: Bad encoding at offset 9 in string of 13 bytes
|
130 |
[ stdin ]:3: warning: UTF-8 decode: Bad encoding at offset 13 in string of 14 bytes
|
131 |
[ stdin ]:3: warning: UTF-8 decode: Bad encoding at offset 13 in string of 14 bytes
|
132 |
## END
|
133 |
## BUG bash/zsh stderr-json: ""
|
134 |
## BUG bash/zsh STDOUT:
|
135 |
1
|
136 |
2
|
137 |
3
|
138 |
4
|
139 |
4
|
140 |
5
|
141 |
6
|
142 |
7
|
143 |
6
|
144 |
7
|
145 |
8
|
146 |
9
|
147 |
10
|
148 |
8
|
149 |
8
|
150 |
## N-I dash stderr-json: ""
|
151 |
## N-I dash STDOUT:
|
152 |
7
|
153 |
8
|
154 |
9
|
155 |
10
|
156 |
11
|
157 |
12
|
158 |
13
|
159 |
14
|
160 |
15
|
161 |
16
|
162 |
17
|
163 |
18
|
164 |
19
|
165 |
20
|
166 |
20
|
167 |
## END
|
168 |
## N-I mksh stderr-json: ""
|
169 |
## N-I mksh STDOUT:
|
170 |
1
|
171 |
2
|
172 |
3
|
173 |
4
|
174 |
5
|
175 |
6
|
176 |
7
|
177 |
8
|
178 |
9
|
179 |
10
|
180 |
11
|
181 |
12
|
182 |
13
|
183 |
14
|
184 |
14
|
185 |
## END
|
186 |
|
187 |
|
188 |
echo ${#undef}
|
189 |
## stdout: 0
|
190 |
|
191 |
|
192 |
set -o nounset
|
193 |
echo ${#undef}
|
194 |
## status: 1
|
195 |
## OK dash status: 2
|
196 |
|
197 |
|
198 |
echo ${#x-default}
|
199 |
|
200 |
x=''
|
201 |
echo ${#x-default}
|
202 |
|
203 |
x='foo'
|
204 |
echo ${#x-default}
|
205 |
|
206 |
## status: 2
|
207 |
## OK bash/mksh status: 1
|
208 |
## stdout-json: ""
|
209 |
## BUG zsh status: 0
|
210 |
## BUG zsh STDOUT:
|
211 |
7
|
212 |
0
|
213 |
3
|
214 |
## END
|
215 |
## BUG dash status: 0
|
216 |
## BUG dash STDOUT:
|
217 |
0
|
218 |
0
|
219 |
3
|
220 |
## END
|
221 |
|