OILS / spec / bool-parse.test.sh View on Github | oils.pub

176 lines, 67 significant
1## oils_failures_allowed: 1
2## compare_shells: bash dash mksh zsh ash
3
4# spec/bool-parse.test.sh
5#
6# [ and [[ share the BoolParser
7#
8# These test cases are for some bugs fixed
9#
10# See also
11# spec/builtin-bracket.test.sh for [
12# spec/dbracket.test.sh for [[
13
14#### test builtin - Unexpected trailing word '--' (#2409)
15
16# Minimal repro of sqsh build error
17set -- -o; test $# -ne 0 -a "$1" != "--"
18echo status=$?
19
20# Now hardcode $1
21test $# -ne 0 -a "-o" != "--"
22echo status=$?
23
24# Remove quotes around -o
25test $# -ne 0 -a -o != "--"
26echo status=$?
27
28# How about a different flag?
29set -- -z; test $# -ne 0 -a "$1" != "--"
30echo status=$?
31
32# A non-flag?
33set -- z; test $# -ne 0 -a "$1" != "--"
34echo status=$?
35
36## STDOUT:
37status=0
38status=0
39status=0
40status=0
41status=0
42## END
43
44#### test builtin: ( = ) is confusing: equality test or non-empty string test
45
46# here it's equality
47test '(' = ')'
48echo status=$?
49
50# here it's like -n =
51test 0 -eq 0 -a '(' = ')'
52echo status=$?
53
54## STDOUT:
55status=1
56status=0
57## END
58
59## BUG zsh STDOUT:
60status=0
61status=1
62## END
63
64#### test builtin: ( == ) is confusing: equality test or non-empty string test
65
66# here it's equality
67test '(' == ')'
68echo status=$?
69
70# here it's like -n ==
71test 0 -eq 0 -a '(' == ')'
72echo status=$?
73
74## STDOUT:
75status=1
76status=0
77## END
78
79## BUG dash STDOUT:
80status=0
81status=0
82## END
83
84## BUG-2 zsh status: 1
85## BUG-2 zsh STDOUT:
86## END
87
88#### Allowed: [[ = ]] and [[ == ]]
89
90[[ = ]]
91echo status=$?
92[[ == ]]
93echo status=$?
94
95## STDOUT:
96status=0
97status=0
98## END
99
100## N-I dash STDOUT:
101status=127
102status=127
103## END
104
105## BUG zsh status: 1
106## BUG zsh STDOUT:
107status=0
108## END
109
110#### Not allowed: [[ ) ]] and [[ ( ]]
111
112[[ ) ]]
113echo status=$?
114[[ ( ]]
115echo status=$?
116
117## status: 2
118## OK mksh status: 1
119## STDOUT:
120## END
121## OK zsh status: 1
122## OK zsh STDOUT:
123status=1
124## END
125
126#### test builtin: ( x ) behavior is the same in both cases
127
128test '(' x ')'
129echo status=$?
130
131test 0 -eq 0 -a '(' x ')'
132echo status=$?
133
134## STDOUT:
135status=0
136status=0
137## END
138
139#### [ -f = ] and [ -f == ]
140
141[ -f = ]
142echo status=$?
143[ -f == ]
144echo status=$?
145
146## STDOUT:
147status=1
148status=1
149## END
150
151## BUG zsh status: 1
152## BUG zsh STDOUT:
153status=1
154## END
155
156#### [[ -f -f ]] and [[ -f == ]]
157[[ -f -f ]]
158echo status=$?
159
160[[ -f == ]]
161echo status=$?
162
163## STDOUT:
164status=1
165status=1
166## END
167
168## N-I dash STDOUT:
169status=127
170status=127
171## END
172
173## BUG zsh status: 1
174## BUG zsh STDOUT:
175status=1
176## END