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

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