1 ## oils_failures_allowed: 1
2
3 #### runproc
4 shopt --set parse_proc parse_at
5
6 f() {
7 write -- f "$@"
8 }
9 proc p {
10 write -- p @ARGV
11 }
12 runproc f 1 2
13 echo status=$?
14
15 runproc p 3 4
16 echo status=$?
17
18 runproc invalid 5 6
19 echo status=$?
20
21 runproc
22 echo status=$?
23
24 ## STDOUT:
25 f
26 1
27 2
28 status=0
29 p
30 3
31 4
32 status=0
33 status=1
34 status=2
35 ## END
36
37
38 #### runproc typed args
39 shopt --set parse_brace parse_proc
40
41 proc p {
42 echo 'hi from p'
43 }
44
45 # The block is ignored for now
46 runproc p {
47 echo myblock
48 }
49 echo
50
51 proc ty (w; t; n; block) {
52 echo 'ty'
53 pp line (w)
54 pp line (t)
55 pp line (n)
56 echo $[type(block)]
57 }
58
59 ty a (42; n=99; ^(echo ty))
60 echo
61
62 runproc ty a (42; n=99; ^(echo ty))
63 echo
64
65 runproc ty a (42; n=99) {
66 echo 'ty gets literal'
67 }
68
69 # TODO: Command vs. Block vs. Literal Block should be unified
70
71 ## STDOUT:
72 hi from p
73
74 ty
75 (Str) "a"
76 (Int) 42
77 (Int) 99
78 Command
79
80 ty
81 (Str) "a"
82 (Int) 42
83 (Int) 99
84 Command
85
86 ty
87 (Str) "a"
88 (Int) 42
89 (Int) 99
90 Block
91 ## END
92
93
94 #### pp asdl
95
96 shopt -s ysh:upgrade
97
98 fopen >out.txt {
99 x=42
100 setvar y = {foo: x}
101
102 pp asdl (x)
103 pp asdl (y)
104
105 # TODO, this might be nice?
106 # pp asdl (x, y)
107 }
108
109 # Two lines with value.Str
110 grep -n -o value.Str out.txt
111
112 # Dict should have an address
113 #grep -n -o 'Dict 0x' out.txt
114
115 #cat out.txt
116
117 ## STDOUT:
118 1:value.Str
119 2:value.Str
120 ## END
121
122 #### pp asdl can handle an object cycle
123
124 shopt -s ysh:upgrade
125
126 var d = {}
127 setvar d.cycle = d
128
129 pp line (d) | fgrep -o '{"cycle":'
130
131 pp asdl (d) | fgrep -o 'cycle ...'
132
133 ## STDOUT:
134 {"cycle":
135 cycle ...
136 ## END
137
138 #### pp line supports BashArray, BashAssoc
139
140 declare -a array=(a b c)
141 pp line (array)
142
143 array[5]=z
144 pp line (array)
145
146 declare -A assoc=([k]=v [k2]=v2)
147 pp line (assoc)
148
149 # I think assoc arrays can never null / unset
150
151 assoc['k3']=
152 pp line (assoc)
153
154 ## STDOUT:
155 {"type":"BashArray","value":{"0":"a","1":"b","2":"c"}}
156 {"type":"BashArray","value":{"0":"a","1":"b","2":"c","5":"z"}}
157 (BashAssoc) {"k":"v","k2":"v2"}
158 (BashAssoc) {"k":"v","k2":"v2","k3":""}
159 ## END
160
161
162 #### pp gc-stats
163
164 pp gc-stats
165
166 ## STDOUT:
167 ## END
168
169
170 #### pp cell
171 x=42
172
173 pp cell x
174 echo status=$?
175
176 pp -- cell :x
177 echo status=$?
178
179 pp cell nonexistent
180 echo status=$?
181 ## STDOUT:
182 x = (Cell exported:F readonly:F nameref:F val:(value.Str s:42))
183 status=0
184 x = (Cell exported:F readonly:F nameref:F val:(value.Str s:42))
185 status=0
186 status=1
187 ## END
188
189 #### pp cell on indexed array with hole
190 declare -a array
191 array[3]=42
192 pp cell array
193 ## STDOUT:
194 array = (Cell exported:F readonly:F nameref:F val:(value.BashArray strs:[_ _ _ 42]))
195 ## END
196
197
198 #### pp proc
199 shopt --set ysh:upgrade
200
201 # This has to be a separate file because sh_spec.py strips comments!
202 . $REPO_ROOT/spec/testdata/doc-comments.sh
203
204 pp proc
205 echo ---
206
207 # print one
208 pp proc f
209
210 ## STDOUT:
211 proc_name doc_comment
212 f "doc ' comment with \" quotes"
213 g ""
214 myproc "YSH-style proc"
215 "true" "Special quoting rule"
216 ---
217 proc_name doc_comment
218 f "doc ' comment with \" quotes"
219 ## END
220
221
222 #### pp (x) is like = keyword
223
224 shopt --set ysh:upgrade
225 source $LIB_YSH/list.ysh
226
227 # It can be piped!
228
229 pp ('foo') | cat
230
231 pp ("isn't this sq") | cat
232
233 pp ('"dq $myvar"') | cat
234
235 pp (r'\ backslash \\') | cat
236
237 pp (u'one \t two \n') | cat
238
239 # Without a terminal, default width is 80
240 pp (repeat([123], 40)) | cat
241
242 ## STDOUT:
243 (Str) 'foo'
244 (Str) b'isn\'t this sq'
245 (Str) '"dq $myvar"'
246 (Str) b'\\ backslash \\\\'
247 (Str) b'one \t two \n'
248 (List)
249 [
250 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, 123,
251 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, 123,
252 123, 123, 123, 123, 123, 123, 123, 123, 123, 123
253 ]
254 ## END