1 | ## oils_failures_allowed: 7
|
2 |
|
3 | #### source-guard is an old way of preventing redefinition - could remove it
|
4 | shopt --set ysh:upgrade
|
5 |
|
6 | source-guard 'main' || return 0
|
7 | source $REPO_ROOT/spec/testdata/module/common.ysh
|
8 | source $REPO_ROOT/spec/testdata/module/module1.ysh
|
9 | ## STDOUT:
|
10 | common
|
11 | module1
|
12 | ## END
|
13 |
|
14 | #### is-main
|
15 |
|
16 | # This sources lib.ysh
|
17 | $SH $REPO_ROOT/spec/testdata/module/main.ysh
|
18 |
|
19 | # Run it directly
|
20 | $SH $REPO_ROOT/spec/testdata/module/lib.ysh
|
21 |
|
22 | ## STDOUT:
|
23 | lib.ysh is not the main module
|
24 | hi from main.ysh
|
25 | hi from lib.ysh
|
26 | ## END
|
27 |
|
28 | #### is-main with -c and stdin
|
29 |
|
30 | $SH -c 'echo -c; is-main; echo status=$?'
|
31 |
|
32 | echo 'echo stdin; is-main; echo status=$?' | $SH
|
33 |
|
34 | ## STDOUT:
|
35 | -c
|
36 | status=0
|
37 | stdin
|
38 | status=0
|
39 | ## END
|
40 |
|
41 | #### use builtin usage
|
42 |
|
43 | use
|
44 | echo no-arg=$?
|
45 |
|
46 | use foo
|
47 | echo one-arg=$?
|
48 |
|
49 | use --extern foo
|
50 | echo extern=$?
|
51 |
|
52 | use --bad-flag
|
53 | echo bad-flag=$?
|
54 |
|
55 | use too many
|
56 | echo too-many=$?
|
57 |
|
58 | use ///no-builtin
|
59 | echo no-builtin=$?
|
60 |
|
61 |
|
62 | ## STDOUT:
|
63 | no-arg=2
|
64 | one-arg=1
|
65 | extern=0
|
66 | bad-flag=2
|
67 | too-many=2
|
68 | no-builtin=1
|
69 | ## END
|
70 |
|
71 |
|
72 | #### use --extern is a no-op, for static analysis
|
73 |
|
74 | use --extern grep sed awk
|
75 | echo status=$?
|
76 |
|
77 | use --extern zzz
|
78 | echo status=$?
|
79 |
|
80 | ## STDOUT:
|
81 | status=0
|
82 | status=0
|
83 | ## END
|
84 |
|
85 | #### use foo.ysh creates a value.Obj, and it's cached on later invocations
|
86 |
|
87 | shopt --set ysh:upgrade
|
88 |
|
89 | var caller_no_leak = 42
|
90 |
|
91 | use $REPO_ROOT/spec/testdata/module2/util.ysh
|
92 |
|
93 | # This is a value.Obj
|
94 | pp test_ (['util', util])
|
95 | var id1 = id(util)
|
96 |
|
97 | var saved_util = util
|
98 |
|
99 | use $REPO_ROOT/spec/testdata/module2/util.ysh
|
100 | pp test_ (['repeated', util])
|
101 | var id2 = id(util)
|
102 |
|
103 | # Create a symlink to test normalization
|
104 |
|
105 | ln -s $REPO_ROOT/spec/testdata/module2/util.ysh symlink.ysh
|
106 |
|
107 | use symlink.ysh
|
108 | pp test_ (['symlink', symlink])
|
109 | var id3 = id(symlink)
|
110 |
|
111 | #pp test_ ([id1, id2, id3])
|
112 |
|
113 | # Make sure they are all the same object
|
114 | assert [id1 === id2]
|
115 | assert [id2 === id3]
|
116 |
|
117 | # Doesn't leak from util.ysh
|
118 | echo "setvar_noleak $[getVar('setvar_noleak')]"
|
119 | echo "setglobal_noleak $[getVar('setglobal_noleak')]"
|
120 |
|
121 | ## STDOUT:
|
122 | caller_no_leak = null
|
123 | (List) ["util",{"MY_INTEGER":42,"log":<Proc>,"die":<Proc>,"setvar_noleak":"util.ysh","setglobal_noleak":"util.ysh","invokableObj":{"x":3,"y":4} ==> {"__invoke__":<Proc>}} ==> {"__invoke__":<BuiltinProc>}]
|
124 | (List) ["repeated",{"MY_INTEGER":42,"log":<Proc>,"die":<Proc>,"setvar_noleak":"util.ysh","setglobal_noleak":"util.ysh","invokableObj":{"x":3,"y":4} ==> {"__invoke__":<Proc>}} ==> {"__invoke__":<BuiltinProc>}]
|
125 | (List) ["symlink",{"MY_INTEGER":42,"log":<Proc>,"die":<Proc>,"setvar_noleak":"util.ysh","setglobal_noleak":"util.ysh","invokableObj":{"x":3,"y":4} ==> {"__invoke__":<Proc>}} ==> {"__invoke__":<BuiltinProc>}]
|
126 | setvar_noleak null
|
127 | setglobal_noleak null
|
128 | ## END
|
129 |
|
130 | #### procs in a module can call setglobal on globals in that module
|
131 | shopt --set ysh:upgrade
|
132 |
|
133 | use $REPO_ROOT/spec/testdata/module2/globals.ysh
|
134 |
|
135 | # get() should work on Obj too. Possibly we should get rid of the default
|
136 | var myproc = get(propView(globals), 'mutate-g1', null)
|
137 | call setVar('mutate-g1', myproc)
|
138 |
|
139 | # you can mutate it internally, but the mutation isn't VISIBLE. GAH!
|
140 | # I wonder if you make Cell a value? or something
|
141 | mutate-g1
|
142 | echo
|
143 |
|
144 | # PROBLEM: This is a value.Obj COPY, not the fucking original!!!
|
145 | # immutable objects??
|
146 |
|
147 | #pp test_ ([id(globals.d), globals.d])
|
148 |
|
149 | call globals.mutateG2()
|
150 | echo
|
151 |
|
152 | #= propView(globals)
|
153 |
|
154 | # these are not provided
|
155 | echo "globals.g1 = $[get(globals, 'g1', null)]"
|
156 | echo "globals.g2 = $[get(globals, 'g2', null)]"
|
157 | echo
|
158 |
|
159 | #pp frame_vars_
|
160 | # Shouldn't appear here
|
161 | echo "importer g1 = $[getVar('g1')]"
|
162 | echo "importer g2 = $[getVar('g2')]"
|
163 |
|
164 | ## STDOUT:
|
165 | g1 = g1
|
166 | g1 = proc mutated
|
167 |
|
168 | g2 = g2
|
169 | g2 = func mutated
|
170 |
|
171 | globals.g1 = null
|
172 | globals.g2 = null
|
173 |
|
174 | importer g1 = null
|
175 | importer g2 = null
|
176 | ## END
|
177 |
|
178 | #### no provided names
|
179 | shopt --set ysh:upgrade
|
180 |
|
181 | use $REPO_ROOT/spec/testdata/module2/no-provide.ysh
|
182 |
|
183 | ## status: 1
|
184 | ## STDOUT:
|
185 | ## END
|
186 |
|
187 | #### bad provide type
|
188 | shopt --set ysh:upgrade
|
189 |
|
190 | use $REPO_ROOT/spec/testdata/module2/bad-provide-type.ysh
|
191 |
|
192 | ## status: 1
|
193 | ## STDOUT:
|
194 | ## END
|
195 |
|
196 | #### invalid provide entries
|
197 | shopt --set ysh:upgrade
|
198 |
|
199 | use $REPO_ROOT/spec/testdata/module2/bad-provide.ysh
|
200 |
|
201 | ## status: 1
|
202 | ## STDOUT:
|
203 | ## END
|
204 |
|
205 | #### use foo.ysh creates a value.Obj with __invoke__
|
206 | shopt --set ysh:upgrade
|
207 |
|
208 | use $REPO_ROOT/spec/testdata/module2/util.ysh
|
209 |
|
210 | # This is a value.Obj
|
211 | #pp test_ (util)
|
212 |
|
213 | util log 'hello'
|
214 | util die 'hello there'
|
215 |
|
216 | ## STDOUT:
|
217 | caller_no_leak = null
|
218 | log hello
|
219 | die hello there
|
220 | ## END
|
221 |
|
222 | #### module itself is invokable Obj, which can contain invokable obj!
|
223 | shopt --set ysh:upgrade
|
224 |
|
225 | use $REPO_ROOT/spec/testdata/module2/util.ysh
|
226 |
|
227 | util invokableObj (1)
|
228 |
|
229 | # Usage error
|
230 | #util invokableObj
|
231 |
|
232 | ## STDOUT:
|
233 | caller_no_leak = null
|
234 | sum = 8
|
235 | ## END
|
236 |
|
237 | #### argument binding test
|
238 | shopt --set ysh:upgrade
|
239 |
|
240 | use $REPO_ROOT/spec/testdata/module2/util2.ysh
|
241 |
|
242 | util2 echo-args w1 w2 w3 w4 (3, 4, 5, 6, n1=7, n2=8, n3=9) {
|
243 | echo hi
|
244 | }
|
245 |
|
246 | echo ---
|
247 |
|
248 | util2 echo-args w1 w2 (3, 4, n3=9) {
|
249 | echo hi
|
250 | }
|
251 |
|
252 | ## STDOUT:
|
253 | (List) ["w1","w2"]
|
254 | (List) ["w3","w4"]
|
255 |
|
256 | (List) [3,4]
|
257 | (List) [5,6]
|
258 |
|
259 | (List) [7,8]
|
260 | (Dict) {"n3":9}
|
261 |
|
262 | <Block>
|
263 | ---
|
264 | (List) ["w1","w2"]
|
265 | (List) []
|
266 |
|
267 | (List) [3,4]
|
268 | (List) []
|
269 |
|
270 | (List) [42,43]
|
271 | (Dict) {"n3":9}
|
272 |
|
273 | <Block>
|
274 | ## END
|
275 |
|
276 | #### module invoked without any arguments is an error
|
277 | shopt --set ysh:upgrade
|
278 |
|
279 | use $REPO_ROOT/spec/testdata/module2/util.ysh
|
280 |
|
281 | util
|
282 |
|
283 | ## status: 2
|
284 | ## STDOUT:
|
285 | caller_no_leak = null
|
286 | ## END
|
287 |
|
288 | #### module invoked with nonexistent name is error
|
289 | shopt --set ysh:upgrade
|
290 |
|
291 | use $REPO_ROOT/spec/testdata/module2/util.ysh
|
292 |
|
293 | util zzz
|
294 |
|
295 | ## status: 2
|
296 | ## STDOUT:
|
297 | caller_no_leak = null
|
298 | ## END
|
299 |
|
300 | #### circular import is an error?
|
301 |
|
302 | echo hi
|
303 |
|
304 | ## STDOUT:
|
305 | ## END
|
306 |
|
307 | #### Module with runtime error
|
308 |
|
309 | echo TODO
|
310 |
|
311 | ## STDOUT:
|
312 | ## END
|
313 |
|
314 | #### Module with parse error
|
315 |
|
316 | echo TODO
|
317 |
|
318 | ## STDOUT:
|
319 | ## END
|
320 |
|
321 | #### user can inspect __modules__ cache
|
322 |
|
323 | echo 'TODO: Dict view of realpath() string -> Obj instance'
|
324 |
|
325 | ## STDOUT:
|
326 | ## END
|
327 |
|
328 | #### use foo.ysh --names a b
|
329 |
|
330 | echo TODO
|
331 |
|
332 | ## STDOUT:
|
333 | ## END
|
334 |
|
335 |
|
336 | #### use foo.ysh --all-provided
|
337 |
|
338 | echo TODO
|
339 |
|
340 | ## STDOUT:
|
341 | ## END
|
342 |
|
343 |
|
344 | #### use foo.ysh --all-for-testing
|
345 |
|
346 | echo TODO
|
347 |
|
348 | ## STDOUT:
|
349 | ## END
|