1 ## our_shell: ysh
2 ## oils_failures_allowed: 3
3
4 #### fastlex: NUL byte not allowed inside char literal #' '
5
6 echo $'var x = #\'\x00\'; echo x=$x' > tmp.oil
7 $SH tmp.oil
8
9 echo $'var x = #\' ' > incomplete.oil
10 $SH incomplete.oil
11
12 ## status: 2
13 ## STDOUT:
14 ## END
15
16 #### fastlex: NUL byte inside shebang line
17
18 # Hm this test doesn't really tickle the bug
19
20 echo $'#! /usr/bin/env \x00 sh \necho hi' > tmp.oil
21 env OILS_HIJACK_SHEBANG=1 $SH tmp.oil
22
23 ## STDOUT:
24 hi
25 ## END
26
27 #### Tea keywords don't interfere with YSH expressions
28
29 var d = {data: 'foo'}
30
31 echo $[d.data]
32
33 var e = {enum: 1, class: 2, import: 3, const: 4, var: 5, set: 6}
34 echo $[len(e)]
35
36 ## STDOUT:
37 foo
38 6
39 ## END
40
41 #### Catch AttributeError
42
43 var s = 'foo'
44 echo s=$s
45 var t = s.bad()
46 echo 'should not get here'
47
48 ## status: 3
49 ## STDOUT:
50 s=foo
51 ## END
52
53
54 #### Command sub paren parsing bug (#1387)
55
56 write $(if (true) { write true })
57
58 const a = $(write $[len('foo')])
59 echo $a
60
61 const b = $(write $[5 ** 3])
62 echo $b
63
64 const c = $(
65 write $[6 + 7]
66 )
67 echo $c
68
69 ## STDOUT:
70 true
71 3
72 125
73 13
74 ## END
75
76
77 #### More Command sub paren parsing
78
79 write $( var mylist = ['for']; for x in (mylist) { echo $x } )
80
81 write $( echo while; while (false) { write hi } )
82
83 write $( if (true) { write 'if' } )
84
85 write $( if (false) { write 'if' } elif (true) { write 'elif' } )
86
87 ## STDOUT:
88 for
89 while
90 if
91 elif
92 ## END
93
94 #### don't execute empty command
95
96 shopt --set ysh:all
97
98 set -x
99
100 try {
101 type -a ''
102 }
103 echo "type -a returned $_status"
104
105 $(true)
106 echo nope
107
108 ## status: 127
109 ## STDOUT:
110 type -a returned 1
111 ## END
112
113
114 #### Do && || with YSH constructs make sense/
115
116 # I guess there's nothing wrong with this?
117 #
118 # But I generally feel && || are only for
119 #
120 # test --file x && test --file y
121
122 var x = []
123 true && call x->append(42)
124 false && call x->append(43)
125 pp test_ (x)
126
127 func amp() {
128 true && return (42)
129 }
130
131 func pipe() {
132 false || return (42)
133 }
134
135 pp test_ (amp())
136 pp test_ (pipe())
137
138 ## STDOUT:
139 ## END
140
141
142 #### shvar then replace - bug #1986 context manager crash
143
144 shvar FOO=bar {
145 for x in (1 .. 500) {
146 var Q = "hello"
147 setvar Q = Q=>replace("hello","world")
148 }
149 }
150 echo $Q
151
152 ## STDOUT:
153 world
154 ## END
155
156
157 #### Parsing crash - bug #2003
158
159 set +o errexit
160
161 $SH -c 'proc y (;x) { return = x }'
162 echo status=$?
163
164 $SH -c 'func y (;x) { return = x }'
165 echo status=$?
166
167 ## STDOUT:
168 status=2
169 status=2
170 ## END
171
172
173 #### proc with IFS= read -r line - dynamic scope - issue #2012
174
175 # this is an issue with lack of dynamic scope
176 # not sure exactly how to handle it ...
177
178 # shvar IFS= { read } is our replacement for dynamic scope
179
180 proc p {
181 read -r line
182 write $line
183 }
184
185 proc p-ifs {
186 IFS= read -r line
187 write $line
188 }
189
190 #set -x
191
192 echo zz | p
193
194 echo yy | p-ifs
195
196 ## STDOUT:
197 zz
198 yy
199 ## END
200
201 #### func call inside proc call - error message attribution
202
203 try 2> foo {
204 $SH -c '
205 func ident(x) {
206 return (x)
207 }
208
209 proc p (; x) {
210 echo $x
211 }
212
213 # BUG: it points to ( in ident(
214 # should point to ( in eval (
215
216 eval (ident([1,2,3]))
217 '
218 }
219
220 cat foo
221
222 ## STDOUT:
223 ## END
224
225
226 #### Crash in parsing case on EOF condition - issue #2037
227
228 var WEIGHT = ${1:-}
229 case (WEIGHT) {
230 "-" { echo "got nothing" }
231 (else) { echo $WEIGHT
232 }
233
234 ## status: 2
235 ## STDOUT:
236 ## END
237
238 #### Crash due to incorrect of context manager rooting - issue #1986
239
240 proc p {
241 var s = "hi"
242 for q in (1..50) {
243 shvar Q="whatever" {
244 setvar s = "." ++ s
245 }
246 }
247 }
248
249 for i in (1..10) {
250 p
251 }
252
253 if false {
254 echo 'testing for longer'
255 for i in (1 .. 1000) {
256 p
257 }
258 }
259
260 ## STDOUT:
261 ## END
262
263
264 #### crash due to arbitrary PNode limit - issue #2078
265
266 #!/usr/bin/env ysh
267 var DelegatedCompName = {
268 "llvm" : "x_project",
269 "rocprofiler_register" : "x_rocprofiler_register",
270 "roct_thunk_interface" : "x_roct",
271 "rocr_runtime" : "x_rocr",
272 "openmp" : "x_openmp",
273 "offload" : "x_offload",
274 "aomp_extras" : "x_extras",
275 "comgr" : "x_comgr",
276 "rocminfo" : "x_rocminfo",
277 "rocsmilib" : "x_rocm_smi_lib",
278 "amdsmi" : "x_amdsmi",
279 "flang_legacy" : "x_flang_legacy",
280 "pgmath" : "x_pgmath",
281 "flang" : "x_flang",
282 "flang_runtime" : "x_flang_runtime",
283 "hipcc" : "x_hipcc",
284 "hipamd" : "x_hipamd",
285 "rocm_dbgapi" : "x_rocdbgapi",
286 "rocgdb" : "x_rocgdb",
287 "roctracer" : "x_roctracer",
288 "rocprofiler" : "x_rocprofiler"
289 }
290
291 echo $[len(DelegatedCompName)]
292
293 ## STDOUT:
294 21
295 ## END