Skip to content

Commit 3e1c617

Browse files
committed
patch 8.0.1245: when WaitFor() has a wrong expression it just waits a second
Problem: When WaitFor() has a wrong expression it just waits a second, which goes unnoticed. (James McCoy) Solution: When WaitFor() times out throw an exception. Fix places where the expression was wrong.
1 parent b94340c commit 3e1c617

5 files changed

Lines changed: 33 additions & 26 deletions

File tree

src/testdir/shared.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ func WaitFor(expr, ...)
139139
endif
140140
sleep 10m
141141
endfor
142-
return timeout
142+
throw 'WaitFor() timed out after ' . timeout . ' msec'
143143
endfunc
144144

145145
" Wait for up to a given milliseconds.

src/testdir/test_channel.vim

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ func Run_test_pipe_to_buffer(use_name, nomod, do_msg)
709709
call ch_sendraw(handle, "double this\n")
710710
call ch_sendraw(handle, "quit\n")
711711
sp pipe-output
712-
call WaitFor('line("$") >= 6 && g:Ch_bufClosed == "yes"')
712+
call WaitFor('line("$") == ' . len(expected) . ' && g:Ch_bufClosed == "yes"')
713713
call assert_equal(expected, getline(1, '$'))
714714
if a:nomod
715715
call assert_equal(0, &modifiable)
@@ -804,7 +804,7 @@ func Run_test_pipe_err_to_buffer(use_name, nomod, do_msg)
804804
call ch_sendraw(handle, "doubleerr this\n")
805805
call ch_sendraw(handle, "quit\n")
806806
sp pipe-err
807-
call WaitFor('line("$") >= 5')
807+
call WaitFor('line("$") == ' . len(expected))
808808
call assert_equal(expected, getline(1, '$'))
809809
if a:nomod
810810
call assert_equal(0, &modifiable)
@@ -1130,12 +1130,14 @@ func Test_pipe_to_buffer_raw()
11301130
let job = job_start([s:python, '-c',
11311131
\ 'import sys; [sys.stdout.write(".") and sys.stdout.flush() for _ in range(10000)]'], options)
11321132
call assert_equal("run", job_status(job))
1133-
call WaitFor('len(join(getline(2,line("$")),"") >= 10000')
1133+
call WaitFor('len(join(getline(1, "$"), "")) >= 10000', 3000)
11341134
try
1135-
for line in getline(2, '$')
1136-
let line = substitute(line, '^\.*', '', '')
1137-
call assert_equal('', line)
1135+
let totlen = 0
1136+
for line in getline(1, '$')
1137+
call assert_equal('', substitute(line, '^\.*', '', ''))
1138+
let totlen += len(line)
11381139
endfor
1140+
call assert_equal(10000, totlen)
11391141
finally
11401142
call job_stop(job)
11411143
bwipe!
@@ -1300,24 +1302,25 @@ func Test_close_and_exit_cb()
13001302
endif
13011303
call ch_log('Test_close_and_exit_cb')
13021304

1303-
let dict = {'ret': {}}
1304-
func dict.close_cb(ch) dict
1305+
let g:retdict = {'ret': {}}
1306+
func g:retdict.close_cb(ch) dict
13051307
let self.ret['close_cb'] = job_status(ch_getjob(a:ch))
13061308
endfunc
1307-
func dict.exit_cb(job, status) dict
1309+
func g:retdict.exit_cb(job, status) dict
13081310
let self.ret['exit_cb'] = job_status(a:job)
13091311
endfunc
13101312

13111313
let g:job = job_start('echo', {
1312-
\ 'close_cb': dict.close_cb,
1313-
\ 'exit_cb': dict.exit_cb,
1314+
\ 'close_cb': g:retdict.close_cb,
1315+
\ 'exit_cb': g:retdict.exit_cb,
13141316
\ })
13151317
call assert_equal('run', job_status(g:job))
13161318
unlet g:job
1317-
call WaitFor('len(dict.ret) >= 2')
1318-
call assert_equal(2, len(dict.ret))
1319-
call assert_match('^\%(dead\|run\)', dict.ret['close_cb'])
1320-
call assert_equal('dead', dict.ret['exit_cb'])
1319+
call WaitFor('len(g:retdict.ret) >= 2')
1320+
call assert_equal(2, len(g:retdict.ret))
1321+
call assert_match('^\%(dead\|run\)', g:retdict.ret['close_cb'])
1322+
call assert_equal('dead', g:retdict.ret['exit_cb'])
1323+
unlet g:retdict
13211324
endfunc
13221325

13231326
""""""""""
@@ -1547,13 +1550,14 @@ func Test_job_stop_immediately()
15471550
return
15481551
endif
15491552

1550-
let job = job_start([s:python, '-c', 'import time;time.sleep(10)'])
1553+
let g:job = job_start([s:python, '-c', 'import time;time.sleep(10)'])
15511554
try
1552-
call job_stop(job)
1553-
call WaitFor('"dead" == job_status(job)')
1554-
call assert_equal('dead', job_status(job))
1555+
call job_stop(g:job)
1556+
call WaitFor('"dead" == job_status(g:job)')
1557+
call assert_equal('dead', job_status(g:job))
15551558
finally
1556-
call job_stop(job, 'kill')
1559+
call job_stop(g:job, 'kill')
1560+
unlet g:job
15571561
endtry
15581562
endfunc
15591563

@@ -1585,7 +1589,7 @@ func Test_collapse_buffers()
15851589
split testout
15861590
1,$delete
15871591
call job_start('cat test_channel.vim', {'out_io': 'buffer', 'out_name': 'testout'})
1588-
call WaitFor('line("$") > g:linecount')
1592+
call WaitFor('line("$") >= g:linecount')
15891593
call assert_inrange(g:linecount, g:linecount + 1, line('$'))
15901594
bwipe!
15911595
endfunc

src/testdir/test_netbeans.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func Nb_basic(port)
2727

2828
" Opening README.txt will result in a setDot command
2929
call WaitFor('len(readfile("Xnetbeans")) > 4')
30-
call WaitFor('getcurpos()[1] == 2')
30+
call WaitFor('getcurpos()[1] == 3')
3131
let pos = getcurpos()
3232
call assert_equal(3, pos[1])
3333
call assert_equal(20, pos[2])

src/testdir/test_terminal.vim

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ func Test_terminal_composing_unicode()
705705

706706
enew
707707
let buf = term_start(cmd, {'curwin': bufnr('')})
708-
let job = term_getjob(buf)
708+
let g:job = term_getjob(buf)
709709
call term_wait(buf, 50)
710710

711711
" ascii + composing
@@ -742,8 +742,9 @@ func Test_terminal_composing_unicode()
742742
call assert_equal("\u00a0\u0308", l[3].chars)
743743

744744
call term_sendkeys(buf, "exit\r")
745-
call WaitFor('job_status(job) == "dead"')
746-
call assert_equal('dead', job_status(job))
745+
call WaitFor('job_status(g:job) == "dead"')
746+
call assert_equal('dead', job_status(g:job))
747747
bwipe!
748+
unlet g:job
748749
let &encoding = save_enc
749750
endfunc

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+
1245,
764766
/**/
765767
1244,
766768
/**/

0 commit comments

Comments
 (0)