summaryrefslogtreecommitdiffstats
path: root/src/testdir/test_channel.vim
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2018-04-28 21:34:40 +0200
committerBram Moolenaar <Bram@vim.org>2018-04-28 21:34:40 +0200
commit50182fa84e20a0547f3e2bd6683ef799fcd27855 (patch)
treee68877870cf854837d637d83208edbd114ce185c /src/testdir/test_channel.vim
parent65a5464985f980d2bbbf4e14d39d416dce065ec7 (diff)
patch 8.0.1771: in tests, when WaitFor() fails it doesn't say whyv8.0.1771
Problem: In tests, when WaitFor() fails it doesn't say why. (James McCoy) Solution: Add WaitForAssert(), which produces an assert error when it fails.
Diffstat (limited to 'src/testdir/test_channel.vim')
-rw-r--r--src/testdir/test_channel.vim130
1 files changed, 47 insertions, 83 deletions
diff --git a/src/testdir/test_channel.vim b/src/testdir/test_channel.vim
index ec8111e583..371afc7997 100644
--- a/src/testdir/test_channel.vim
+++ b/src/testdir/test_channel.vim
@@ -95,18 +95,15 @@ func Ch_communicate(port)
" handled before getting the response, but it's not guaranteed, thus wait a
" tiny bit for the commands to get executed.
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('added2', getline('$'))
" Request command "foo bar", which fails silently.
call assert_equal('ok', ch_evalexpr(handle, 'bad command'))
- call WaitFor('v:errmsg =~ "E492"')
- call assert_match('E492:.*foo bar', v:errmsg)
+ call WaitForAssert({-> assert_match("E492:.*foo bar", v:errmsg)})
call assert_equal('ok', ch_evalexpr(handle, 'do normal', {'timeout': 100}))
- call WaitFor('"added more" == getline("$")')
- call assert_equal('added more', getline('$'))
+ call WaitForAssert({-> assert_equal('added more', getline('$'))})
" Send a request with a specific handler.
call ch_sendexpr(handle, 'hello!', {'callback': 'Ch_requestHandler'})
@@ -188,10 +185,9 @@ func Ch_communicate(port)
" Send an expr request
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('two', getline(line('$') - 1))
- call assert_equal('three', getline('$'))
" Request a redraw, we don't check for the effect.
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.
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.
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
func Test_channel_handler()
@@ -334,7 +330,7 @@ func Ch_channel_zero(port)
let g:Ch_reply = ''
call assert_equal('sent zero', ch_evalexpr(handle, 'send zero'))
if s:has_handler
- call WaitFor('"zero index" == g:Ch_reply')
+ call WaitForAssert({-> assert_equal('zero index', g:Ch_reply)})
else
sleep 20m
call assert_equal('', g:Ch_reply)
@@ -344,7 +340,7 @@ func Ch_channel_zero(port)
let g:Ch_reply = ''
let g:Ch_zero_reply = ''
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
call assert_equal('zero index', g:Ch_reply)
else
@@ -395,15 +391,12 @@ func Ch_raw_one_time_callback(port)
" The messages are sent raw, we do our own JSON strings here.
call ch_sendraw(handle, "[1, \"hello!\"]\n", {'callback': 'Ch_handleRaw1'})
- call WaitFor('g:Ch_reply1 != ""')
- call assert_equal("[1, \"got it\"]", g:Ch_reply1)
+ call WaitForAssert({-> assert_equal("[1, \"got it\"]", g:Ch_reply1)})
call ch_sendraw(handle, "[2, \"echo something\"]\n", {'callback': 'Ch_handleRaw2'})
call ch_sendraw(handle, "[3, \"wait a bit\"]\n", {'callback': 'Ch_handleRaw3'})
- call WaitFor('g:Ch_reply2 != ""')
- call assert_equal("[2, \"something\"]", g:Ch_reply2)
+ call WaitForAssert({-> assert_equal("[2, \"something\"]", g:Ch_reply2)})
" wait for the 200 msec delayed reply
- call WaitFor('g:Ch_reply3 != ""')
- call assert_equal("[3, \"waited\"]", g:Ch_reply3)
+ call WaitForAssert({-> assert_equal("[3, \"waited\"]", g:Ch_reply3)})
endfunc
func Test_raw_one_time_callback()
@@ -494,8 +487,7 @@ func Test_raw_pipe()
let g:Ch_reply = ""
call ch_sendraw(job, "double this\n", {'callback': 'Ch_handler'})
- call WaitFor('"" != g:Ch_reply')
- call assert_equal("this\nAND this\n", substitute(g:Ch_reply, "\r", "", 'g'))
+ call WaitForAssert({-> assert_equal("this\nAND this\n", substitute(g:Ch_reply, "\r", "", 'g'))})
let reply = ch_evalraw(job, "quit\n", {'timeout': 100})
call assert_equal("Goodbye!\n", substitute(reply, "\r", "", 'g'))
@@ -504,7 +496,7 @@ func Test_raw_pipe()
endtry
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)
call assert_equal("dead", info.status)
call assert_equal("term", info.stoponexit)
@@ -602,7 +594,7 @@ func Stop_g_job()
if has('win32')
" On MS-Windows the server must close the file handle before we are able
" to delete the file.
- call WaitFor('job_status(g:job) == "dead"')
+ call WaitForAssert({-> assert_equal('dead', job_status(g:job))})
sleep 10m
endif
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 two\n")
call ch_sendraw(handle, "double this\n")
- call WaitFor('len(readfile("Xoutput")) > 2')
- call assert_equal(['line one', 'line two', 'this', 'AND this'], readfile('Xoutput'))
+ call WaitForAssert({-> assert_equal(['line one', 'line two', 'this', 'AND this'], readfile('Xoutput'))})
finally
call Stop_g_job()
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 two\n")
call ch_sendraw(handle, "doubleerr this\n")
- call WaitFor('len(readfile("Xoutput")) > 2')
- call assert_equal(['line one', 'line two', 'this', 'AND this'], readfile('Xoutput'))
+ call WaitForAssert({-> assert_equal(['line one', 'line two', 'this', 'AND this'], readfile('Xoutput'))})
finally
call Stop_g_job()
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, "double this\n")
call ch_sendraw(handle, "doubleerr that\n")
- call WaitFor('len(readfile("Xoutput")) > 5')
- call assert_equal(['line one', 'line two', 'this', 'AND this', 'that', 'AND that'], readfile('Xoutput'))
+ call WaitForAssert({-> assert_equal(['line one', 'line two', 'this', 'AND this', 'that', 'AND that'], readfile('Xoutput'))})
finally
call Stop_g_job()
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)
call assert_equal("run", job_status(job))
try
- call WaitFor('line("$") == 3')
- call assert_equal(3, line('$'))
+ call WaitForAssert({-> assert_equal(3, line('$'))})
quit!
sleep 100m
" 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, "quit\n")
sp pipe-err
- call WaitFor('line("$") == ' . len(expected))
- call assert_equal(expected, getline(1, '$'))
+ call WaitForAssert({-> assert_equal(expected, getline(1, '$'))})
if a:nomod
call assert_equal(0, &modifiable)
else
@@ -872,8 +859,7 @@ func Test_pipe_both_to_buffer()
call ch_sendraw(handle, "doubleerr that\n")
call ch_sendraw(handle, "quit\n")
sp pipe-err
- call WaitFor('line("$") >= 7')
- call assert_equal(['Reading from channel output...', 'line one', 'line two', 'this', 'AND this', 'that', 'AND that', 'Goodbye!'], getline(1, '$'))
+ call WaitForAssert({-> assert_equal(['Reading from channel output...', 'line one', 'line two', 'this', 'AND this', 'that', 'AND that', 'Goodbye!'], getline(1, '$'))})
bwipe!
finally
call job_stop(job)
@@ -939,8 +925,7 @@ func Run_pipe_through_sort(all, use_buffer)
call ch_close_in(g:job)
endif
- call WaitFor('job_status(g:job) == "dead"')
- call assert_equal("dead", job_status(g:job))
+ call WaitForAssert({-> assert_equal("dead", job_status(g:job))})
sp sortout
call WaitFor('line("$") > 3')
@@ -1222,16 +1207,14 @@ func Test_out_cb()
let g:Ch_errmsg = ''
call ch_sendraw(job, "echo [0, \"hello\"]\n")
call ch_sendraw(job, "echoerr [0, \"there\"]\n")
- call WaitFor('g:Ch_outmsg != ""')
- call assert_equal("dict: hello", g:Ch_outmsg)
- call WaitFor('g:Ch_errmsg != ""')
- call assert_equal("dict: there", g:Ch_errmsg)
+ call WaitForAssert({-> assert_equal("dict: hello", g:Ch_outmsg)})
+ call WaitForAssert({-> assert_equal("dict: there", g:Ch_errmsg)})
" Receive a json object split in pieces
unlet! g:Ch_outobj
call ch_sendraw(job, "echosplit [0, {\"one\": 1,| \"tw|o\": 2, \"three\": 3|}]\n")
- call WaitFor('exists("g:Ch_outobj")')
- call assert_equal({'one': 1, 'two': 2, 'three': 3}, g:Ch_outobj)
+ let g:Ch_outobj = ''
+ call WaitForAssert({-> assert_equal({'one': 1, 'two': 2, 'three': 3}, g:Ch_outobj)})
finally
call job_stop(job)
endtry
@@ -1261,9 +1244,8 @@ func Test_out_close_cb()
\ 'close_cb': 'CloseHandler'})
call assert_equal("run", job_status(job))
try
- call WaitFor('g:Ch_closemsg != 0 && g:Ch_msg1 != ""')
- call assert_equal('quit', g:Ch_msg1)
- call assert_equal(2, g:Ch_closemsg)
+ call WaitForAssert({-> assert_equal('quit', g:Ch_msg1)})
+ call WaitForAssert({-> assert_equal(2, g:Ch_closemsg)})
finally
call job_stop(job)
delfunc OutHandler
@@ -1285,8 +1267,7 @@ func Test_read_in_close_cb()
\ {'close_cb': 'CloseHandler'})
call assert_equal("run", job_status(job))
try
- call WaitFor('g:Ch_received != ""')
- call assert_equal('quit', g:Ch_received)
+ call WaitForAssert({-> assert_equal('quit', g:Ch_received)})
finally
call job_stop(job)
delfunc CloseHandler
@@ -1310,8 +1291,7 @@ func Test_read_in_close_cb_incomplete()
\ {'close_cb': 'CloseHandler'})
call assert_equal("run", job_status(job))
try
- call WaitFor('g:Ch_received != ""')
- call assert_equal('incomplete', g:Ch_received)
+ call WaitForAssert({-> assert_equal('incomplete', g:Ch_received)})
finally
call job_stop(job)
delfunc CloseHandler
@@ -1335,10 +1315,8 @@ func Test_out_cb_lambda()
let g:Ch_errmsg = ''
call ch_sendraw(job, "echo [0, \"hello\"]\n")
call ch_sendraw(job, "echoerr [0, \"there\"]\n")
- call WaitFor('g:Ch_outmsg != ""')
- call assert_equal("lambda: hello", g:Ch_outmsg)
- call WaitFor('g:Ch_errmsg != ""')
- call assert_equal("lambda: there", g:Ch_errmsg)
+ call WaitForAssert({-> assert_equal("lambda: hello", g:Ch_outmsg)})
+ call WaitForAssert({-> assert_equal("lambda: there", g:Ch_errmsg)})
finally
call job_stop(job)
endtry
@@ -1364,8 +1342,7 @@ func Test_close_and_exit_cb()
\ })
call assert_equal('run', job_status(g:job))
unlet g:job
- call WaitFor('len(g:retdict.ret) >= 2')
- call assert_equal(2, len(g:retdict.ret))
+ call WaitForAssert({-> assert_equal(2, len(g:retdict.ret))})
call assert_match('^\%(dead\|run\)', g:retdict.ret['close_cb'])
call assert_equal('dead', g:retdict.ret['exit_cb'])
unlet g:retdict
@@ -1383,8 +1360,7 @@ endfunc
func Ch_unlet_handle(port)
let s:channelfd = ch_open('localhost:' . a:port, s:chopt)
call ch_sendexpr(s:channelfd, "test", {'callback': function('s:UnletHandler')})
- call WaitFor('"what?" == g:Ch_unletResponse')
- call assert_equal('what?', g:Ch_unletResponse)
+ call WaitForAssert({-> assert_equal('what?', g:Ch_unletResponse)})
endfunc
func Test_unlet_handle()
@@ -1404,8 +1380,7 @@ endfunc
func Ch_close_handle(port)
let s:channelfd = ch_open('localhost:' . a:port, s:chopt)
call ch_sendexpr(s:channelfd, "test", {'callback': function('Ch_CloseHandler')})
- call WaitFor('"what?" == g:Ch_unletResponse')
- call assert_equal('what?', g:Ch_unletResponse)
+ call WaitForAssert({-> assert_equal('what?', g:Ch_unletResponse)})
endfunc
func Test_close_handle()
@@ -1458,8 +1433,7 @@ function Ch_test_call(port)
let g:Ch_call_ret = []
call assert_equal('ok', ch_evalexpr(handle, 'call-func'))
- call WaitFor('len(g:Ch_call_ret) > 0')
- call assert_equal([1, 2, 3], g:Ch_call_ret)
+ call WaitForAssert({-> assert_equal([1, 2, 3], g:Ch_call_ret)})
endfunc
func Test_call()
@@ -1556,8 +1530,7 @@ function Ch_test_close_callback(port)
call ch_setoptions(handle, {'close_cb': 'MyCloseCb'})
call assert_equal('', ch_evalexpr(handle, 'close me'))
- call WaitFor('"closed" == g:Ch_close_ret')
- call assert_equal('closed', g:Ch_close_ret)
+ call WaitForAssert({-> assert_equal('closed', g:Ch_close_ret)})
endfunc
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 assert_equal('', ch_evalexpr(handle, 'close me'))
- call WaitFor('"closed" == g:Ch_d.close_ret')
- call assert_equal('closed', g:Ch_d.close_ret)
+ call WaitForAssert({-> assert_equal('closed', g:Ch_d.close_ret)})
unlet g:Ch_d
endfunc
@@ -1601,8 +1573,7 @@ func Test_job_stop_immediately()
let g:job = job_start([s:python, '-c', 'import time;time.sleep(10)'])
try
call job_stop(g:job)
- call WaitFor('"dead" == job_status(g:job)')
- call assert_equal('dead', job_status(g:job))
+ call WaitForAssert({-> assert_equal('dead', job_status(g:job))})
finally
call job_stop(g:job, 'kill')
unlet g:job
@@ -1637,8 +1608,7 @@ func Test_collapse_buffers()
split testout
1,$delete
call job_start('cat test_channel.vim', {'out_io': 'buffer', 'out_name': 'testout'})
- call WaitFor('line("$") >= g:linecount')
- call assert_inrange(g:linecount, g:linecount + 1, line('$'))
+ call WaitForAssert({-> assert_inrange(g:linecount, g:linecount + 1, line('$'))})
bwipe!
endfunc
@@ -1648,13 +1618,11 @@ func Test_cmd_parsing()
endif
call assert_false(filereadable("file with space"))
let job = job_start('touch "file with space"')
- call WaitFor('filereadable("file with space")')
- call assert_true(filereadable("file with space"))
+ call WaitForAssert({-> assert_true(filereadable("file with space"))})
call delete("file with space")
let job = job_start('touch file\ with\ space')
- call WaitFor('filereadable("file with space")')
- call assert_true(filereadable("file with space"))
+ call WaitForAssert({-> assert_true(filereadable("file with space"))})
call delete("file with space")
endfunc
@@ -1683,7 +1651,7 @@ func Test_raw_passes_nul()
new mybuffer
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'})
- call WaitFor('"dead" == job_status(g:Ch_job)')
+ call WaitForAssert({-> assert_equal("dead", job_status(g:Ch_job))})
bwipe!
split Xtestwrite
call assert_equal("asdf\nasdf", getline(1))
@@ -1707,8 +1675,7 @@ func Test_read_nonl_line()
let g:linecount = 0
let arg = 'import sys;sys.stdout.write("1\n2\n3")'
call job_start([s:python, '-c', arg], {'callback': 'MyLineCountCb'})
- call WaitFor('3 <= g:linecount')
- call assert_equal(3, g:linecount)
+ call WaitForAssert({-> assert_equal(3, g:linecount)})
endfunc
func Test_read_from_terminated_job()
@@ -1719,8 +1686,7 @@ func Test_read_from_terminated_job()
let g:linecount = 0
let arg = 'import os,sys;os.close(1);sys.stderr.write("test\n")'
call job_start([s:python, '-c', arg], {'callback': 'MyLineCountCb'})
- call WaitFor('1 <= g:linecount')
- call assert_equal(1, g:linecount)
+ call WaitForAssert({-> assert_equal(1, g:linecount)})
endfunc
func Test_env()
@@ -1736,8 +1702,7 @@ func Test_env()
endif
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 WaitFor('"" != g:envstr')
- call assert_equal("bar", g:envstr)
+ call WaitForAssert({-> assert_equal("bar", g:envstr)})
unlet g:envstr
endfunc
@@ -1756,7 +1721,7 @@ func Test_cwd()
endif
let job = job_start(cmd, {'callback': {ch,msg -> execute(":let g:envstr .= msg")}, 'cwd': expect})
try
- call WaitFor('"" != g:envstr')
+ call WaitForAssert({-> assert_notequal("", g:envstr)})
let expect = substitute(expect, '[/\\]$', '', '')
let g:envstr = substitute(g:envstr, '[/\\]$', '', '')
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 assert_equal('', ch_evalexpr(handle, 'close me'))
- call WaitFor('"closed" == g:Ch_close_ret')
- call assert_equal('closed', g:Ch_close_ret)
+ call WaitForAssert({-> assert_equal('closed', g:Ch_close_ret)})
endfunc
func Test_close_lambda()