OILS / spec / ysh-builtin-shopt.test.sh View on Github | oilshell.org

180 lines, 96 significant
1## oils_failures_allowed: 1
2
3#### shopt supports long flags
4shopt -p nullglob
5
6shopt --set nullglob
7shopt -p nullglob
8
9shopt --unset nullglob
10shopt -p nullglob
11## STDOUT:
12shopt -u nullglob
13shopt -s nullglob
14shopt -u nullglob
15## END
16
17#### shopt supports 'set' options
18shopt -p errexit
19
20shopt --set errexit
21false
22
23echo should not get here
24## status: 1
25## STDOUT:
26shopt -u errexit
27## END
28
29
30#### shopt --unset errexit { }
31shopt --set oil:all
32
33echo one
34
35shopt --unset errexit {
36 echo two
37 false
38 echo three
39}
40
41false
42echo 'should not get here'
43
44## status: 1
45## STDOUT:
46one
47two
48three
49## END
50
51#### shopt -p works correctly inside block
52shopt --set parse_brace
53
54shopt -p | grep inherit_errexit
55shopt --set inherit_errexit {
56 shopt -p | grep inherit_errexit
57}
58
59## STDOUT:
60shopt -u inherit_errexit
61shopt -s inherit_errexit
62## END
63
64
65#### shopt --set GROUP { }
66shopt --set parse_brace
67
68shopt -p | grep errexit
69echo ---
70
71shopt --set oil:all {
72 #false
73 #echo status=$?
74 shopt -p | grep errexit
75}
76echo ---
77
78shopt --set oil:upgrade {
79 shopt -p | grep errexit
80}
81echo ---
82
83shopt --set strict:all {
84 shopt -p | grep errexit
85}
86
87# TODO: shopt --table should show the error value
88
89## STDOUT:
90shopt -u command_sub_errexit
91shopt -u inherit_errexit
92shopt -u strict_errexit
93shopt -u verbose_errexit
94---
95shopt -s command_sub_errexit
96shopt -s inherit_errexit
97shopt -s strict_errexit
98shopt -s verbose_errexit
99---
100shopt -s command_sub_errexit
101shopt -s inherit_errexit
102shopt -u strict_errexit
103shopt -s verbose_errexit
104---
105shopt -u command_sub_errexit
106shopt -u inherit_errexit
107shopt -s strict_errexit
108shopt -u verbose_errexit
109## END
110
111#### shopt and block status
112shopt --set oil:all
113
114shopt --unset errexit {
115 false
116}
117# this is still 0, even though last command was 1
118echo status=$?
119
120## STDOUT:
121status=0
122## END
123
124#### shopt usage error
125shopt --set oil:all
126
127echo one
128shopt --set a {
129 echo two
130}
131echo status=$?
132## status: 2
133## STDOUT:
134one
135## END
136
137#### shopt -p
138
139shopt -p errexit
140shopt -p nullglob
141
142echo --
143shopt -p strict:all | head -n 3
144
145echo --
146shopt --set strict:all
147shopt -p strict:all | head -n 3
148
149## STDOUT:
150shopt -u errexit
151shopt -u nullglob
152--
153shopt -u strict_argv
154shopt -u strict_arith
155shopt -u strict_array
156--
157shopt -s strict_argv
158shopt -s strict_arith
159shopt -s strict_array
160## END
161
162#### TODO: all options as a table
163
164shopt --table
165
166# This is unlike shopt -p because
167
168# 1) It shows ALL options, not just 'shopt' options
169# 2) It shows it in QTT format?
170
171# opt_name Str value Bool
172# errexit true
173# nounset false
174#
175# Could also be T and F? JSON is more obvious
176
177
178## STDOUT:
179## END
180