Skip to content

Commit bbc7a2d

Browse files
author
Andy Chu
committed
[spec/builtin-set] Failing test case for 'set -' special case
This is issue #2364
1 parent ceac37a commit bbc7a2d

File tree

1 file changed

+83
-39
lines changed

1 file changed

+83
-39
lines changed

spec/builtin-set.test.sh

Lines changed: 83 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
## compare_shells: bash dash mksh zsh
2+
## oils_failures_allowed: 1
23

34
#### can continue after unknown option
45
#
@@ -22,7 +23,6 @@ echo done
2223
## stdout: a b c
2324
## status: 1
2425

25-
2626
#### nounset with "$@"
2727
set a b c
2828
set -u # shouldn't touch argv
@@ -63,6 +63,56 @@ echo status=$?
6363
## status: 1
6464
## OK dash status: 2
6565

66+
#### set -o lists options
67+
# NOTE: osh doesn't use the same format yet.
68+
set -o | grep -o noexec
69+
## STDOUT:
70+
noexec
71+
## END
72+
73+
#### 'set' and 'eval' round trip
74+
75+
# NOTE: not testing arrays and associative arrays!
76+
_space='[ ]'
77+
_whitespace=$'[\t\r\n]'
78+
_sq="'single quotes'"
79+
_backslash_dq="\\ \""
80+
_unicode=$'[\u03bc]'
81+
82+
# Save the variables
83+
varfile=$TMP/vars-$(basename $SH).txt
84+
85+
set | grep '^_' > "$varfile"
86+
87+
# Unset variables
88+
unset _space _whitespace _sq _backslash_dq _unicode
89+
echo [ $_space $_whitespace $_sq $_backslash_dq $_unicode ]
90+
91+
# Restore them
92+
93+
. $varfile
94+
echo "Code saved to $varfile" 1>&2 # for debugging
95+
96+
test "$_space" = '[ ]' && echo OK
97+
test "$_whitespace" = $'[\t\r\n]' && echo OK
98+
test "$_sq" = "'single quotes'" && echo OK
99+
test "$_backslash_dq" = "\\ \"" && echo OK
100+
test "$_unicode" = $'[\u03bc]' && echo OK
101+
102+
## STDOUT:
103+
[ ]
104+
OK
105+
OK
106+
OK
107+
OK
108+
OK
109+
## END
110+
111+
## BUG zsh status: 1
112+
## BUG zsh STDOUT:
113+
[ ]
114+
## END
115+
#
66116
#### set - -
67117
set a b
68118
echo "$@"
@@ -117,52 +167,46 @@ a b
117167
--
118168
## END
119169

120-
#### set -o lists options
121-
# NOTE: osh doesn't use the same format yet.
122-
set -o | grep -o noexec
123-
## STDOUT:
124-
noexec
125-
## END
126-
127-
#### 'set' and 'eval' round trip
128-
129-
# NOTE: not testing arrays and associative arrays!
130-
_space='[ ]'
131-
_whitespace=$'[\t\r\n]'
132-
_sq="'single quotes'"
133-
_backslash_dq="\\ \""
134-
_unicode=$'[\u03bc]'
170+
#### set - leading single dash is ignored, turns off xtrace verbose (#2364)
135171

136-
# Save the variables
137-
varfile=$TMP/vars-$(basename $SH).txt
172+
show_options() {
173+
case $- in
174+
*v*) echo verbose-on ;;
175+
esac
176+
case $- in
177+
*x*) echo xtrace-on ;;
178+
esac
179+
}
138180

139-
set | grep '^_' > "$varfile"
181+
set -x -v
182+
show_options
183+
echo
140184

141-
# Unset variables
142-
unset _space _whitespace _sq _backslash_dq _unicode
143-
echo [ $_space $_whitespace $_sq $_backslash_dq $_unicode ]
185+
set - a b c
186+
echo "$@"
187+
show_options
188+
echo
144189

145-
# Restore them
190+
# dash that's not leading is not special
191+
set x - y z
192+
echo "$@"
146193

147-
. $varfile
148-
echo "Code saved to $varfile" 1>&2 # for debugging
194+
## STDOUT:
195+
verbose-on
196+
xtrace-on
149197

150-
test "$_space" = '[ ]' && echo OK
151-
test "$_whitespace" = $'[\t\r\n]' && echo OK
152-
test "$_sq" = "'single quotes'" && echo OK
153-
test "$_backslash_dq" = "\\ \"" && echo OK
154-
test "$_unicode" = $'[\u03bc]' && echo OK
198+
a b c
155199

156-
## STDOUT:
157-
[ ]
158-
OK
159-
OK
160-
OK
161-
OK
162-
OK
200+
x - y z
163201
## END
164202

165-
## BUG zsh status: 1
166203
## BUG zsh STDOUT:
167-
[ ]
204+
verbose-on
205+
xtrace-on
206+
207+
a b c
208+
verbose-on
209+
xtrace-on
210+
211+
x - y z
168212
## END

0 commit comments

Comments
 (0)