1
0
forked from aniani/vim

patch 8.0.1771: in tests, when WaitFor() fails it doesn't say why

Problem:    In tests, when WaitFor() fails it doesn't say why. (James McCoy)
Solution:   Add WaitForAssert(), which produces an assert error when it fails.
This commit is contained in:
Bram Moolenaar
2018-04-28 21:34:40 +02:00
parent 65a5464985
commit 50182fa84e
8 changed files with 130 additions and 120 deletions

View File

@@ -64,9 +64,15 @@ func RunVimInTerminal(arguments, options)
let cols = term_getsize(buf)[1] let cols = term_getsize(buf)[1]
endif endif
" Wait for "All" of the ruler in the status line to be shown. " Wait for "All" or "Top" of the ruler in the status line to be shown. This
" This can be quite slow (e.g. when using valgrind). " can be quite slow (e.g. when using valgrind).
call WaitFor({-> len(term_getline(buf, rows)) >= cols - 1}) " If it fails then show the terminal contents for debugging.
try
call WaitFor({-> len(term_getline(buf, rows)) >= cols - 1})
catch /timed out after/
let lines = map(range(1, rows), {key, val -> term_getline(buf, val)})
call assert_report('RunVimInTerminal() failed, screen contents: ' . join(lines, "<NL>"))
endtry
return buf return buf
endfunc endfunc
@@ -75,7 +81,7 @@ endfunc
func StopVimInTerminal(buf) func StopVimInTerminal(buf)
call assert_equal("running", term_getstatus(a:buf)) call assert_equal("running", term_getstatus(a:buf))
call term_sendkeys(a:buf, "\<Esc>\<Esc>:qa!\<cr>") call term_sendkeys(a:buf, "\<Esc>\<Esc>:qa!\<cr>")
call WaitFor('term_getstatus(' . a:buf . ') == "finished"') call WaitForAssert({-> assert_equal("finished", term_getstatus(a:buf))})
only! only!
endfunc endfunc

View File

@@ -115,38 +115,80 @@ endfunc
" Wait for up to five seconds for "expr" to become true. "expr" can be a " Wait for up to five seconds for "expr" to become true. "expr" can be a
" stringified expression to evaluate, or a funcref without arguments. " stringified expression to evaluate, or a funcref without arguments.
" Using a lambda works best. Example:
" call WaitFor({-> status == "ok"})
"
" A second argument can be used to specify a different timeout in msec. " A second argument can be used to specify a different timeout in msec.
" "
" Return time slept in milliseconds. With the +reltime feature this can be " When successful the time slept is returned.
" more than the actual waiting time. Without +reltime it can also be less. " When running into the timeout an exception is thrown, thus the function does
" not return.
func WaitFor(expr, ...) func WaitFor(expr, ...)
let timeout = get(a:000, 0, 5000) let timeout = get(a:000, 0, 5000)
let slept = s:WaitForCommon(a:expr, v:null, timeout)
if slept < 0
throw 'WaitFor() timed out after ' . timeout . ' msec'
endif
return slept
endfunc
" Wait for up to five seconds for "assert" to return zero. "assert" must be a
" (lambda) function containing one assert function. Example:
" call WaitForAssert({-> assert_equal("dead", job_status(job)})
"
" A second argument can be used to specify a different timeout in msec.
"
" Return zero for success, one for failure (like the assert function).
func WaitForAssert(assert, ...)
let timeout = get(a:000, 0, 5000)
if s:WaitForCommon(v:null, a:assert, timeout) < 0
return 1
endif
return 0
endfunc
" Common implementation of WaitFor() and WaitForAssert().
" Either "expr" or "assert" is not v:null
" Return the waiting time for success, -1 for failure.
func s:WaitForCommon(expr, assert, timeout)
" using reltime() is more accurate, but not always available " using reltime() is more accurate, but not always available
let slept = 0
if has('reltime') if has('reltime')
let start = reltime() let start = reltime()
else
let slept = 0
endif endif
if type(a:expr) == v:t_func
let Test = a:expr while 1
else if type(a:expr) == v:t_func
let Test = {-> eval(a:expr) } let success = a:expr()
endif elseif type(a:assert) == v:t_func
for i in range(timeout / 10) let success = a:assert() == 0
if Test() else
if has('reltime') let success = eval(a:expr)
return float2nr(reltimefloat(reltime(start)) * 1000) endif
endif if success
return slept return slept
endif endif
if !has('reltime')
if slept >= a:timeout
break
endif
if type(a:assert) == v:t_func
" Remove the error added by the assert function.
call remove(v:errors, -1)
endif
sleep 10m
if has('reltime')
let slept = float2nr(reltimefloat(reltime(start)) * 1000)
else
let slept += 10 let slept += 10
endif endif
sleep 10m endwhile
endfor
throw 'WaitFor() timed out after ' . timeout . ' msec' return -1 " timed out
endfunc endfunc
" Wait for up to a given milliseconds. " Wait for up to a given milliseconds.
" With the +timers feature this waits for key-input by getchar(), Resume() " With the +timers feature this waits for key-input by getchar(), Resume()
" feeds key-input and resumes process. Return time waited in milliseconds. " feeds key-input and resumes process. Return time waited in milliseconds.

View File

@@ -1322,11 +1322,11 @@ func Test_Changed_FirstTime()
let buf = term_start([GetVimProg(), '--clean', '-c', 'set noswapfile'], {'term_rows': 3}) let buf = term_start([GetVimProg(), '--clean', '-c', 'set noswapfile'], {'term_rows': 3})
call assert_equal('running', term_getstatus(buf)) call assert_equal('running', term_getstatus(buf))
" Wait for the ruler (in the status line) to be shown. " Wait for the ruler (in the status line) to be shown.
call WaitFor({-> term_getline(buf, 3) =~# '\<All$'}) call WaitForAssert({-> assert_match('\<All$', term_getline(buf, 3))})
" It's only adding autocmd, so that no event occurs. " It's only adding autocmd, so that no event occurs.
call term_sendkeys(buf, ":au! TextChanged <buffer> call writefile(['No'], 'Xchanged.txt')\<cr>") call term_sendkeys(buf, ":au! TextChanged <buffer> call writefile(['No'], 'Xchanged.txt')\<cr>")
call term_sendkeys(buf, "\<C-\\>\<C-N>:qa!\<cr>") call term_sendkeys(buf, "\<C-\\>\<C-N>:qa!\<cr>")
call WaitFor({-> term_getstatus(buf) == 'finished'}) call WaitForAssert({-> assert_equal('finished', term_getstatus(buf))})
call assert_equal([''], readfile('Xchanged.txt')) call assert_equal([''], readfile('Xchanged.txt'))
" clean up " clean up

View File

@@ -95,18 +95,15 @@ func Ch_communicate(port)
" handled before getting the response, but it's not guaranteed, thus wait a " handled before getting the response, but it's not guaranteed, thus wait a
" tiny bit for the commands to get executed. " tiny bit for the commands to get executed.
call assert_equal('ok', ch_evalexpr(handle, 'make change')) call assert_equal('ok', ch_evalexpr(handle, 'make change'))
call WaitFor('"added2" == getline("$")') call WaitForAssert({-> assert_equal("added2", getline("$"))})
call assert_equal('added1', getline(line('$') - 1)) call assert_equal('added1', getline(line('$') - 1))
call assert_equal('added2', getline('$'))
" Request command "foo bar", which fails silently. " Request command "foo bar", which fails silently.
call assert_equal('ok', ch_evalexpr(handle, 'bad command')) call assert_equal('ok', ch_evalexpr(handle, 'bad command'))
call WaitFor('v:errmsg =~ "E492"') call WaitForAssert({-> assert_match("E492:.*foo bar", v:errmsg)})
call assert_match('E492:.*foo bar', v:errmsg)
call assert_equal('ok', ch_evalexpr(handle, 'do normal', {'timeout': 100})) call assert_equal('ok', ch_evalexpr(handle, 'do normal', {'timeout': 100}))
call WaitFor('"added more" == getline("$")') call WaitForAssert({-> assert_equal('added more', getline('$'))})
call assert_equal('added more', getline('$'))
" Send a request with a specific handler. " Send a request with a specific handler.
call ch_sendexpr(handle, 'hello!', {'callback': 'Ch_requestHandler'}) call ch_sendexpr(handle, 'hello!', {'callback': 'Ch_requestHandler'})
@@ -188,10 +185,9 @@ func Ch_communicate(port)
" Send an expr request " Send an expr request
call assert_equal('ok', ch_evalexpr(handle, 'an expr')) call assert_equal('ok', ch_evalexpr(handle, 'an expr'))
call WaitFor('"three" == getline("$")') call WaitForAssert({-> assert_equal('three', getline('$'))})
call assert_equal('one', getline(line('$') - 2)) call assert_equal('one', getline(line('$') - 2))
call assert_equal('two', getline(line('$') - 1)) call assert_equal('two', getline(line('$') - 1))
call assert_equal('three', getline('$'))
" Request a redraw, we don't check for the effect. " Request a redraw, we don't check for the effect.
call assert_equal('ok', ch_evalexpr(handle, 'redraw')) call assert_equal('ok', ch_evalexpr(handle, 'redraw'))
@@ -288,11 +284,11 @@ func Ch_channel_handler(port)
" Test that it works while waiting on a numbered message. " Test that it works while waiting on a numbered message.
call assert_equal('ok', ch_evalexpr(handle, 'call me')) call assert_equal('ok', ch_evalexpr(handle, 'call me'))
call WaitFor('"we called you" == g:Ch_reply') call WaitForAssert({-> assert_equal('we called you', g:Ch_reply)})
" Test that it works while not waiting on a numbered message. " Test that it works while not waiting on a numbered message.
call ch_sendexpr(handle, 'call me again') call ch_sendexpr(handle, 'call me again')
call WaitFor('"we did call you" == g:Ch_reply') call WaitForAssert({-> assert_equal('we did call you', g:Ch_reply)})
endfunc endfunc
func Test_channel_handler() func Test_channel_handler()
@@ -334,7 +330,7 @@ func Ch_channel_zero(port)
let g:Ch_reply = '' let g:Ch_reply = ''
call assert_equal('sent zero', ch_evalexpr(handle, 'send zero')) call assert_equal('sent zero', ch_evalexpr(handle, 'send zero'))
if s:has_handler if s:has_handler
call WaitFor('"zero index" == g:Ch_reply') call WaitForAssert({-> assert_equal('zero index', g:Ch_reply)})
else else
sleep 20m sleep 20m
call assert_equal('', g:Ch_reply) call assert_equal('', g:Ch_reply)
@@ -344,7 +340,7 @@ func Ch_channel_zero(port)
let g:Ch_reply = '' let g:Ch_reply = ''
let g:Ch_zero_reply = '' let g:Ch_zero_reply = ''
call ch_sendexpr(handle, 'send zero', {'callback': 'Ch_oneHandler'}) call ch_sendexpr(handle, 'send zero', {'callback': 'Ch_oneHandler'})
call WaitFor('"sent zero" == g:Ch_zero_reply') call WaitForAssert({-> assert_equal('sent zero', g:Ch_zero_reply)})
if s:has_handler if s:has_handler
call assert_equal('zero index', g:Ch_reply) call assert_equal('zero index', g:Ch_reply)
else else
@@ -395,15 +391,12 @@ func Ch_raw_one_time_callback(port)
" The messages are sent raw, we do our own JSON strings here. " The messages are sent raw, we do our own JSON strings here.
call ch_sendraw(handle, "[1, \"hello!\"]\n", {'callback': 'Ch_handleRaw1'}) call ch_sendraw(handle, "[1, \"hello!\"]\n", {'callback': 'Ch_handleRaw1'})
call WaitFor('g:Ch_reply1 != ""') call WaitForAssert({-> assert_equal("[1, \"got it\"]", g:Ch_reply1)})
call assert_equal("[1, \"got it\"]", g:Ch_reply1)
call ch_sendraw(handle, "[2, \"echo something\"]\n", {'callback': 'Ch_handleRaw2'}) call ch_sendraw(handle, "[2, \"echo something\"]\n", {'callback': 'Ch_handleRaw2'})
call ch_sendraw(handle, "[3, \"wait a bit\"]\n", {'callback': 'Ch_handleRaw3'}) call ch_sendraw(handle, "[3, \"wait a bit\"]\n", {'callback': 'Ch_handleRaw3'})
call WaitFor('g:Ch_reply2 != ""') call WaitForAssert({-> assert_equal("[2, \"something\"]", g:Ch_reply2)})
call assert_equal("[2, \"something\"]", g:Ch_reply2)
" wait for the 200 msec delayed reply " wait for the 200 msec delayed reply
call WaitFor('g:Ch_reply3 != ""') call WaitForAssert({-> assert_equal("[3, \"waited\"]", g:Ch_reply3)})
call assert_equal("[3, \"waited\"]", g:Ch_reply3)
endfunc endfunc
func Test_raw_one_time_callback() func Test_raw_one_time_callback()
@@ -494,8 +487,7 @@ func Test_raw_pipe()
let g:Ch_reply = "" let g:Ch_reply = ""
call ch_sendraw(job, "double this\n", {'callback': 'Ch_handler'}) call ch_sendraw(job, "double this\n", {'callback': 'Ch_handler'})
call WaitFor('"" != g:Ch_reply') call WaitForAssert({-> assert_equal("this\nAND this\n", substitute(g:Ch_reply, "\r", "", 'g'))})
call assert_equal("this\nAND this\n", substitute(g:Ch_reply, "\r", "", 'g'))
let reply = ch_evalraw(job, "quit\n", {'timeout': 100}) let reply = ch_evalraw(job, "quit\n", {'timeout': 100})
call assert_equal("Goodbye!\n", substitute(reply, "\r", "", 'g')) call assert_equal("Goodbye!\n", substitute(reply, "\r", "", 'g'))
@@ -504,7 +496,7 @@ func Test_raw_pipe()
endtry endtry
let g:Ch_job = job let g:Ch_job = job
call WaitFor('"dead" == job_status(g:Ch_job)') call WaitForAssert({-> assert_equal("dead", job_status(g:Ch_job))})
let info = job_info(job) let info = job_info(job)
call assert_equal("dead", info.status) call assert_equal("dead", info.status)
call assert_equal("term", info.stoponexit) call assert_equal("term", info.stoponexit)
@@ -602,7 +594,7 @@ func Stop_g_job()
if has('win32') if has('win32')
" On MS-Windows the server must close the file handle before we are able " On MS-Windows the server must close the file handle before we are able
" to delete the file. " to delete the file.
call WaitFor('job_status(g:job) == "dead"') call WaitForAssert({-> assert_equal('dead', job_status(g:job))})
sleep 10m sleep 10m
endif endif
endfunc endfunc
@@ -641,8 +633,7 @@ func Test_nl_write_out_file()
call ch_sendraw(handle, "echo line one\n") call ch_sendraw(handle, "echo line one\n")
call ch_sendraw(handle, "echo line two\n") call ch_sendraw(handle, "echo line two\n")
call ch_sendraw(handle, "double this\n") call ch_sendraw(handle, "double this\n")
call WaitFor('len(readfile("Xoutput")) > 2') call WaitForAssert({-> assert_equal(['line one', 'line two', 'this', 'AND this'], readfile('Xoutput'))})
call assert_equal(['line one', 'line two', 'this', 'AND this'], readfile('Xoutput'))
finally finally
call Stop_g_job() call Stop_g_job()
call assert_equal(-1, match(s:get_resources(), '\(^\|/\)Xoutput$')) call assert_equal(-1, match(s:get_resources(), '\(^\|/\)Xoutput$'))
@@ -663,8 +654,7 @@ func Test_nl_write_err_file()
call ch_sendraw(handle, "echoerr line one\n") call ch_sendraw(handle, "echoerr line one\n")
call ch_sendraw(handle, "echoerr line two\n") call ch_sendraw(handle, "echoerr line two\n")
call ch_sendraw(handle, "doubleerr this\n") call ch_sendraw(handle, "doubleerr this\n")
call WaitFor('len(readfile("Xoutput")) > 2') call WaitForAssert({-> assert_equal(['line one', 'line two', 'this', 'AND this'], readfile('Xoutput'))})
call assert_equal(['line one', 'line two', 'this', 'AND this'], readfile('Xoutput'))
finally finally
call Stop_g_job() call Stop_g_job()
call delete('Xoutput') call delete('Xoutput')
@@ -685,8 +675,7 @@ func Test_nl_write_both_file()
call ch_sendraw(handle, "echo line two\n") call ch_sendraw(handle, "echo line two\n")
call ch_sendraw(handle, "double this\n") call ch_sendraw(handle, "double this\n")
call ch_sendraw(handle, "doubleerr that\n") call ch_sendraw(handle, "doubleerr that\n")
call WaitFor('len(readfile("Xoutput")) > 5') call WaitForAssert({-> assert_equal(['line one', 'line two', 'this', 'AND this', 'that', 'AND that'], readfile('Xoutput'))})
call assert_equal(['line one', 'line two', 'this', 'AND this', 'that', 'AND that'], readfile('Xoutput'))
finally finally
call Stop_g_job() call Stop_g_job()
call assert_equal(-1, match(s:get_resources(), '\(^\|/\)Xoutput$')) call assert_equal(-1, match(s:get_resources(), '\(^\|/\)Xoutput$'))
@@ -777,8 +766,7 @@ func Test_close_output_buffer()
let job = job_start(s:python . " test_channel_write.py", options) let job = job_start(s:python . " test_channel_write.py", options)
call assert_equal("run", job_status(job)) call assert_equal("run", job_status(job))
try try
call WaitFor('line("$") == 3') call WaitForAssert({-> assert_equal(3, line('$'))})
call assert_equal(3, line('$'))
quit! quit!
sleep 100m sleep 100m
" Make sure the write didn't happen to the wrong buffer. " Make sure the write didn't happen to the wrong buffer.
@@ -827,8 +815,7 @@ func Run_test_pipe_err_to_buffer(use_name, nomod, do_msg)
call ch_sendraw(handle, "doubleerr this\n") call ch_sendraw(handle, "doubleerr this\n")
call ch_sendraw(handle, "quit\n") call ch_sendraw(handle, "quit\n")
sp pipe-err sp pipe-err
call WaitFor('line("$") == ' . len(expected)) call WaitForAssert({-> assert_equal(expected, getline(1, '$'))})
call assert_equal(expected, getline(1, '$'))
if a:nomod if a:nomod
call assert_equal(0, &modifiable) call assert_equal(0, &modifiable)
else else
@@ -872,8 +859,7 @@ func Test_pipe_both_to_buffer()
call ch_sendraw(handle, "doubleerr that\n") call ch_sendraw(handle, "doubleerr that\n")
call ch_sendraw(handle, "quit\n") call ch_sendraw(handle, "quit\n")
sp pipe-err sp pipe-err
call WaitFor('line("$") >= 7') call WaitForAssert({-> assert_equal(['Reading from channel output...', 'line one', 'line two', 'this', 'AND this', 'that', 'AND that', 'Goodbye!'], getline(1, '$'))})
call assert_equal(['Reading from channel output...', 'line one', 'line two', 'this', 'AND this', 'that', 'AND that', 'Goodbye!'], getline(1, '$'))
bwipe! bwipe!
finally finally
call job_stop(job) call job_stop(job)
@@ -939,8 +925,7 @@ func Run_pipe_through_sort(all, use_buffer)
call ch_close_in(g:job) call ch_close_in(g:job)
endif endif
call WaitFor('job_status(g:job) == "dead"') call WaitForAssert({-> assert_equal("dead", job_status(g:job))})
call assert_equal("dead", job_status(g:job))
sp sortout sp sortout
call WaitFor('line("$") > 3') call WaitFor('line("$") > 3')
@@ -1222,16 +1207,14 @@ func Test_out_cb()
let g:Ch_errmsg = '' let g:Ch_errmsg = ''
call ch_sendraw(job, "echo [0, \"hello\"]\n") call ch_sendraw(job, "echo [0, \"hello\"]\n")
call ch_sendraw(job, "echoerr [0, \"there\"]\n") call ch_sendraw(job, "echoerr [0, \"there\"]\n")
call WaitFor('g:Ch_outmsg != ""') call WaitForAssert({-> assert_equal("dict: hello", g:Ch_outmsg)})
call assert_equal("dict: hello", g:Ch_outmsg) call WaitForAssert({-> assert_equal("dict: there", g:Ch_errmsg)})
call WaitFor('g:Ch_errmsg != ""')
call assert_equal("dict: there", g:Ch_errmsg)
" Receive a json object split in pieces " Receive a json object split in pieces
unlet! g:Ch_outobj unlet! g:Ch_outobj
call ch_sendraw(job, "echosplit [0, {\"one\": 1,| \"tw|o\": 2, \"three\": 3|}]\n") call ch_sendraw(job, "echosplit [0, {\"one\": 1,| \"tw|o\": 2, \"three\": 3|}]\n")
call WaitFor('exists("g:Ch_outobj")') let g:Ch_outobj = ''
call assert_equal({'one': 1, 'two': 2, 'three': 3}, g:Ch_outobj) call WaitForAssert({-> assert_equal({'one': 1, 'two': 2, 'three': 3}, g:Ch_outobj)})
finally finally
call job_stop(job) call job_stop(job)
endtry endtry
@@ -1261,9 +1244,8 @@ func Test_out_close_cb()
\ 'close_cb': 'CloseHandler'}) \ 'close_cb': 'CloseHandler'})
call assert_equal("run", job_status(job)) call assert_equal("run", job_status(job))
try try
call WaitFor('g:Ch_closemsg != 0 && g:Ch_msg1 != ""') call WaitForAssert({-> assert_equal('quit', g:Ch_msg1)})
call assert_equal('quit', g:Ch_msg1) call WaitForAssert({-> assert_equal(2, g:Ch_closemsg)})
call assert_equal(2, g:Ch_closemsg)
finally finally
call job_stop(job) call job_stop(job)
delfunc OutHandler delfunc OutHandler
@@ -1285,8 +1267,7 @@ func Test_read_in_close_cb()
\ {'close_cb': 'CloseHandler'}) \ {'close_cb': 'CloseHandler'})
call assert_equal("run", job_status(job)) call assert_equal("run", job_status(job))
try try
call WaitFor('g:Ch_received != ""') call WaitForAssert({-> assert_equal('quit', g:Ch_received)})
call assert_equal('quit', g:Ch_received)
finally finally
call job_stop(job) call job_stop(job)
delfunc CloseHandler delfunc CloseHandler
@@ -1310,8 +1291,7 @@ func Test_read_in_close_cb_incomplete()
\ {'close_cb': 'CloseHandler'}) \ {'close_cb': 'CloseHandler'})
call assert_equal("run", job_status(job)) call assert_equal("run", job_status(job))
try try
call WaitFor('g:Ch_received != ""') call WaitForAssert({-> assert_equal('incomplete', g:Ch_received)})
call assert_equal('incomplete', g:Ch_received)
finally finally
call job_stop(job) call job_stop(job)
delfunc CloseHandler delfunc CloseHandler
@@ -1335,10 +1315,8 @@ func Test_out_cb_lambda()
let g:Ch_errmsg = '' let g:Ch_errmsg = ''
call ch_sendraw(job, "echo [0, \"hello\"]\n") call ch_sendraw(job, "echo [0, \"hello\"]\n")
call ch_sendraw(job, "echoerr [0, \"there\"]\n") call ch_sendraw(job, "echoerr [0, \"there\"]\n")
call WaitFor('g:Ch_outmsg != ""') call WaitForAssert({-> assert_equal("lambda: hello", g:Ch_outmsg)})
call assert_equal("lambda: hello", g:Ch_outmsg) call WaitForAssert({-> assert_equal("lambda: there", g:Ch_errmsg)})
call WaitFor('g:Ch_errmsg != ""')
call assert_equal("lambda: there", g:Ch_errmsg)
finally finally
call job_stop(job) call job_stop(job)
endtry endtry
@@ -1364,8 +1342,7 @@ func Test_close_and_exit_cb()
\ }) \ })
call assert_equal('run', job_status(g:job)) call assert_equal('run', job_status(g:job))
unlet g:job unlet g:job
call WaitFor('len(g:retdict.ret) >= 2') call WaitForAssert({-> assert_equal(2, len(g:retdict.ret))})
call assert_equal(2, len(g:retdict.ret))
call assert_match('^\%(dead\|run\)', g:retdict.ret['close_cb']) call assert_match('^\%(dead\|run\)', g:retdict.ret['close_cb'])
call assert_equal('dead', g:retdict.ret['exit_cb']) call assert_equal('dead', g:retdict.ret['exit_cb'])
unlet g:retdict unlet g:retdict
@@ -1383,8 +1360,7 @@ endfunc
func Ch_unlet_handle(port) func Ch_unlet_handle(port)
let s:channelfd = ch_open('localhost:' . a:port, s:chopt) let s:channelfd = ch_open('localhost:' . a:port, s:chopt)
call ch_sendexpr(s:channelfd, "test", {'callback': function('s:UnletHandler')}) call ch_sendexpr(s:channelfd, "test", {'callback': function('s:UnletHandler')})
call WaitFor('"what?" == g:Ch_unletResponse') call WaitForAssert({-> assert_equal('what?', g:Ch_unletResponse)})
call assert_equal('what?', g:Ch_unletResponse)
endfunc endfunc
func Test_unlet_handle() func Test_unlet_handle()
@@ -1404,8 +1380,7 @@ endfunc
func Ch_close_handle(port) func Ch_close_handle(port)
let s:channelfd = ch_open('localhost:' . a:port, s:chopt) let s:channelfd = ch_open('localhost:' . a:port, s:chopt)
call ch_sendexpr(s:channelfd, "test", {'callback': function('Ch_CloseHandler')}) call ch_sendexpr(s:channelfd, "test", {'callback': function('Ch_CloseHandler')})
call WaitFor('"what?" == g:Ch_unletResponse') call WaitForAssert({-> assert_equal('what?', g:Ch_unletResponse)})
call assert_equal('what?', g:Ch_unletResponse)
endfunc endfunc
func Test_close_handle() func Test_close_handle()
@@ -1458,8 +1433,7 @@ function Ch_test_call(port)
let g:Ch_call_ret = [] let g:Ch_call_ret = []
call assert_equal('ok', ch_evalexpr(handle, 'call-func')) call assert_equal('ok', ch_evalexpr(handle, 'call-func'))
call WaitFor('len(g:Ch_call_ret) > 0') call WaitForAssert({-> assert_equal([1, 2, 3], g:Ch_call_ret)})
call assert_equal([1, 2, 3], g:Ch_call_ret)
endfunc endfunc
func Test_call() func Test_call()
@@ -1556,8 +1530,7 @@ function Ch_test_close_callback(port)
call ch_setoptions(handle, {'close_cb': 'MyCloseCb'}) call ch_setoptions(handle, {'close_cb': 'MyCloseCb'})
call assert_equal('', ch_evalexpr(handle, 'close me')) call assert_equal('', ch_evalexpr(handle, 'close me'))
call WaitFor('"closed" == g:Ch_close_ret') call WaitForAssert({-> assert_equal('closed', g:Ch_close_ret)})
call assert_equal('closed', g:Ch_close_ret)
endfunc endfunc
func Test_close_callback() func Test_close_callback()
@@ -1578,8 +1551,7 @@ function Ch_test_close_partial(port)
call ch_setoptions(handle, {'close_cb': g:Ch_d.closeCb}) call ch_setoptions(handle, {'close_cb': g:Ch_d.closeCb})
call assert_equal('', ch_evalexpr(handle, 'close me')) call assert_equal('', ch_evalexpr(handle, 'close me'))
call WaitFor('"closed" == g:Ch_d.close_ret') call WaitForAssert({-> assert_equal('closed', g:Ch_d.close_ret)})
call assert_equal('closed', g:Ch_d.close_ret)
unlet g:Ch_d unlet g:Ch_d
endfunc endfunc
@@ -1601,8 +1573,7 @@ func Test_job_stop_immediately()
let g:job = job_start([s:python, '-c', 'import time;time.sleep(10)']) let g:job = job_start([s:python, '-c', 'import time;time.sleep(10)'])
try try
call job_stop(g:job) call job_stop(g:job)
call WaitFor('"dead" == job_status(g:job)') call WaitForAssert({-> assert_equal('dead', job_status(g:job))})
call assert_equal('dead', job_status(g:job))
finally finally
call job_stop(g:job, 'kill') call job_stop(g:job, 'kill')
unlet g:job unlet g:job
@@ -1637,8 +1608,7 @@ func Test_collapse_buffers()
split testout split testout
1,$delete 1,$delete
call job_start('cat test_channel.vim', {'out_io': 'buffer', 'out_name': 'testout'}) call job_start('cat test_channel.vim', {'out_io': 'buffer', 'out_name': 'testout'})
call WaitFor('line("$") >= g:linecount') call WaitForAssert({-> assert_inrange(g:linecount, g:linecount + 1, line('$'))})
call assert_inrange(g:linecount, g:linecount + 1, line('$'))
bwipe! bwipe!
endfunc endfunc
@@ -1648,13 +1618,11 @@ func Test_cmd_parsing()
endif endif
call assert_false(filereadable("file with space")) call assert_false(filereadable("file with space"))
let job = job_start('touch "file with space"') let job = job_start('touch "file with space"')
call WaitFor('filereadable("file with space")') call WaitForAssert({-> assert_true(filereadable("file with space"))})
call assert_true(filereadable("file with space"))
call delete("file with space") call delete("file with space")
let job = job_start('touch file\ with\ space') let job = job_start('touch file\ with\ space')
call WaitFor('filereadable("file with space")') call WaitForAssert({-> assert_true(filereadable("file with space"))})
call assert_true(filereadable("file with space"))
call delete("file with space") call delete("file with space")
endfunc endfunc
@@ -1683,7 +1651,7 @@ func Test_raw_passes_nul()
new mybuffer new mybuffer
call setline(1, ["asdf\nasdf", "xxx\n", "\nyyy"]) call setline(1, ["asdf\nasdf", "xxx\n", "\nyyy"])
let g:Ch_job = job_start('cat', {'in_io': 'buffer', 'in_name': 'mybuffer', 'out_io': 'file', 'out_name': 'Xtestwrite'}) let g:Ch_job = job_start('cat', {'in_io': 'buffer', 'in_name': 'mybuffer', 'out_io': 'file', 'out_name': 'Xtestwrite'})
call WaitFor('"dead" == job_status(g:Ch_job)') call WaitForAssert({-> assert_equal("dead", job_status(g:Ch_job))})
bwipe! bwipe!
split Xtestwrite split Xtestwrite
call assert_equal("asdf\nasdf", getline(1)) call assert_equal("asdf\nasdf", getline(1))
@@ -1707,8 +1675,7 @@ func Test_read_nonl_line()
let g:linecount = 0 let g:linecount = 0
let arg = 'import sys;sys.stdout.write("1\n2\n3")' let arg = 'import sys;sys.stdout.write("1\n2\n3")'
call job_start([s:python, '-c', arg], {'callback': 'MyLineCountCb'}) call job_start([s:python, '-c', arg], {'callback': 'MyLineCountCb'})
call WaitFor('3 <= g:linecount') call WaitForAssert({-> assert_equal(3, g:linecount)})
call assert_equal(3, g:linecount)
endfunc endfunc
func Test_read_from_terminated_job() func Test_read_from_terminated_job()
@@ -1719,8 +1686,7 @@ func Test_read_from_terminated_job()
let g:linecount = 0 let g:linecount = 0
let arg = 'import os,sys;os.close(1);sys.stderr.write("test\n")' let arg = 'import os,sys;os.close(1);sys.stderr.write("test\n")'
call job_start([s:python, '-c', arg], {'callback': 'MyLineCountCb'}) call job_start([s:python, '-c', arg], {'callback': 'MyLineCountCb'})
call WaitFor('1 <= g:linecount') call WaitForAssert({-> assert_equal(1, g:linecount)})
call assert_equal(1, g:linecount)
endfunc endfunc
func Test_env() func Test_env()
@@ -1736,8 +1702,7 @@ func Test_env()
endif endif
call assert_fails('call job_start(cmd, {"env": 1})', 'E475:') call assert_fails('call job_start(cmd, {"env": 1})', 'E475:')
call job_start(cmd, {'callback': {ch,msg -> execute(":let g:envstr .= msg")}, 'env': {'FOO': 'bar'}}) call job_start(cmd, {'callback': {ch,msg -> execute(":let g:envstr .= msg")}, 'env': {'FOO': 'bar'}})
call WaitFor('"" != g:envstr') call WaitForAssert({-> assert_equal("bar", g:envstr)})
call assert_equal("bar", g:envstr)
unlet g:envstr unlet g:envstr
endfunc endfunc
@@ -1756,7 +1721,7 @@ func Test_cwd()
endif endif
let job = job_start(cmd, {'callback': {ch,msg -> execute(":let g:envstr .= msg")}, 'cwd': expect}) let job = job_start(cmd, {'callback': {ch,msg -> execute(":let g:envstr .= msg")}, 'cwd': expect})
try try
call WaitFor('"" != g:envstr') call WaitForAssert({-> assert_notequal("", g:envstr)})
let expect = substitute(expect, '[/\\]$', '', '') let expect = substitute(expect, '[/\\]$', '', '')
let g:envstr = substitute(g:envstr, '[/\\]$', '', '') let g:envstr = substitute(g:envstr, '[/\\]$', '', '')
if $CI != '' && stridx(g:envstr, '/private/') == 0 if $CI != '' && stridx(g:envstr, '/private/') == 0
@@ -1779,8 +1744,7 @@ function Ch_test_close_lambda(port)
call ch_setoptions(handle, {'close_cb': {ch -> execute("let g:Ch_close_ret = 'closed'")}}) call ch_setoptions(handle, {'close_cb': {ch -> execute("let g:Ch_close_ret = 'closed'")}})
call assert_equal('', ch_evalexpr(handle, 'close me')) call assert_equal('', ch_evalexpr(handle, 'close me'))
call WaitFor('"closed" == g:Ch_close_ret') call WaitForAssert({-> assert_equal('closed', g:Ch_close_ret)})
call assert_equal('closed', g:Ch_close_ret)
endfunc endfunc
func Test_close_lambda() func Test_close_lambda()

View File

@@ -28,12 +28,11 @@ func Test_client_server()
let name = 'XVIMTEST' let name = 'XVIMTEST'
let cmd .= ' --servername ' . name let cmd .= ' --servername ' . name
let job = job_start(cmd, {'stoponexit': 'kill', 'out_io': 'null'}) let job = job_start(cmd, {'stoponexit': 'kill', 'out_io': 'null'})
call WaitFor({-> job_status(job) == "run"}) call WaitForAssert({-> assert_equal("run", job_status(job))})
" Takes a short while for the server to be active. " Takes a short while for the server to be active.
" When using valgrind it takes much longer. " When using valgrind it takes much longer.
call WaitFor('serverlist() =~ "' . name . '"') call WaitForAssert({-> assert_match(name, serverlist())})
call assert_match(name, serverlist())
call remote_foreground(name) call remote_foreground(name)
@@ -54,12 +53,10 @@ func Test_client_server()
endif endif
" Wait for the server to be up and answering requests. " Wait for the server to be up and answering requests.
sleep 100m sleep 100m
call WaitFor('remote_expr("' . name . '", "v:version", "", 1) != ""') call WaitForAssert({-> assert_true(remote_expr(name, "v:version", "", 1) != "")})
call assert_true(remote_expr(name, "v:version", "", 1) != "")
call remote_send(name, ":let testvar = 'maybe'\<CR>") call remote_send(name, ":let testvar = 'maybe'\<CR>")
call WaitFor('remote_expr("' . name . '", "testvar", "", 1) == "maybe"') call WaitForAssert({-> assert_equal('maybe', remote_expr(name, "testvar", "", 2))})
call assert_equal('maybe', remote_expr(name, "testvar", "", 2))
endif endif
call assert_fails('call remote_send("XXX", ":let testvar = ''yes''\<CR>")', 'E241') call assert_fails('call remote_send("XXX", ":let testvar = ''yes''\<CR>")', 'E241')
@@ -94,7 +91,7 @@ func Test_client_server()
call remote_send(name, ":qa!\<CR>") call remote_send(name, ":qa!\<CR>")
try try
call WaitFor({-> job_status(job) == "dead"}) call WaitForAssert({-> assert_equal("dead", job_status(job))})
finally finally
if job_status(job) != 'dead' if job_status(job) != 'dead'
call assert_report('Server did not exit') call assert_report('Server did not exit')

View File

@@ -8,9 +8,9 @@ func Test_job_start_fails()
if has('job') if has('job')
let job = job_start('axdfxsdf') let job = job_start('axdfxsdf')
if has('unix') if has('unix')
call WaitFor({-> job_status(job) == "dead"}) call WaitForAssert({-> assert_equal("dead", job_status(job))})
else else
call WaitFor({-> job_status(job) == "fail"}) call WaitForAssert({-> assert_equal("fail", job_status(job))})
endif endif
endif endif
endfunc endfunc

View File

@@ -83,8 +83,7 @@ func Test_terminal_wipe_buffer()
let buf = Run_shell_in_terminal({}) let buf = Run_shell_in_terminal({})
call assert_fails(buf . 'bwipe', 'E517') call assert_fails(buf . 'bwipe', 'E517')
exe buf . 'bwipe!' exe buf . 'bwipe!'
call WaitFor('job_status(g:job) == "dead"') call WaitForAssert({-> assert_equal('dead', job_status(g:job))})
call assert_equal('dead', job_status(g:job))
call assert_equal("", bufname(buf)) call assert_equal("", bufname(buf))
unlet g:job unlet g:job
@@ -100,7 +99,7 @@ func Test_terminal_split_quit()
call assert_equal('run', job_status(g:job)) call assert_equal('run', job_status(g:job))
quit! quit!
call WaitFor('job_status(g:job) == "dead"') call WaitForAssert({-> assert_equal('dead', job_status(g:job))})
call assert_equal('dead', job_status(g:job)) call assert_equal('dead', job_status(g:job))
exe buf . 'bwipe' exe buf . 'bwipe'

View File

@@ -761,6 +761,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1771,
/**/ /**/
1770, 1770,
/**/ /**/