Mercurial > vim
comparison src/testdir/test_channel.vim @ 12765:c1347c968d31 v8.0.1260
patch 8.0.1260: using global variables for WaitFor()
commit https://github.com/vim/vim/commit/ab8b1c14a31e36ae87cc7e13c4a75318d513fc7b
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Nov 4 19:24:31 2017 +0100
patch 8.0.1260: using global variables for WaitFor()
Problem: Using global variables for WaitFor().
Solution: Use a lambda function instead. Don't check a condition if
WaitFor() already checked it.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 04 Nov 2017 19:30:06 +0100 |
parents | 810a4c3d4f7e |
children | 6cf6138b6484 |
comparison
equal
deleted
inserted
replaced
12764:c5c3974588fe | 12765:c1347c968d31 |
---|---|
272 endif | 272 endif |
273 | 273 |
274 " Test that it works while waiting on a numbered message. | 274 " Test that it works while waiting on a numbered message. |
275 call assert_equal('ok', ch_evalexpr(handle, 'call me')) | 275 call assert_equal('ok', ch_evalexpr(handle, 'call me')) |
276 call WaitFor('"we called you" == g:Ch_reply') | 276 call WaitFor('"we called you" == g:Ch_reply') |
277 call assert_equal('we called you', g:Ch_reply) | |
278 | 277 |
279 " Test that it works while not waiting on a numbered message. | 278 " Test that it works while not waiting on a numbered message. |
280 call ch_sendexpr(handle, 'call me again') | 279 call ch_sendexpr(handle, 'call me again') |
281 call WaitFor('"we did call you" == g:Ch_reply') | 280 call WaitFor('"we did call you" == g:Ch_reply') |
282 call assert_equal('we did call you', g:Ch_reply) | |
283 endfunc | 281 endfunc |
284 | 282 |
285 func Test_channel_handler() | 283 func Test_channel_handler() |
286 call ch_log('Test_channel_handler()') | 284 call ch_log('Test_channel_handler()') |
287 let g:Ch_reply = "" | 285 let g:Ch_reply = "" |
320 " Check that eval works if a zero id message is sent back. | 318 " Check that eval works if a zero id message is sent back. |
321 let g:Ch_reply = '' | 319 let g:Ch_reply = '' |
322 call assert_equal('sent zero', ch_evalexpr(handle, 'send zero')) | 320 call assert_equal('sent zero', ch_evalexpr(handle, 'send zero')) |
323 if s:has_handler | 321 if s:has_handler |
324 call WaitFor('"zero index" == g:Ch_reply') | 322 call WaitFor('"zero index" == g:Ch_reply') |
325 call assert_equal('zero index', g:Ch_reply) | |
326 else | 323 else |
327 sleep 20m | 324 sleep 20m |
328 call assert_equal('', g:Ch_reply) | 325 call assert_equal('', g:Ch_reply) |
329 endif | 326 endif |
330 | 327 |
336 if s:has_handler | 333 if s:has_handler |
337 call assert_equal('zero index', g:Ch_reply) | 334 call assert_equal('zero index', g:Ch_reply) |
338 else | 335 else |
339 call assert_equal('', g:Ch_reply) | 336 call assert_equal('', g:Ch_reply) |
340 endif | 337 endif |
341 call assert_equal('sent zero', g:Ch_zero_reply) | |
342 endfunc | 338 endfunc |
343 | 339 |
344 func Test_zero_reply() | 340 func Test_zero_reply() |
345 call ch_log('Test_zero_reply()') | 341 call ch_log('Test_zero_reply()') |
346 " Run with channel handler | 342 " Run with channel handler |
1466 endif | 1462 endif |
1467 | 1463 |
1468 let g:exit_cb_val = {'start': reltime(), 'end': 0, 'process': 0} | 1464 let g:exit_cb_val = {'start': reltime(), 'end': 0, 'process': 0} |
1469 let job = job_start([s:python, '-c', 'import time;time.sleep(0.5)'], {'exit_cb': 'MyExitTimeCb'}) | 1465 let job = job_start([s:python, '-c', 'import time;time.sleep(0.5)'], {'exit_cb': 'MyExitTimeCb'}) |
1470 let g:exit_cb_val.process = job_info(job).process | 1466 let g:exit_cb_val.process = job_info(job).process |
1471 call WaitFor('type(g:exit_cb_val.end) != v:t_number || g:exit_cb_val.end != 0') | 1467 call WaitFor('type(g:exit_cb_val.end) != v:t_number || g:exit_cb_val.end != 0', 2000) |
1472 let elapsed = reltimefloat(g:exit_cb_val.end) | 1468 let elapsed = reltimefloat(g:exit_cb_val.end) |
1473 call assert_true(elapsed > 0.5) | 1469 call assert_true(elapsed > 0.5) |
1474 call assert_true(elapsed < 1.0) | 1470 call assert_true(elapsed < 1.0) |
1475 | 1471 |
1476 " case: unreferenced job, using timer | 1472 " case: unreferenced job, using timer |