OILS / spec / ysh-control-flow.test.sh View on Github | oilshell.org

182 lines, 106 significant
1
2
3#### cd builtin: fatal error in block
4shopt -s ysh:all
5cd / {
6 echo one
7 false
8 echo two
9}
10## status: 1
11## STDOUT:
12one
13## END
14
15
16#### cd builtin: return in block
17shopt -s ysh:all
18f() {
19 cd / {
20 echo one
21 return
22 echo two
23 }
24 # not reached, because we're turning out of f
25 echo 'end func'
26}
27f
28## STDOUT:
29one
30## END
31
32#### cd builtin: break in block
33shopt -s ysh:all
34f() {
35 cd / {
36 echo one
37 for i in 1 2; do
38 echo $i
39 break # break out of loop
40 done
41
42 break # break out of block isn't valid
43 echo two
44 }
45 echo end func
46}
47f
48## status: 1
49## STDOUT:
50one
511
52## END
53
54#### proc eval block: fatal error
55shopt -s ysh:all
56
57proc proc-that-runs-block (; ; ; b) {
58 call io->eval(b)
59}
60proc-that-runs-block {
61 echo one
62 false
63 echo two
64}
65## status: 1
66## STDOUT:
67one
68## END
69
70#### proc eval block: return
71shopt -s ysh:all
72
73proc proc-that-runs-block (; ; ; b) {
74 call io->eval(b)
75}
76
77f() {
78 proc-that-runs-block {
79 echo one
80 return
81 echo two
82 }
83 # this is reached because we're returning of proc-that-runs-block
84 echo 'end func'
85}
86f
87## STDOUT:
88one
89end func
90## END
91
92#### proc eval block: break in block
93shopt -s ysh:all
94
95proc proc-that-runs-block (; ; ; b) {
96 call io->eval(b)
97}
98
99f() {
100 proc-that-runs-block {
101 echo one
102 for i in 1 2; do
103 echo $i
104 break # break out of loop
105 done
106
107 break # break out of block isn't valid
108 echo two
109 }
110 echo end func
111}
112f
113## status: 1
114## STDOUT:
115one
1161
117## END
118
119#### proc eval string: fatal error
120shopt -s ysh:all
121
122proc proc-that-evals (s) {
123 eval $s
124}
125proc-that-evals '
126 echo one
127 false
128 echo two
129'
130## status: 1
131## STDOUT:
132one
133## END
134
135#### proc eval string: return
136shopt -s ysh:all
137
138proc proc-that-evals (s) {
139 eval $s
140}
141
142f() {
143 proc-that-evals '
144 echo one
145 return
146 echo two
147 '
148 # this is reached because we're returning of proc-that-evals
149 echo 'end func'
150}
151f
152## STDOUT:
153one
154end func
155## END
156
157#### proc eval string: break
158shopt -s ysh:all
159
160proc proc-that-evals (s) {
161 eval $s
162}
163
164f() {
165 proc-that-evals '
166 echo one
167 for i in 1 2; do
168 echo $i
169 break # break out of loop
170 done
171
172 break # break out of string is not valid
173 echo two
174 '
175 echo end func
176}
177f
178## status: 1
179## STDOUT:
180one
1811
182## END