comparison src/testdir/test_channel.vim @ 9517:9f8f03a44886 v7.4.2039

commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe Author: Bram Moolenaar <Bram@vim.org> Date: Fri Jul 15 17:09:11 2016 +0200 patch 7.4.2039 Problem: The Netbeans integration is not tested. Solution: Add a first Netbeans test.
author Christian Brabandt <cb@256bit.org>
date Fri, 15 Jul 2016 17:15:05 +0200
parents 2465b6cda394
children e8b3db8e2d30
comparison
equal deleted inserted replaced
9516:a0898dcc7507 9517:9f8f03a44886
3 3
4 if !has('channel') 4 if !has('channel')
5 finish 5 finish
6 endif 6 endif
7 7
8 " This test requires the Python command to run the test server. 8 source shared.vim
9 " This most likely only works on Unix and Windows. 9
10 if has('unix') 10 let s:python = PythonProg()
11 " We also need the job feature or the pkill command to make sure the server 11 if s:python == ''
12 " can be stopped.
13 if !(executable('python') && (has('job') || executable('pkill')))
14 finish
15 endif
16 let s:python = 'python'
17 elseif has('win32')
18 " Use Python Launcher for Windows (py.exe) if available.
19 if executable('py.exe')
20 let s:python = 'py.exe'
21 elseif executable('python.exe')
22 let s:python = 'python.exe'
23 else
24 finish
25 endif
26 else
27 " Can't run this test. 12 " Can't run this test.
28 finish 13 finish
29 endif 14 endif
30 15
31 let s:chopt = {} 16 let s:chopt = {}
32 17
33 " Run "testfunc" after sarting the server and stop the server afterwards. 18 " Run "testfunc" after sarting the server and stop the server afterwards.
34 func s:run_server(testfunc, ...) 19 func s:run_server(testfunc, ...)
35 " The Python program writes the port number in Xportnr. 20 call RunServer('test_channel.py', a:testfunc, a:000)
36 call delete("Xportnr") 21 endfunc
37 22
38 if a:0 == 1 23 let g:Ch_responseMsg = ''
39 let arg = ' ' . a:1 24 func Ch_requestHandler(handle, msg)
40 else 25 let g:Ch_responseHandle = a:handle
41 let arg = '' 26 let g:Ch_responseMsg = a:msg
42 endif 27 endfunc
43 let cmd = s:python . " test_channel.py" . arg 28
44 29 func Ch_communicate(port)
45 try
46 if has('job')
47 let s:job = job_start(cmd, {"stoponexit": "hup"})
48 call job_setoptions(s:job, {"stoponexit": "kill"})
49 elseif has('win32')
50 exe 'silent !start cmd /c start "test_channel" ' . cmd
51 else
52 exe 'silent !' . cmd . '&'
53 endif
54
55 " Wait for up to 2 seconds for the port number to be there.
56 let l = []
57 for i in range(200)
58 try
59 let l = readfile("Xportnr")
60 catch
61 endtry
62 if len(l) >= 1
63 break
64 endif
65 sleep 10m
66 endfor
67 call delete("Xportnr")
68
69 if len(l) == 0
70 " Can't make the connection, give up.
71 call assert_false(1, "Can't start test_channel.py")
72 return -1
73 endif
74 let port = l[0]
75
76 call call(function(a:testfunc), [port])
77 catch
78 call assert_false(1, "Caught exception: " . v:exception)
79 finally
80 call s:kill_server()
81 endtry
82 endfunc
83
84 func s:kill_server()
85 if has('job')
86 if exists('s:job')
87 call job_stop(s:job)
88 unlet s:job
89 endif
90 elseif has('win32')
91 call system('taskkill /IM ' . s:python . ' /T /F /FI "WINDOWTITLE eq test_channel"')
92 else
93 call system("pkill -f test_channel.py")
94 endif
95 endfunc
96
97 let s:responseMsg = ''
98 func s:RequestHandler(handle, msg)
99 let s:responseHandle = a:handle
100 let s:responseMsg = a:msg
101 endfunc
102
103 " Wait for up to a second for "expr" to become true.
104 func s:waitFor(expr)
105 for i in range(100)
106 try
107 if eval(a:expr)
108 return
109 endif
110 catch
111 endtry
112 sleep 10m
113 endfor
114 endfunc
115
116 func s:communicate(port)
117 let handle = ch_open('localhost:' . a:port, s:chopt) 30 let handle = ch_open('localhost:' . a:port, s:chopt)
118 if ch_status(handle) == "fail" 31 if ch_status(handle) == "fail"
119 call assert_false(1, "Can't open channel") 32 call assert_false(1, "Can't open channel")
120 return 33 return
121 endif 34 endif
138 call assert_equal('ok', ch_evalexpr(handle, 'malformed2')) 51 call assert_equal('ok', ch_evalexpr(handle, 'malformed2'))
139 call assert_equal('ok', ch_evalexpr(handle, 'malformed3')) 52 call assert_equal('ok', ch_evalexpr(handle, 'malformed3'))
140 53
141 " split command should work 54 " split command should work
142 call assert_equal('ok', ch_evalexpr(handle, 'split')) 55 call assert_equal('ok', ch_evalexpr(handle, 'split'))
143 call s:waitFor('exists("g:split")') 56 call WaitFor('exists("g:split")')
144 call assert_equal(123, g:split) 57 call assert_equal(123, g:split)
145 58
146 " Request that triggers sending two ex commands. These will usually be 59 " Request that triggers sending two ex commands. These will usually be
147 " handled before getting the response, but it's not guaranteed, thus wait a 60 " handled before getting the response, but it's not guaranteed, thus wait a
148 " tiny bit for the commands to get executed. 61 " tiny bit for the commands to get executed.
149 call assert_equal('ok', ch_evalexpr(handle, 'make change')) 62 call assert_equal('ok', ch_evalexpr(handle, 'make change'))
150 call s:waitFor('"added2" == getline("$")') 63 call WaitFor('"added2" == getline("$")')
151 call assert_equal('added1', getline(line('$') - 1)) 64 call assert_equal('added1', getline(line('$') - 1))
152 call assert_equal('added2', getline('$')) 65 call assert_equal('added2', getline('$'))
153 66
154 " Request command "foo bar", which fails silently. 67 " Request command "foo bar", which fails silently.
155 call assert_equal('ok', ch_evalexpr(handle, 'bad command')) 68 call assert_equal('ok', ch_evalexpr(handle, 'bad command'))
156 call s:waitFor('v:errmsg =~ "E492"') 69 call WaitFor('v:errmsg =~ "E492"')
157 call assert_match('E492:.*foo bar', v:errmsg) 70 call assert_match('E492:.*foo bar', v:errmsg)
158 71
159 call assert_equal('ok', ch_evalexpr(handle, 'do normal', {'timeout': 100})) 72 call assert_equal('ok', ch_evalexpr(handle, 'do normal', {'timeout': 100}))
160 call s:waitFor('"added more" == getline("$")') 73 call WaitFor('"added more" == getline("$")')
161 call assert_equal('added more', getline('$')) 74 call assert_equal('added more', getline('$'))
162 75
163 " Send a request with a specific handler. 76 " Send a request with a specific handler.
164 call ch_sendexpr(handle, 'hello!', {'callback': 's:RequestHandler'}) 77 call ch_sendexpr(handle, 'hello!', {'callback': 'Ch_requestHandler'})
165 call s:waitFor('exists("s:responseHandle")') 78 call WaitFor('exists("g:Ch_responseHandle")')
166 if !exists('s:responseHandle') 79 if !exists('g:Ch_responseHandle')
167 call assert_false(1, 's:responseHandle was not set') 80 call assert_false(1, 'g:Ch_responseHandle was not set')
168 else 81 else
169 call assert_equal(handle, s:responseHandle) 82 call assert_equal(handle, g:Ch_responseHandle)
170 unlet s:responseHandle 83 unlet g:Ch_responseHandle
171 endif 84 endif
172 call assert_equal('got it', s:responseMsg) 85 call assert_equal('got it', g:Ch_responseMsg)
173 86
174 let s:responseMsg = '' 87 let g:Ch_responseMsg = ''
175 call ch_sendexpr(handle, 'hello!', {'callback': function('s:RequestHandler')}) 88 call ch_sendexpr(handle, 'hello!', {'callback': function('Ch_requestHandler')})
176 call s:waitFor('exists("s:responseHandle")') 89 call WaitFor('exists("g:Ch_responseHandle")')
177 if !exists('s:responseHandle') 90 if !exists('g:Ch_responseHandle')
178 call assert_false(1, 's:responseHandle was not set') 91 call assert_false(1, 'g:Ch_responseHandle was not set')
179 else 92 else
180 call assert_equal(handle, s:responseHandle) 93 call assert_equal(handle, g:Ch_responseHandle)
181 unlet s:responseHandle 94 unlet g:Ch_responseHandle
182 endif 95 endif
183 call assert_equal('got it', s:responseMsg) 96 call assert_equal('got it', g:Ch_responseMsg)
184 97
185 " Collect garbage, tests that our handle isn't collected. 98 " Collect garbage, tests that our handle isn't collected.
186 call test_garbagecollect_now() 99 call test_garbagecollect_now()
187 100
188 " check setting options (without testing the effect) 101 " check setting options (without testing the effect)
223 sleep 10m 136 sleep 10m
224 call assert_equal([-5, 'ERROR'], ch_evalexpr(handle, 'eval-result')) 137 call assert_equal([-5, 'ERROR'], ch_evalexpr(handle, 'eval-result'))
225 138
226 " Send an expr request 139 " Send an expr request
227 call assert_equal('ok', ch_evalexpr(handle, 'an expr')) 140 call assert_equal('ok', ch_evalexpr(handle, 'an expr'))
228 call s:waitFor('"three" == getline("$")') 141 call WaitFor('"three" == getline("$")')
229 call assert_equal('one', getline(line('$') - 2)) 142 call assert_equal('one', getline(line('$') - 2))
230 call assert_equal('two', getline(line('$') - 1)) 143 call assert_equal('two', getline(line('$') - 1))
231 call assert_equal('three', getline('$')) 144 call assert_equal('three', getline('$'))
232 145
233 " Request a redraw, we don't check for the effect. 146 " Request a redraw, we don't check for the effect.
255 call ch_sendexpr(handle, '!quit!') 168 call ch_sendexpr(handle, '!quit!')
256 endfunc 169 endfunc
257 170
258 func Test_communicate() 171 func Test_communicate()
259 call ch_log('Test_communicate()') 172 call ch_log('Test_communicate()')
260 call s:run_server('s:communicate') 173 call s:run_server('Ch_communicate')
261 endfunc 174 endfunc
262 175
263 " Test that we can open two channels. 176 " Test that we can open two channels.
264 func s:two_channels(port) 177 func Ch_two_channels(port)
265 let handle = ch_open('localhost:' . a:port, s:chopt) 178 let handle = ch_open('localhost:' . a:port, s:chopt)
266 if ch_status(handle) == "fail" 179 if ch_status(handle) == "fail"
267 call assert_false(1, "Can't open channel") 180 call assert_false(1, "Can't open channel")
268 return 181 return
269 endif 182 endif
284 call ch_close(newhandle) 197 call ch_close(newhandle)
285 endfunc 198 endfunc
286 199
287 func Test_two_channels() 200 func Test_two_channels()
288 call ch_log('Test_two_channels()') 201 call ch_log('Test_two_channels()')
289 call s:run_server('s:two_channels') 202 call s:run_server('Ch_two_channels')
290 endfunc 203 endfunc
291 204
292 " Test that a server crash is handled gracefully. 205 " Test that a server crash is handled gracefully.
293 func s:server_crash(port) 206 func Ch_server_crash(port)
294 let handle = ch_open('localhost:' . a:port, s:chopt) 207 let handle = ch_open('localhost:' . a:port, s:chopt)
295 if ch_status(handle) == "fail" 208 if ch_status(handle) == "fail"
296 call assert_false(1, "Can't open channel") 209 call assert_false(1, "Can't open channel")
297 return 210 return
298 endif 211 endif
302 sleep 10m 215 sleep 10m
303 endfunc 216 endfunc
304 217
305 func Test_server_crash() 218 func Test_server_crash()
306 call ch_log('Test_server_crash()') 219 call ch_log('Test_server_crash()')
307 call s:run_server('s:server_crash') 220 call s:run_server('Ch_server_crash')
308 endfunc 221 endfunc
309 222
310 """"""""" 223 """""""""
311 224
312 let s:reply = "" 225 let g:Ch_reply = ""
313 func s:Handler(chan, msg) 226 func Ch_handler(chan, msg)
314 unlet s:reply 227 unlet g:Ch_reply
315 let s:reply = a:msg 228 let g:Ch_reply = a:msg
316 endfunc 229 endfunc
317 230
318 func s:channel_handler(port) 231 func Ch_channel_handler(port)
319 let handle = ch_open('localhost:' . a:port, s:chopt) 232 let handle = ch_open('localhost:' . a:port, s:chopt)
320 if ch_status(handle) == "fail" 233 if ch_status(handle) == "fail"
321 call assert_false(1, "Can't open channel") 234 call assert_false(1, "Can't open channel")
322 return 235 return
323 endif 236 endif
324 237
325 " Test that it works while waiting on a numbered message. 238 " Test that it works while waiting on a numbered message.
326 call assert_equal('ok', ch_evalexpr(handle, 'call me')) 239 call assert_equal('ok', ch_evalexpr(handle, 'call me'))
327 call s:waitFor('"we called you" == s:reply') 240 call WaitFor('"we called you" == g:Ch_reply')
328 call assert_equal('we called you', s:reply) 241 call assert_equal('we called you', g:Ch_reply)
329 242
330 " Test that it works while not waiting on a numbered message. 243 " Test that it works while not waiting on a numbered message.
331 call ch_sendexpr(handle, 'call me again') 244 call ch_sendexpr(handle, 'call me again')
332 call s:waitFor('"we did call you" == s:reply') 245 call WaitFor('"we did call you" == g:Ch_reply')
333 call assert_equal('we did call you', s:reply) 246 call assert_equal('we did call you', g:Ch_reply)
334 endfunc 247 endfunc
335 248
336 func Test_channel_handler() 249 func Test_channel_handler()
337 call ch_log('Test_channel_handler()') 250 call ch_log('Test_channel_handler()')
338 let s:chopt.callback = 's:Handler' 251 let s:chopt.callback = 'Ch_handler'
339 call s:run_server('s:channel_handler') 252 call s:run_server('Ch_channel_handler')
340 let s:chopt.callback = function('s:Handler') 253 let s:chopt.callback = function('Ch_handler')
341 call s:run_server('s:channel_handler') 254 call s:run_server('Ch_channel_handler')
342 unlet s:chopt.callback 255 unlet s:chopt.callback
343 endfunc 256 endfunc
344 257
345 """"""""" 258 """""""""
346 259
347 let s:ch_reply = '' 260 let g:Ch_reply = ''
348 func s:ChHandler(chan, msg) 261 func Ch_zeroHandler(chan, msg)
349 unlet s:ch_reply 262 unlet g:Ch_reply
350 let s:ch_reply = a:msg 263 let g:Ch_reply = a:msg
351 endfunc 264 endfunc
352 265
353 let s:zero_reply = '' 266 let g:Ch_zero_reply = ''
354 func s:OneHandler(chan, msg) 267 func Ch_oneHandler(chan, msg)
355 unlet s:zero_reply 268 unlet g:Ch_zero_reply
356 let s:zero_reply = a:msg 269 let g:Ch_zero_reply = a:msg
357 endfunc 270 endfunc
358 271
359 func s:channel_zero(port) 272 func Ch_channel_zero(port)
360 let handle = ch_open('localhost:' . a:port, s:chopt) 273 let handle = ch_open('localhost:' . a:port, s:chopt)
361 if ch_status(handle) == "fail" 274 if ch_status(handle) == "fail"
362 call assert_false(1, "Can't open channel") 275 call assert_false(1, "Can't open channel")
363 return 276 return
364 endif 277 endif
365 278
366 " Check that eval works. 279 " Check that eval works.
367 call assert_equal('got it', ch_evalexpr(handle, 'hello!')) 280 call assert_equal('got it', ch_evalexpr(handle, 'hello!'))
368 281
369 " Check that eval works if a zero id message is sent back. 282 " Check that eval works if a zero id message is sent back.
370 let s:ch_reply = '' 283 let g:Ch_reply = ''
371 call assert_equal('sent zero', ch_evalexpr(handle, 'send zero')) 284 call assert_equal('sent zero', ch_evalexpr(handle, 'send zero'))
372 if s:has_handler 285 if s:has_handler
373 call s:waitFor('"zero index" == s:ch_reply') 286 call WaitFor('"zero index" == g:Ch_reply')
374 call assert_equal('zero index', s:ch_reply) 287 call assert_equal('zero index', g:Ch_reply)
375 else 288 else
376 sleep 20m 289 sleep 20m
377 call assert_equal('', s:ch_reply) 290 call assert_equal('', g:Ch_reply)
378 endif 291 endif
379 292
380 " Check that handler works if a zero id message is sent back. 293 " Check that handler works if a zero id message is sent back.
381 let s:ch_reply = '' 294 let g:Ch_reply = ''
382 let s:zero_reply = '' 295 let g:Ch_zero_reply = ''
383 call ch_sendexpr(handle, 'send zero', {'callback': 's:OneHandler'}) 296 call ch_sendexpr(handle, 'send zero', {'callback': 'Ch_oneHandler'})
384 call s:waitFor('"sent zero" == s:zero_reply') 297 call WaitFor('"sent zero" == g:Ch_zero_reply')
385 if s:has_handler 298 if s:has_handler
386 call assert_equal('zero index', s:ch_reply) 299 call assert_equal('zero index', g:Ch_reply)
387 else 300 else
388 call assert_equal('', s:ch_reply) 301 call assert_equal('', g:Ch_reply)
389 endif 302 endif
390 call assert_equal('sent zero', s:zero_reply) 303 call assert_equal('sent zero', g:Ch_zero_reply)
391 endfunc 304 endfunc
392 305
393 func Test_zero_reply() 306 func Test_zero_reply()
394 call ch_log('Test_zero_reply()') 307 call ch_log('Test_zero_reply()')
395 " Run with channel handler 308 " Run with channel handler
396 let s:has_handler = 1 309 let s:has_handler = 1
397 let s:chopt.callback = 's:ChHandler' 310 let s:chopt.callback = 'Ch_zeroHandler'
398 call s:run_server('s:channel_zero') 311 call s:run_server('Ch_channel_zero')
399 unlet s:chopt.callback 312 unlet s:chopt.callback
400 313
401 " Run without channel handler 314 " Run without channel handler
402 let s:has_handler = 0 315 let s:has_handler = 0
403 call s:run_server('s:channel_zero') 316 call s:run_server('Ch_channel_zero')
404 endfunc 317 endfunc
405 318
406 """"""""" 319 """""""""
407 320
408 let s:reply1 = "" 321 let g:Ch_reply1 = ""
409 func s:HandleRaw1(chan, msg) 322 func Ch_handleRaw1(chan, msg)
410 unlet s:reply1 323 unlet g:Ch_reply1
411 let s:reply1 = a:msg 324 let g:Ch_reply1 = a:msg
412 endfunc 325 endfunc
413 326
414 let s:reply2 = "" 327 let g:Ch_reply2 = ""
415 func s:HandleRaw2(chan, msg) 328 func Ch_handleRaw2(chan, msg)
416 unlet s:reply2 329 unlet g:Ch_reply2
417 let s:reply2 = a:msg 330 let g:Ch_reply2 = a:msg
418 endfunc 331 endfunc
419 332
420 let s:reply3 = "" 333 let g:Ch_reply3 = ""
421 func s:HandleRaw3(chan, msg) 334 func Ch_handleRaw3(chan, msg)
422 unlet s:reply3 335 unlet g:Ch_reply3
423 let s:reply3 = a:msg 336 let g:Ch_reply3 = a:msg
424 endfunc 337 endfunc
425 338
426 func s:raw_one_time_callback(port) 339 func Ch_raw_one_time_callback(port)
427 let handle = ch_open('localhost:' . a:port, s:chopt) 340 let handle = ch_open('localhost:' . a:port, s:chopt)
428 if ch_status(handle) == "fail" 341 if ch_status(handle) == "fail"
429 call assert_false(1, "Can't open channel") 342 call assert_false(1, "Can't open channel")
430 return 343 return
431 endif 344 endif
432 call ch_setoptions(handle, {'mode': 'raw'}) 345 call ch_setoptions(handle, {'mode': 'raw'})
433 346
434 " The message are sent raw, we do our own JSON strings here. 347 " The message are sent raw, we do our own JSON strings here.
435 call ch_sendraw(handle, "[1, \"hello!\"]", {'callback': 's:HandleRaw1'}) 348 call ch_sendraw(handle, "[1, \"hello!\"]", {'callback': 'Ch_handleRaw1'})
436 call s:waitFor('s:reply1 != ""') 349 call WaitFor('g:Ch_reply1 != ""')
437 call assert_equal("[1, \"got it\"]", s:reply1) 350 call assert_equal("[1, \"got it\"]", g:Ch_reply1)
438 call ch_sendraw(handle, "[2, \"echo something\"]", {'callback': 's:HandleRaw2'}) 351 call ch_sendraw(handle, "[2, \"echo something\"]", {'callback': 'Ch_handleRaw2'})
439 call ch_sendraw(handle, "[3, \"wait a bit\"]", {'callback': 's:HandleRaw3'}) 352 call ch_sendraw(handle, "[3, \"wait a bit\"]", {'callback': 'Ch_handleRaw3'})
440 call s:waitFor('s:reply2 != ""') 353 call WaitFor('g:Ch_reply2 != ""')
441 call assert_equal("[2, \"something\"]", s:reply2) 354 call assert_equal("[2, \"something\"]", g:Ch_reply2)
442 " wait for the 200 msec delayed reply 355 " wait for the 200 msec delayed reply
443 call s:waitFor('s:reply3 != ""') 356 call WaitFor('g:Ch_reply3 != ""')
444 call assert_equal("[3, \"waited\"]", s:reply3) 357 call assert_equal("[3, \"waited\"]", g:Ch_reply3)
445 endfunc 358 endfunc
446 359
447 func Test_raw_one_time_callback() 360 func Test_raw_one_time_callback()
448 call ch_log('Test_raw_one_time_callback()') 361 call ch_log('Test_raw_one_time_callback()')
449 call s:run_server('s:raw_one_time_callback') 362 call s:run_server('Ch_raw_one_time_callback')
450 endfunc 363 endfunc
451 364
452 """"""""" 365 """""""""
453 366
454 " Test that trying to connect to a non-existing port fails quickly. 367 " Test that trying to connect to a non-existing port fails quickly.
510 call assert_equal("Goodbye!\n", substitute(reply, "\r", "", 'g')) 423 call assert_equal("Goodbye!\n", substitute(reply, "\r", "", 'g'))
511 finally 424 finally
512 call job_stop(job) 425 call job_stop(job)
513 endtry 426 endtry
514 427
515 let s:job = job 428 let g:Ch_job = job
516 call s:waitFor('"dead" == job_status(s:job)') 429 call WaitFor('"dead" == job_status(g:Ch_job)')
517 let info = job_info(job) 430 let info = job_info(job)
518 call assert_equal("dead", info.status) 431 call assert_equal("dead", info.status)
519 call assert_equal("term", info.stoponexit) 432 call assert_equal("term", info.stoponexit)
520 endfunc 433 endfunc
521 434
626 try 539 try
627 let handle = job_getchannel(job) 540 let handle = job_getchannel(job)
628 call ch_sendraw(handle, "echo line one\n") 541 call ch_sendraw(handle, "echo line one\n")
629 call ch_sendraw(handle, "echo line two\n") 542 call ch_sendraw(handle, "echo line two\n")
630 call ch_sendraw(handle, "double this\n") 543 call ch_sendraw(handle, "double this\n")
631 call s:waitFor('len(readfile("Xoutput")) > 2') 544 call WaitFor('len(readfile("Xoutput")) > 2')
632 call assert_equal(['line one', 'line two', 'this', 'AND this'], readfile('Xoutput')) 545 call assert_equal(['line one', 'line two', 'this', 'AND this'], readfile('Xoutput'))
633 finally 546 finally
634 call job_stop(job) 547 call job_stop(job)
635 call delete('Xoutput') 548 call delete('Xoutput')
636 endtry 549 endtry
647 try 560 try
648 let handle = job_getchannel(job) 561 let handle = job_getchannel(job)
649 call ch_sendraw(handle, "echoerr line one\n") 562 call ch_sendraw(handle, "echoerr line one\n")
650 call ch_sendraw(handle, "echoerr line two\n") 563 call ch_sendraw(handle, "echoerr line two\n")
651 call ch_sendraw(handle, "doubleerr this\n") 564 call ch_sendraw(handle, "doubleerr this\n")
652 call s:waitFor('len(readfile("Xoutput")) > 2') 565 call WaitFor('len(readfile("Xoutput")) > 2')
653 call assert_equal(['line one', 'line two', 'this', 'AND this'], readfile('Xoutput')) 566 call assert_equal(['line one', 'line two', 'this', 'AND this'], readfile('Xoutput'))
654 finally 567 finally
655 call job_stop(job) 568 call job_stop(job)
656 call delete('Xoutput') 569 call delete('Xoutput')
657 endtry 570 endtry
669 let handle = job_getchannel(job) 582 let handle = job_getchannel(job)
670 call ch_sendraw(handle, "echoerr line one\n") 583 call ch_sendraw(handle, "echoerr line one\n")
671 call ch_sendraw(handle, "echo line two\n") 584 call ch_sendraw(handle, "echo line two\n")
672 call ch_sendraw(handle, "double this\n") 585 call ch_sendraw(handle, "double this\n")
673 call ch_sendraw(handle, "doubleerr that\n") 586 call ch_sendraw(handle, "doubleerr that\n")
674 call s:waitFor('len(readfile("Xoutput")) > 5') 587 call WaitFor('len(readfile("Xoutput")) > 5')
675 call assert_equal(['line one', 'line two', 'this', 'AND this', 'that', 'AND that'], readfile('Xoutput')) 588 call assert_equal(['line one', 'line two', 'this', 'AND this', 'that', 'AND that'], readfile('Xoutput'))
676 finally 589 finally
677 call job_stop(job) 590 call job_stop(job)
678 call delete('Xoutput') 591 call delete('Xoutput')
679 endtry 592 endtry
680 endfunc 593 endfunc
681 594
682 func BufCloseCb(ch) 595 func BufCloseCb(ch)
683 let s:bufClosed = 'yes' 596 let g:Ch_bufClosed = 'yes'
684 endfunc 597 endfunc
685 598
686 func Run_test_pipe_to_buffer(use_name, nomod) 599 func Run_test_pipe_to_buffer(use_name, nomod)
687 if !has('job') 600 if !has('job')
688 return 601 return
689 endif 602 endif
690 call ch_log('Test_pipe_to_buffer()') 603 call ch_log('Test_pipe_to_buffer()')
691 let s:bufClosed = 'no' 604 let g:Ch_bufClosed = 'no'
692 let options = {'out_io': 'buffer', 'close_cb': 'BufCloseCb'} 605 let options = {'out_io': 'buffer', 'close_cb': 'BufCloseCb'}
693 if a:use_name 606 if a:use_name
694 let options['out_name'] = 'pipe-output' 607 let options['out_name'] = 'pipe-output'
695 let firstline = 'Reading from channel output...' 608 let firstline = 'Reading from channel output...'
696 else 609 else
709 call ch_sendraw(handle, "echo line one\n") 622 call ch_sendraw(handle, "echo line one\n")
710 call ch_sendraw(handle, "echo line two\n") 623 call ch_sendraw(handle, "echo line two\n")
711 call ch_sendraw(handle, "double this\n") 624 call ch_sendraw(handle, "double this\n")
712 call ch_sendraw(handle, "quit\n") 625 call ch_sendraw(handle, "quit\n")
713 sp pipe-output 626 sp pipe-output
714 call s:waitFor('line("$") >= 6 && s:bufClosed == "yes"') 627 call WaitFor('line("$") >= 6 && g:Ch_bufClosed == "yes"')
715 call assert_equal([firstline, 'line one', 'line two', 'this', 'AND this', 'Goodbye!'], getline(1, '$')) 628 call assert_equal([firstline, 'line one', 'line two', 'this', 'AND this', 'Goodbye!'], getline(1, '$'))
716 if a:nomod 629 if a:nomod
717 call assert_equal(0, &modifiable) 630 call assert_equal(0, &modifiable)
718 else 631 else
719 call assert_equal(1, &modifiable) 632 call assert_equal(1, &modifiable)
720 endif 633 endif
721 call assert_equal('yes', s:bufClosed) 634 call assert_equal('yes', g:Ch_bufClosed)
722 bwipe! 635 bwipe!
723 finally 636 finally
724 call job_stop(job) 637 call job_stop(job)
725 endtry 638 endtry
726 endfunc 639 endfunc
762 call ch_sendraw(handle, "echoerr line one\n") 675 call ch_sendraw(handle, "echoerr line one\n")
763 call ch_sendraw(handle, "echoerr line two\n") 676 call ch_sendraw(handle, "echoerr line two\n")
764 call ch_sendraw(handle, "doubleerr this\n") 677 call ch_sendraw(handle, "doubleerr this\n")
765 call ch_sendraw(handle, "quit\n") 678 call ch_sendraw(handle, "quit\n")
766 sp pipe-err 679 sp pipe-err
767 call s:waitFor('line("$") >= 5') 680 call WaitFor('line("$") >= 5')
768 call assert_equal([firstline, 'line one', 'line two', 'this', 'AND this'], getline(1, '$')) 681 call assert_equal([firstline, 'line one', 'line two', 'this', 'AND this'], getline(1, '$'))
769 if a:nomod 682 if a:nomod
770 call assert_equal(0, &modifiable) 683 call assert_equal(0, &modifiable)
771 else 684 else
772 call assert_equal(1, &modifiable) 685 call assert_equal(1, &modifiable)
803 call ch_sendraw(handle, "echoerr line two\n") 716 call ch_sendraw(handle, "echoerr line two\n")
804 call ch_sendraw(handle, "double this\n") 717 call ch_sendraw(handle, "double this\n")
805 call ch_sendraw(handle, "doubleerr that\n") 718 call ch_sendraw(handle, "doubleerr that\n")
806 call ch_sendraw(handle, "quit\n") 719 call ch_sendraw(handle, "quit\n")
807 sp pipe-err 720 sp pipe-err
808 call s:waitFor('line("$") >= 7') 721 call WaitFor('line("$") >= 7')
809 call assert_equal(['Reading from channel output...', 'line one', 'line two', 'this', 'AND this', 'that', 'AND that', 'Goodbye!'], getline(1, '$')) 722 call assert_equal(['Reading from channel output...', 'line one', 'line two', 'this', 'AND this', 'that', 'AND that', 'Goodbye!'], getline(1, '$'))
810 bwipe! 723 bwipe!
811 finally 724 finally
812 call job_stop(job) 725 call job_stop(job)
813 endtry 726 endtry
860 try 773 try
861 let handle = job_getchannel(job) 774 let handle = job_getchannel(job)
862 call ch_sendraw(handle, "echo line one\n") 775 call ch_sendraw(handle, "echo line one\n")
863 call ch_sendraw(handle, "echo line two\n") 776 call ch_sendraw(handle, "echo line two\n")
864 exe ch_getbufnr(handle, "out") . 'sbuf' 777 exe ch_getbufnr(handle, "out") . 'sbuf'
865 call s:waitFor('line("$") >= 3') 778 call WaitFor('line("$") >= 3')
866 call assert_equal(['Reading from channel output...', 'line one', 'line two'], getline(1, '$')) 779 call assert_equal(['Reading from channel output...', 'line one', 'line two'], getline(1, '$'))
867 bwipe! 780 bwipe!
868 finally 781 finally
869 call job_stop(job) 782 call job_stop(job)
870 endtry 783 endtry
881 try 794 try
882 let handle = job_getchannel(job) 795 let handle = job_getchannel(job)
883 call ch_sendraw(handle, "echo [0, \"hello\"]\n") 796 call ch_sendraw(handle, "echo [0, \"hello\"]\n")
884 call ch_sendraw(handle, "echo [-2, 12.34]\n") 797 call ch_sendraw(handle, "echo [-2, 12.34]\n")
885 exe ch_getbufnr(handle, "out") . 'sbuf' 798 exe ch_getbufnr(handle, "out") . 'sbuf'
886 call s:waitFor('line("$") >= 3') 799 call WaitFor('line("$") >= 3')
887 call assert_equal(['Reading from channel output...', '[0,"hello"]', '[-2,12.34]'], getline(1, '$')) 800 call assert_equal(['Reading from channel output...', '[0,"hello"]', '[-2,12.34]'], getline(1, '$'))
888 bwipe! 801 bwipe!
889 finally 802 finally
890 call job_stop(job) 803 call job_stop(job)
891 endtry 804 endtry
1026 let options = {'out_mode': 'raw', 'out_io': 'buffer', 'out_name': 'testout'} 939 let options = {'out_mode': 'raw', 'out_io': 'buffer', 'out_name': 'testout'}
1027 split testout 940 split testout
1028 let job = job_start([s:python, '-c', 941 let job = job_start([s:python, '-c',
1029 \ 'import sys; [sys.stdout.write(".") and sys.stdout.flush() for _ in range(10000)]'], options) 942 \ 'import sys; [sys.stdout.write(".") and sys.stdout.flush() for _ in range(10000)]'], options)
1030 call assert_equal("run", job_status(job)) 943 call assert_equal("run", job_status(job))
1031 call s:waitFor('len(join(getline(2,line("$")),"") >= 10000') 944 call WaitFor('len(join(getline(2,line("$")),"") >= 10000')
1032 try 945 try
1033 for line in getline(2, '$') 946 for line in getline(2, '$')
1034 let line = substitute(line, '^\.*', '', '') 947 let line = substitute(line, '^\.*', '', '')
1035 call assert_equal('', line) 948 call assert_equal('', line)
1036 endfor 949 endfor
1073 endif 986 endif
1074 call ch_log('Test_out_cb()') 987 call ch_log('Test_out_cb()')
1075 988
1076 let dict = {'thisis': 'dict: '} 989 let dict = {'thisis': 'dict: '}
1077 func dict.outHandler(chan, msg) dict 990 func dict.outHandler(chan, msg) dict
1078 let s:outmsg = self.thisis . a:msg 991 let g:Ch_outmsg = self.thisis . a:msg
1079 endfunc 992 endfunc
1080 func dict.errHandler(chan, msg) dict 993 func dict.errHandler(chan, msg) dict
1081 let s:errmsg = self.thisis . a:msg 994 let g:Ch_errmsg = self.thisis . a:msg
1082 endfunc 995 endfunc
1083 let job = job_start(s:python . " test_channel_pipe.py", 996 let job = job_start(s:python . " test_channel_pipe.py",
1084 \ {'out_cb': dict.outHandler, 997 \ {'out_cb': dict.outHandler,
1085 \ 'out_mode': 'json', 998 \ 'out_mode': 'json',
1086 \ 'err_cb': dict.errHandler, 999 \ 'err_cb': dict.errHandler,
1087 \ 'err_mode': 'json'}) 1000 \ 'err_mode': 'json'})
1088 call assert_equal("run", job_status(job)) 1001 call assert_equal("run", job_status(job))
1089 try 1002 try
1090 let s:outmsg = '' 1003 let g:Ch_outmsg = ''
1091 let s:errmsg = '' 1004 let g:Ch_errmsg = ''
1092 call ch_sendraw(job, "echo [0, \"hello\"]\n") 1005 call ch_sendraw(job, "echo [0, \"hello\"]\n")
1093 call ch_sendraw(job, "echoerr [0, \"there\"]\n") 1006 call ch_sendraw(job, "echoerr [0, \"there\"]\n")
1094 call s:waitFor('s:outmsg != ""') 1007 call WaitFor('g:Ch_outmsg != ""')
1095 call assert_equal("dict: hello", s:outmsg) 1008 call assert_equal("dict: hello", g:Ch_outmsg)
1096 call s:waitFor('s:errmsg != ""') 1009 call WaitFor('g:Ch_errmsg != ""')
1097 call assert_equal("dict: there", s:errmsg) 1010 call assert_equal("dict: there", g:Ch_errmsg)
1098 finally 1011 finally
1099 call job_stop(job) 1012 call job_stop(job)
1100 endtry 1013 endtry
1101 endfunc 1014 endfunc
1102 1015
1105 return 1018 return
1106 endif 1019 endif
1107 call ch_log('Test_out_close_cb()') 1020 call ch_log('Test_out_close_cb()')
1108 1021
1109 let s:counter = 1 1022 let s:counter = 1
1110 let s:msg1 = '' 1023 let g:Ch_msg1 = ''
1111 let s:closemsg = 0 1024 let g:Ch_closemsg = 0
1112 func! OutHandler(chan, msg) 1025 func! OutHandler(chan, msg)
1113 if s:counter == 1 1026 if s:counter == 1
1114 let s:msg1 = a:msg 1027 let g:Ch_msg1 = a:msg
1115 endif 1028 endif
1116 let s:counter += 1 1029 let s:counter += 1
1117 endfunc 1030 endfunc
1118 func! CloseHandler(chan) 1031 func! CloseHandler(chan)
1119 let s:closemsg = s:counter 1032 let g:Ch_closemsg = s:counter
1120 let s:counter += 1 1033 let s:counter += 1
1121 endfunc 1034 endfunc
1122 let job = job_start(s:python . " test_channel_pipe.py quit now", 1035 let job = job_start(s:python . " test_channel_pipe.py quit now",
1123 \ {'out_cb': 'OutHandler', 1036 \ {'out_cb': 'OutHandler',
1124 \ 'close_cb': 'CloseHandler'}) 1037 \ 'close_cb': 'CloseHandler'})
1125 call assert_equal("run", job_status(job)) 1038 call assert_equal("run", job_status(job))
1126 try 1039 try
1127 call s:waitFor('s:closemsg != 0 && s:msg1 != ""') 1040 call WaitFor('g:Ch_closemsg != 0 && g:Ch_msg1 != ""')
1128 call assert_equal('quit', s:msg1) 1041 call assert_equal('quit', g:Ch_msg1)
1129 call assert_equal(2, s:closemsg) 1042 call assert_equal(2, g:Ch_closemsg)
1130 finally 1043 finally
1131 call job_stop(job) 1044 call job_stop(job)
1132 delfunc OutHandler 1045 delfunc OutHandler
1133 delfunc CloseHandler 1046 delfunc CloseHandler
1134 endtry 1047 endtry
1138 if !has('job') 1051 if !has('job')
1139 return 1052 return
1140 endif 1053 endif
1141 call ch_log('Test_read_in_close_cb()') 1054 call ch_log('Test_read_in_close_cb()')
1142 1055
1143 let s:received = '' 1056 let g:Ch_received = ''
1144 func! CloseHandler(chan) 1057 func! CloseHandler(chan)
1145 let s:received = ch_read(a:chan) 1058 let g:Ch_received = ch_read(a:chan)
1146 endfunc 1059 endfunc
1147 let job = job_start(s:python . " test_channel_pipe.py quit now", 1060 let job = job_start(s:python . " test_channel_pipe.py quit now",
1148 \ {'close_cb': 'CloseHandler'}) 1061 \ {'close_cb': 'CloseHandler'})
1149 call assert_equal("run", job_status(job)) 1062 call assert_equal("run", job_status(job))
1150 try 1063 try
1151 call s:waitFor('s:received != ""') 1064 call WaitFor('g:Ch_received != ""')
1152 call assert_equal('quit', s:received) 1065 call assert_equal('quit', g:Ch_received)
1153 finally 1066 finally
1154 call job_stop(job) 1067 call job_stop(job)
1155 delfunc CloseHandler 1068 delfunc CloseHandler
1156 endtry 1069 endtry
1157 endfunc 1070 endfunc
1158 1071
1159 """""""""" 1072 """"""""""
1160 1073
1161 let s:unletResponse = '' 1074 let g:Ch_unletResponse = ''
1162 func s:UnletHandler(handle, msg) 1075 func s:UnletHandler(handle, msg)
1163 let s:unletResponse = a:msg 1076 let g:Ch_unletResponse = a:msg
1164 unlet s:channelfd 1077 unlet s:channelfd
1165 endfunc 1078 endfunc
1166 1079
1167 " Test that "unlet handle" in a handler doesn't crash Vim. 1080 " Test that "unlet handle" in a handler doesn't crash Vim.
1168 func s:unlet_handle(port) 1081 func Ch_unlet_handle(port)
1169 let s:channelfd = ch_open('localhost:' . a:port, s:chopt) 1082 let s:channelfd = ch_open('localhost:' . a:port, s:chopt)
1170 call ch_sendexpr(s:channelfd, "test", {'callback': function('s:UnletHandler')}) 1083 call ch_sendexpr(s:channelfd, "test", {'callback': function('s:UnletHandler')})
1171 call s:waitFor('"what?" == s:unletResponse') 1084 call WaitFor('"what?" == g:Ch_unletResponse')
1172 call assert_equal('what?', s:unletResponse) 1085 call assert_equal('what?', g:Ch_unletResponse)
1173 endfunc 1086 endfunc
1174 1087
1175 func Test_unlet_handle() 1088 func Test_unlet_handle()
1176 call ch_log('Test_unlet_handle()') 1089 call ch_log('Test_unlet_handle()')
1177 call s:run_server('s:unlet_handle') 1090 call s:run_server('Ch_unlet_handle')
1178 endfunc 1091 endfunc
1179 1092
1180 """""""""" 1093 """"""""""
1181 1094
1182 let s:unletResponse = '' 1095 let g:Ch_unletResponse = ''
1183 func s:CloseHandler(handle, msg) 1096 func Ch_CloseHandler(handle, msg)
1184 let s:unletResponse = a:msg 1097 let g:Ch_unletResponse = a:msg
1185 call ch_close(s:channelfd) 1098 call ch_close(s:channelfd)
1186 endfunc 1099 endfunc
1187 1100
1188 " Test that "unlet handle" in a handler doesn't crash Vim. 1101 " Test that "unlet handle" in a handler doesn't crash Vim.
1189 func s:close_handle(port) 1102 func Ch_close_handle(port)
1190 let s:channelfd = ch_open('localhost:' . a:port, s:chopt) 1103 let s:channelfd = ch_open('localhost:' . a:port, s:chopt)
1191 call ch_sendexpr(s:channelfd, "test", {'callback': function('s:CloseHandler')}) 1104 call ch_sendexpr(s:channelfd, "test", {'callback': function('Ch_CloseHandler')})
1192 call s:waitFor('"what?" == s:unletResponse') 1105 call WaitFor('"what?" == g:Ch_unletResponse')
1193 call assert_equal('what?', s:unletResponse) 1106 call assert_equal('what?', g:Ch_unletResponse)
1194 endfunc 1107 endfunc
1195 1108
1196 func Test_close_handle() 1109 func Test_close_handle()
1197 call ch_log('Test_close_handle()') 1110 call ch_log('Test_close_handle()')
1198 call s:run_server('s:close_handle') 1111 call s:run_server('Ch_close_handle')
1199 endfunc 1112 endfunc
1200 1113
1201 """""""""" 1114 """"""""""
1202 1115
1203 func Test_open_fail() 1116 func Test_open_fail()
1207 let d = ch 1120 let d = ch
1208 endfunc 1121 endfunc
1209 1122
1210 """""""""" 1123 """"""""""
1211 1124
1212 func s:open_delay(port) 1125 func Ch_open_delay(port)
1213 " Wait up to a second for the port to open. 1126 " Wait up to a second for the port to open.
1214 let s:chopt.waittime = 1000 1127 let s:chopt.waittime = 1000
1215 let channel = ch_open('localhost:' . a:port, s:chopt) 1128 let channel = ch_open('localhost:' . a:port, s:chopt)
1216 unlet s:chopt.waittime 1129 unlet s:chopt.waittime
1217 if ch_status(channel) == "fail" 1130 if ch_status(channel) == "fail"
1223 endfunc 1136 endfunc
1224 1137
1225 func Test_open_delay() 1138 func Test_open_delay()
1226 call ch_log('Test_open_delay()') 1139 call ch_log('Test_open_delay()')
1227 " The server will wait half a second before creating the port. 1140 " The server will wait half a second before creating the port.
1228 call s:run_server('s:open_delay', 'delay') 1141 call s:run_server('Ch_open_delay', 'delay')
1229 endfunc 1142 endfunc
1230 1143
1231 """"""""" 1144 """""""""
1232 1145
1233 function MyFunction(a,b,c) 1146 function MyFunction(a,b,c)
1234 let s:call_ret = [a:a, a:b, a:c] 1147 let g:Ch_call_ret = [a:a, a:b, a:c]
1235 endfunc 1148 endfunc
1236 1149
1237 function s:test_call(port) 1150 function Ch_test_call(port)
1238 let handle = ch_open('localhost:' . a:port, s:chopt) 1151 let handle = ch_open('localhost:' . a:port, s:chopt)
1239 if ch_status(handle) == "fail" 1152 if ch_status(handle) == "fail"
1240 call assert_false(1, "Can't open channel") 1153 call assert_false(1, "Can't open channel")
1241 return 1154 return
1242 endif 1155 endif
1243 1156
1244 let s:call_ret = [] 1157 let g:Ch_call_ret = []
1245 call assert_equal('ok', ch_evalexpr(handle, 'call-func')) 1158 call assert_equal('ok', ch_evalexpr(handle, 'call-func'))
1246 call s:waitFor('len(s:call_ret) > 0') 1159 call WaitFor('len(g:Ch_call_ret) > 0')
1247 call assert_equal([1, 2, 3], s:call_ret) 1160 call assert_equal([1, 2, 3], g:Ch_call_ret)
1248 endfunc 1161 endfunc
1249 1162
1250 func Test_call() 1163 func Test_call()
1251 call ch_log('Test_call()') 1164 call ch_log('Test_call()')
1252 call s:run_server('s:test_call') 1165 call s:run_server('Ch_test_call')
1253 endfunc 1166 endfunc
1254 1167
1255 """"""""" 1168 """""""""
1256 1169
1257 let s:job_exit_ret = 'not yet' 1170 let g:Ch_job_exit_ret = 'not yet'
1258 function MyExitCb(job, status) 1171 function MyExitCb(job, status)
1259 let s:job_exit_ret = 'done' 1172 let g:Ch_job_exit_ret = 'done'
1260 endfunc 1173 endfunc
1261 1174
1262 function s:test_exit_callback(port) 1175 function Ch_test_exit_callback(port)
1263 call job_setoptions(s:job, {'exit_cb': 'MyExitCb'}) 1176 call job_setoptions(g:currentJob, {'exit_cb': 'MyExitCb'})
1264 let s:exit_job = s:job 1177 let g:Ch_exit_job = g:currentJob
1265 call assert_equal('MyExitCb', job_info(s:job)['exit_cb']) 1178 call assert_equal('MyExitCb', job_info(g:currentJob)['exit_cb'])
1266 endfunc 1179 endfunc
1267 1180
1268 func Test_exit_callback() 1181 func Test_exit_callback()
1269 if has('job') 1182 if has('job')
1270 call ch_log('Test_exit_callback()') 1183 call ch_log('Test_exit_callback()')
1271 call s:run_server('s:test_exit_callback') 1184 call s:run_server('Ch_test_exit_callback')
1272 1185
1273 " wait up to a second for the job to exit 1186 " wait up to a second for the job to exit
1274 for i in range(100) 1187 for i in range(100)
1275 if s:job_exit_ret == 'done' 1188 if g:Ch_job_exit_ret == 'done'
1276 break 1189 break
1277 endif 1190 endif
1278 sleep 10m 1191 sleep 10m
1279 " calling job_status() triggers the callback 1192 " calling job_status() triggers the callback
1280 call job_status(s:exit_job) 1193 call job_status(g:Ch_exit_job)
1281 endfor 1194 endfor
1282 1195
1283 call assert_equal('done', s:job_exit_ret) 1196 call assert_equal('done', g:Ch_job_exit_ret)
1284 call assert_equal('dead', job_info(s:exit_job).status) 1197 call assert_equal('dead', job_info(g:Ch_exit_job).status)
1285 unlet s:exit_job 1198 unlet g:Ch_exit_job
1286 endif 1199 endif
1287 endfunc 1200 endfunc
1288 1201
1289 """"""""" 1202 """""""""
1290 1203
1291 let s:ch_close_ret = 'alive' 1204 let g:Ch_close_ret = 'alive'
1292 function MyCloseCb(ch) 1205 function MyCloseCb(ch)
1293 let s:ch_close_ret = 'closed' 1206 let g:Ch_close_ret = 'closed'
1294 endfunc 1207 endfunc
1295 1208
1296 function s:test_close_callback(port) 1209 function Ch_test_close_callback(port)
1297 let handle = ch_open('localhost:' . a:port, s:chopt) 1210 let handle = ch_open('localhost:' . a:port, s:chopt)
1298 if ch_status(handle) == "fail" 1211 if ch_status(handle) == "fail"
1299 call assert_false(1, "Can't open channel") 1212 call assert_false(1, "Can't open channel")
1300 return 1213 return
1301 endif 1214 endif
1302 call ch_setoptions(handle, {'close_cb': 'MyCloseCb'}) 1215 call ch_setoptions(handle, {'close_cb': 'MyCloseCb'})
1303 1216
1304 call assert_equal('', ch_evalexpr(handle, 'close me')) 1217 call assert_equal('', ch_evalexpr(handle, 'close me'))
1305 call s:waitFor('"closed" == s:ch_close_ret') 1218 call WaitFor('"closed" == g:Ch_close_ret')
1306 call assert_equal('closed', s:ch_close_ret) 1219 call assert_equal('closed', g:Ch_close_ret)
1307 endfunc 1220 endfunc
1308 1221
1309 func Test_close_callback() 1222 func Test_close_callback()
1310 call ch_log('Test_close_callback()') 1223 call ch_log('Test_close_callback()')
1311 call s:run_server('s:test_close_callback') 1224 call s:run_server('Ch_test_close_callback')
1312 endfunc 1225 endfunc
1313 1226
1314 function s:test_close_partial(port) 1227 function Ch_test_close_partial(port)
1315 let handle = ch_open('localhost:' . a:port, s:chopt) 1228 let handle = ch_open('localhost:' . a:port, s:chopt)
1316 if ch_status(handle) == "fail" 1229 if ch_status(handle) == "fail"
1317 call assert_false(1, "Can't open channel") 1230 call assert_false(1, "Can't open channel")
1318 return 1231 return
1319 endif 1232 endif
1320 let s:d = {} 1233 let g:Ch_d = {}
1321 func s:d.closeCb(ch) dict 1234 func g:Ch_d.closeCb(ch) dict
1322 let self.close_ret = 'closed' 1235 let self.close_ret = 'closed'
1323 endfunc 1236 endfunc
1324 call ch_setoptions(handle, {'close_cb': s:d.closeCb}) 1237 call ch_setoptions(handle, {'close_cb': g:Ch_d.closeCb})
1325 1238
1326 call assert_equal('', ch_evalexpr(handle, 'close me')) 1239 call assert_equal('', ch_evalexpr(handle, 'close me'))
1327 call s:waitFor('"closed" == s:d.close_ret') 1240 call WaitFor('"closed" == g:Ch_d.close_ret')
1328 call assert_equal('closed', s:d.close_ret) 1241 call assert_equal('closed', g:Ch_d.close_ret)
1329 unlet s:d 1242 unlet g:Ch_d
1330 endfunc 1243 endfunc
1331 1244
1332 func Test_close_partial() 1245 func Test_close_partial()
1333 call ch_log('Test_close_partial()') 1246 call ch_log('Test_close_partial()')
1334 call s:run_server('s:test_close_partial') 1247 call s:run_server('Ch_test_close_partial')
1335 endfunc 1248 endfunc
1336 1249
1337 func Test_job_start_invalid() 1250 func Test_job_start_invalid()
1338 call assert_fails('call job_start($x)', 'E474:') 1251 call assert_fails('call job_start($x)', 'E474:')
1339 call assert_fails('call job_start("")', 'E474:') 1252 call assert_fails('call job_start("")', 'E474:')
1365 let g:linecount = line('$') 1278 let g:linecount = line('$')
1366 close 1279 close
1367 split testout 1280 split testout
1368 1,$delete 1281 1,$delete
1369 call job_start('cat test_channel.vim', {'out_io': 'buffer', 'out_name': 'testout'}) 1282 call job_start('cat test_channel.vim', {'out_io': 'buffer', 'out_name': 'testout'})
1370 call s:waitFor('line("$") > g:linecount') 1283 call WaitFor('line("$") > g:linecount')
1371 call assert_true(line('$') > g:linecount) 1284 call assert_true(line('$') > g:linecount)
1372 bwipe! 1285 bwipe!
1373 endfunc 1286 endfunc
1374 1287
1375 1288
1376 " Uncomment this to see what happens, output is in src/testdir/channellog. 1289 " Uncomment this to see what happens, output is in src/testdir/channellog.
1377 " call ch_logfile('channellog', 'w') 1290 call ch_logfile('channellog', 'w')