Skip to content

Commit ab8b1c1

Browse files
committed
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.
1 parent 13deab8 commit ab8b1c1

7 files changed

Lines changed: 68 additions & 80 deletions

File tree

src/testdir/test_channel.vim

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,12 +274,10 @@ func Ch_channel_handler(port)
274274
" Test that it works while waiting on a numbered message.
275275
call assert_equal('ok', ch_evalexpr(handle, 'call me'))
276276
call WaitFor('"we called you" == g:Ch_reply')
277-
call assert_equal('we called you', g:Ch_reply)
278277

279278
" Test that it works while not waiting on a numbered message.
280279
call ch_sendexpr(handle, 'call me again')
281280
call WaitFor('"we did call you" == g:Ch_reply')
282-
call assert_equal('we did call you', g:Ch_reply)
283281
endfunc
284282

285283
func Test_channel_handler()
@@ -322,7 +320,6 @@ func Ch_channel_zero(port)
322320
call assert_equal('sent zero', ch_evalexpr(handle, 'send zero'))
323321
if s:has_handler
324322
call WaitFor('"zero index" == g:Ch_reply')
325-
call assert_equal('zero index', g:Ch_reply)
326323
else
327324
sleep 20m
328325
call assert_equal('', g:Ch_reply)
@@ -338,7 +335,6 @@ func Ch_channel_zero(port)
338335
else
339336
call assert_equal('', g:Ch_reply)
340337
endif
341-
call assert_equal('sent zero', g:Ch_zero_reply)
342338
endfunc
343339

344340
func Test_zero_reply()
@@ -1468,7 +1464,7 @@ func Test_exit_callback_interval()
14681464
let g:exit_cb_val = {'start': reltime(), 'end': 0, 'process': 0}
14691465
let job = job_start([s:python, '-c', 'import time;time.sleep(0.5)'], {'exit_cb': 'MyExitTimeCb'})
14701466
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)
14721468
let elapsed = reltimefloat(g:exit_cb_val.end)
14731469
call assert_true(elapsed > 0.5)
14741470
call assert_true(elapsed < 1.0)

src/testdir/test_clientserver.vim

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,8 @@ func Test_client_server()
2727

2828
let name = 'XVIMTEST'
2929
let cmd .= ' --servername ' . name
30-
let g:job = job_start(cmd, {'stoponexit': 'kill', 'out_io': 'null'})
31-
call WaitFor('job_status(g:job) == "run"')
32-
if job_status(g:job) != 'run'
33-
call assert_report('Cannot run the Vim server')
34-
return
35-
endif
30+
let job = job_start(cmd, {'stoponexit': 'kill', 'out_io': 'null'})
31+
call WaitFor({-> job_status(job) == "run"})
3632

3733
" Takes a short while for the server to be active.
3834
" When using valgrind it takes much longer.
@@ -83,7 +79,7 @@ func Test_client_server()
8379
call remote_send(name, ":call server2client(expand('<client>'), 'another')\<CR>", 'g:myserverid')
8480
let peek_result = 'nothing'
8581
let r = remote_peek(g:myserverid, 'peek_result')
86-
" unpredictable whether the result is already avaialble.
82+
" unpredictable whether the result is already available.
8783
if r > 0
8884
call assert_equal('another', peek_result)
8985
elseif r == 0
@@ -97,11 +93,14 @@ func Test_client_server()
9793
call assert_equal('another', remote_read(g:myserverid, 2))
9894

9995
call remote_send(name, ":qa!\<CR>")
100-
call WaitFor('job_status(g:job) == "dead"')
101-
if job_status(g:job) != 'dead'
102-
call assert_report('Server did not exit')
103-
call job_stop(g:job, 'kill')
104-
endif
96+
try
97+
call WaitFor({-> job_status(job) == "dead"})
98+
finally
99+
if job_status(job) != 'dead'
100+
call assert_report('Server did not exit')
101+
call job_stop(job, 'kill')
102+
endif
103+
endtry
105104
endfunc
106105

107106
" Uncomment this line to get a debugging log

src/testdir/test_job_fails.vim

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,11 @@ source shared.vim
66

77
func Test_job_start_fails()
88
if has('job')
9-
let g:job = job_start('axdfxsdf')
9+
let job = job_start('axdfxsdf')
1010
if has('unix')
11-
call WaitFor('job_status(g:job) == "dead"')
12-
call assert_equal('dead', job_status(g:job))
11+
call WaitFor({-> job_status(job) == "dead"})
1312
else
14-
call WaitFor('job_status(g:job) == "fail"')
15-
call assert_equal('fail', job_status(g:job))
13+
call WaitFor({-> job_status(job) == "fail"})
1614
endif
17-
unlet g:job
1815
endif
1916
endfunc

src/testdir/test_popup.vim

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -638,30 +638,30 @@ func Test_popup_and_window_resize()
638638
return
639639
endif
640640
let rows = h / 3
641-
let g:buf = term_start([GetVimProg(), '--clean', '-c', 'set noswapfile'], {'term_rows': rows})
642-
call term_sendkeys(g:buf, (h / 3 - 1) . "o\<esc>")
641+
let buf = term_start([GetVimProg(), '--clean', '-c', 'set noswapfile'], {'term_rows': rows})
642+
call term_sendkeys(buf, (h / 3 - 1) . "o\<esc>")
643643
" Wait for the nested Vim to exit insert mode, where it will show the ruler.
644644
" Need to trigger a redraw.
645-
call WaitFor(printf('execute("redraw") == "" && term_getline(g:buf, %d) =~ "\\<%d,.*Bot"', rows, rows))
645+
call WaitFor({-> execute("redraw") == "" && term_getline(buf, rows) =~ '\<' . rows . ',.*Bot'})
646646

647-
call term_sendkeys(g:buf, "Gi\<c-x>")
648-
call term_sendkeys(g:buf, "\<c-v>")
649-
call term_wait(g:buf, 100)
647+
call term_sendkeys(buf, "Gi\<c-x>")
648+
call term_sendkeys(buf, "\<c-v>")
649+
call term_wait(buf, 100)
650650
" popup first entry "!" must be at the top
651-
call WaitFor('term_getline(g:buf, 1) =~ "^!"')
652-
call assert_match('^!\s*$', term_getline(g:buf, 1))
651+
call WaitFor({-> term_getline(buf, 1) =~ "^!"})
652+
call assert_match('^!\s*$', term_getline(buf, 1))
653653
exe 'resize +' . (h - 1)
654-
call term_wait(g:buf, 100)
654+
call term_wait(buf, 100)
655655
redraw!
656656
" popup shifted down, first line is now empty
657-
call WaitFor('term_getline(g:buf, 1) == ""')
658-
call assert_equal('', term_getline(g:buf, 1))
657+
call WaitFor({-> term_getline(buf, 1) == ""})
658+
call assert_equal('', term_getline(buf, 1))
659659
sleep 100m
660660
" popup is below cursor line and shows first match "!"
661-
call WaitFor('term_getline(g:buf, term_getcursor(g:buf)[0] + 1) =~ "^!"')
662-
call assert_match('^!\s*$', term_getline(g:buf, term_getcursor(g:buf)[0] + 1))
661+
call WaitFor({-> term_getline(buf, term_getcursor(buf)[0] + 1) =~ "^!"})
662+
call assert_match('^!\s*$', term_getline(buf, term_getcursor(buf)[0] + 1))
663663
" cursor line also shows !
664-
call assert_match('^!\s*$', term_getline(g:buf, term_getcursor(g:buf)[0]))
664+
call assert_match('^!\s*$', term_getline(buf, term_getcursor(buf)[0]))
665665
bwipe!
666666
endfunc
667667

src/testdir/test_quotestar.vim

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,8 @@ func Do_test_quotestar_for_x11()
6060
call assert_notmatch(name, serverlist())
6161

6262
let cmd .= ' --servername ' . name
63-
let g:job = job_start(cmd, {'stoponexit': 'kill', 'out_io': 'null'})
64-
call WaitFor('job_status(g:job) == "run"')
65-
if job_status(g:job) != 'run'
66-
call assert_report('Cannot run the Vim server')
67-
return ''
68-
endif
63+
let job = job_start(cmd, {'stoponexit': 'kill', 'out_io': 'null'})
64+
call WaitFor({-> job_status(job) == "run"})
6965

7066
" Takes a short while for the server to be active.
7167
call WaitFor('serverlist() =~ "' . name . '"')
@@ -124,11 +120,14 @@ func Do_test_quotestar_for_x11()
124120
endif
125121

126122
call remote_send(name, ":qa!\<CR>")
127-
call WaitFor('job_status(g:job) == "dead"')
128-
if job_status(g:job) != 'dead'
129-
call assert_report('Server did not exit')
130-
call job_stop(g:job, 'kill')
131-
endif
123+
try
124+
call WaitFor({-> job_status(job) == "dead"})
125+
finally
126+
if job_status(job) != 'dead'
127+
call assert_report('Server did not exit')
128+
call job_stop(job, 'kill')
129+
endif
130+
endtry
132131

133132
return ''
134133
endfunc

src/testdir/test_terminal.vim

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -189,15 +189,14 @@ func Test_terminal_scrape_123()
189189
call term_wait(1234)
190190

191191
call term_wait(buf)
192-
let g:buf = buf
193192
" On MS-Windows we first get a startup message of two lines, wait for the
194193
" "cls" to happen, after that we have one line with three characters.
195-
call WaitFor('len(term_scrape(g:buf, 1)) == 3')
194+
call WaitFor({-> len(term_scrape(buf, 1)) == 3})
196195
call Check_123(buf)
197196

198197
" Must still work after the job ended.
199-
let g:job = term_getjob(buf)
200-
call WaitFor('job_status(g:job) == "dead"')
198+
let job = term_getjob(buf)
199+
call WaitFor({-> job_status(job) == "dead"})
201200
call term_wait(buf)
202201
call Check_123(buf)
203202

@@ -213,17 +212,17 @@ func Test_terminal_scrape_multibyte()
213212
if has('win32')
214213
" Run cmd with UTF-8 codepage to make the type command print the expected
215214
" multibyte characters.
216-
let g:buf = term_start("cmd /K chcp 65001")
217-
call term_sendkeys(g:buf, "type Xtext\<CR>")
218-
call term_sendkeys(g:buf, "exit\<CR>")
219-
let g:line = 4
215+
let buf = term_start("cmd /K chcp 65001")
216+
call term_sendkeys(buf, "type Xtext\<CR>")
217+
call term_sendkeys(buf, "exit\<CR>")
218+
let line = 4
220219
else
221-
let g:buf = term_start("cat Xtext")
222-
let g:line = 1
220+
let buf = term_start("cat Xtext")
221+
let line = 1
223222
endif
224223

225-
call WaitFor('len(term_scrape(g:buf, g:line)) >= 7 && term_scrape(g:buf, g:line)[0].chars == "l"')
226-
let l = term_scrape(g:buf, g:line)
224+
call WaitFor({-> len(term_scrape(buf, line)) >= 7 && term_scrape(buf, line)[0].chars == "l"})
225+
let l = term_scrape(buf, line)
227226
call assert_true(len(l) >= 7)
228227
call assert_equal('l', l[0].chars)
229228
call assert_equal('é', l[1].chars)
@@ -235,13 +234,11 @@ func Test_terminal_scrape_multibyte()
235234
call assert_equal('r', l[5].chars)
236235
call assert_equal('s', l[6].chars)
237236

238-
let g:job = term_getjob(g:buf)
239-
call WaitFor('job_status(g:job) == "dead"')
240-
call term_wait(g:buf)
237+
let job = term_getjob(buf)
238+
call WaitFor({-> job_status(job) == "dead"})
239+
call term_wait(buf)
241240

242-
exe g:buf . 'bwipe'
243-
unlet g:buf
244-
unlet g:line
241+
exe buf . 'bwipe'
245242
call delete('Xtext')
246243
endfunc
247244

@@ -254,8 +251,8 @@ func Test_terminal_scroll()
254251
endif
255252
let buf = term_start(cmd)
256253

257-
let g:job = term_getjob(buf)
258-
call WaitFor('job_status(g:job) == "dead"')
254+
let job = term_getjob(buf)
255+
call WaitFor({-> job_status(job) == "dead"})
259256
call term_wait(buf)
260257
if has('win32')
261258
" TODO: this should not be needed
@@ -483,7 +480,7 @@ func Test_terminal_list_args()
483480
endfunction
484481

485482
func Test_terminal_noblock()
486-
let g:buf = term_start(&shell)
483+
let buf = term_start(&shell)
487484
if has('mac')
488485
" The shell or something else has a problem dealing with more than 1000
489486
" characters at the same time.
@@ -493,26 +490,24 @@ func Test_terminal_noblock()
493490
endif
494491

495492
for c in ['a','b','c','d','e','f','g','h','i','j','k']
496-
call term_sendkeys(g:buf, 'echo ' . repeat(c, len) . "\<cr>")
493+
call term_sendkeys(buf, 'echo ' . repeat(c, len) . "\<cr>")
497494
endfor
498-
call term_sendkeys(g:buf, "echo done\<cr>")
495+
call term_sendkeys(buf, "echo done\<cr>")
499496

500497
" On MS-Windows there is an extra empty line below "done". Find "done" in
501498
" the last-but-one or the last-but-two line.
502-
let g:lnum = term_getsize(g:buf)[0] - 1
503-
call WaitFor('term_getline(g:buf, g:lnum) =~ "done" || term_getline(g:buf, g:lnum - 1) =~ "done"', 3000)
504-
let line = term_getline(g:buf, g:lnum)
499+
let lnum = term_getsize(buf)[0] - 1
500+
call WaitFor({-> term_getline(buf, lnum) =~ "done" || term_getline(buf, lnum - 1) =~ "done"}, 3000)
501+
let line = term_getline(buf, lnum)
505502
if line !~ 'done'
506-
let line = term_getline(g:buf, g:lnum - 1)
503+
let line = term_getline(buf, lnum - 1)
507504
endif
508505
call assert_match('done', line)
509506

510-
let g:job = term_getjob(g:buf)
511-
call Stop_shell_in_terminal(g:buf)
512-
call term_wait(g:buf)
513-
unlet g:buf
507+
let g:job = term_getjob(buf)
508+
call Stop_shell_in_terminal(buf)
509+
call term_wait(buf)
514510
unlet g:job
515-
unlet g:lnum
516511
bwipe
517512
endfunc
518513

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,8 @@ static char *(features[]) =
761761

762762
static int included_patches[] =
763763
{ /* Add new patch number below this line */
764+
/**/
765+
1260,
764766
/**/
765767
1259,
766768
/**/

0 commit comments

Comments
 (0)