diff options
author | Bram Moolenaar <Bram@vim.org> | 2018-04-30 14:28:24 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2018-04-30 14:28:24 +0200 |
commit | 0e9d1ae3216a5940b36bb56d155fb300b2e55b00 (patch) | |
tree | 767c007fd1c9241730dd2f9053614e41837475a7 /src/testdir | |
parent | 850d427f070a61267ef384a449992e72d2bea12c (diff) | |
download | vim-0e9d1ae3216a5940b36bb56d155fb300b2e55b00.zip |
patch 8.0.1776: in tests, when WaitFor() fails it doesn't say why
Problem: In tests, when WaitFor() fails it doesn't say why.
Solution: Turn a few more WaitFor() into WaitForAssert().
Diffstat (limited to 'src/testdir')
-rw-r--r-- | src/testdir/test_popup.vim | 9 | ||||
-rw-r--r-- | src/testdir/test_quotestar.vim | 22 | ||||
-rw-r--r-- | src/testdir/test_search.vim | 4 | ||||
-rw-r--r-- | src/testdir/test_terminal.vim | 103 | ||||
-rw-r--r-- | src/testdir/test_timers.vim | 6 |
5 files changed, 63 insertions, 81 deletions
diff --git a/src/testdir/test_popup.vim b/src/testdir/test_popup.vim index ed3198585..d682dd211 100644 --- a/src/testdir/test_popup.vim +++ b/src/testdir/test_popup.vim @@ -649,18 +649,15 @@ func Test_popup_and_window_resize() call term_sendkeys(buf, "\<c-v>") call term_wait(buf, 100) " popup first entry "!" must be at the top - call WaitFor({-> term_getline(buf, 1) =~ "^!"}) - call assert_match('^!\s*$', term_getline(buf, 1)) + call WaitForAssert({-> assert_match('^!\s*$', term_getline(buf, 1))}) exe 'resize +' . (h - 1) call term_wait(buf, 100) redraw! " popup shifted down, first line is now empty - call WaitFor({-> term_getline(buf, 1) == ""}) - call assert_equal('', term_getline(buf, 1)) + call WaitForAssert({-> assert_equal('', term_getline(buf, 1))}) sleep 100m " popup is below cursor line and shows first match "!" - call WaitFor({-> term_getline(buf, term_getcursor(buf)[0] + 1) =~ "^!"}) - call assert_match('^!\s*$', term_getline(buf, term_getcursor(buf)[0] + 1)) + call WaitForAssert({-> assert_match('^!\s*$', term_getline(buf, term_getcursor(buf)[0] + 1))}) " cursor line also shows ! call assert_match('^!\s*$', term_getline(buf, term_getcursor(buf)[0])) bwipe! diff --git a/src/testdir/test_quotestar.vim b/src/testdir/test_quotestar.vim index b83fbe40e..ce5a9ee82 100644 --- a/src/testdir/test_quotestar.vim +++ b/src/testdir/test_quotestar.vim @@ -54,34 +54,33 @@ func Do_test_quotestar_for_x11() " Make sure a previous server has exited try call remote_send(name, ":qa!\<CR>") - call WaitFor('serverlist() !~ "' . name . '"') catch /E241:/ endtry - call assert_notmatch(name, serverlist()) + call WaitForAssert({-> assert_notmatch(name, serverlist())}) let cmd .= ' --servername ' . name 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. - call WaitFor('serverlist() =~ "' . name . '"') + call WaitForAssert({-> assert_match(name, serverlist())}) " Wait for the server to be up and answering requests. One second is not " always sufficient. - call WaitFor('remote_expr("' . name . '", "v:version", "", 2) != ""') + call WaitForAssert({-> assert_notequal('', remote_expr(name, "v:version", "", 2))}) " Clear the *-register of this vim instance and wait for it to be picked up " by the server. let @* = 'no' call remote_foreground(name) - call WaitFor('remote_expr("' . name . '", "@*", "", 1) == "no"') + call WaitForAssert({-> assert_equal("no", remote_expr(name, "@*", "", 1))}) " Set the * register on the server. call remote_send(name, ":let @* = 'yes'\<CR>") - call WaitFor('remote_expr("' . name . '", "@*", "", 1) == "yes"') + call WaitForAssert({-> assert_equal("yes", remote_expr(name, "@*", "", 1))}) " Check that the *-register of this vim instance is changed as expected. - call WaitFor('@* == "yes"') + call WaitForAssert({-> assert_equal("yes", @*)}) " Handle the large selection over 262040 byte. let length = 262044 @@ -109,18 +108,17 @@ func Do_test_quotestar_for_x11() call remote_send(name, ":gui -f\<CR>") endif " Wait for the server in the GUI to be up and answering requests. - call WaitFor('remote_expr("' . name . '", "has(\"gui_running\")", "", 1) =~ "1"') + call WaitForAssert({-> assert_match("1", remote_expr(name, "has('gui_running')", "", 1))}) call remote_send(name, ":let @* = 'maybe'\<CR>") - call WaitFor('remote_expr("' . name . '", "@*", "", 1) == "maybe"') - call assert_equal('maybe', remote_expr(name, "@*", "", 2)) + call WaitForAssert({-> assert_equal("maybe", remote_expr(name, "@*", "", 2))}) call assert_equal('maybe', @*) endif call remote_send(name, ":qa!\<CR>") try - call WaitFor({-> job_status(job) == "dead"}) + call WaitForAssert({-> assert_equal("dead", job_status(job))}) finally if job_status(job) != 'dead' call assert_report('Server did not exit') diff --git a/src/testdir/test_search.vim b/src/testdir/test_search.vim index 93a03434c..c923e9d40 100644 --- a/src/testdir/test_search.vim +++ b/src/testdir/test_search.vim @@ -494,7 +494,7 @@ func Test_search_cmdline8() call writefile(lines, 'Xsearch.txt') let buf = term_start([GetVimProg(), '--clean', '-c', 'set noswapfile', 'Xsearch.txt'], {'term_rows': 3}) - call WaitFor({-> lines == [term_getline(buf, 1), term_getline(buf, 2)] }) + call WaitForAssert({-> assert_equal(lines, [term_getline(buf, 1), term_getline(buf, 2)])}) call term_sendkeys(buf, ":set incsearch hlsearch\<cr>") call term_sendkeys(buf, ":14vsp\<cr>") @@ -619,7 +619,7 @@ func Test_search_cmdline_incsearch_highlight_attr() call writefile(lines, 'Xsearch.txt') let buf = term_start([GetVimProg(), '--clean', '-c', 'set noswapfile', 'Xsearch.txt'], {'term_rows': 3}) - call WaitFor({-> lines == [term_getline(buf, 1), term_getline(buf, 2)] }) + call WaitForAssert({-> assert_equal(lines, [term_getline(buf, 1), term_getline(buf, 2)])}) " wait for vim to complete initialization call term_wait(buf) diff --git a/src/testdir/test_terminal.vim b/src/testdir/test_terminal.vim index 07386a318..c9d463715 100644 --- a/src/testdir/test_terminal.vim +++ b/src/testdir/test_terminal.vim @@ -100,7 +100,6 @@ func Test_terminal_split_quit() quit! call WaitForAssert({-> assert_equal('dead', job_status(g:job))}) - call assert_equal('dead', job_status(g:job)) exe buf . 'bwipe' unlet g:job @@ -142,8 +141,8 @@ func Test_terminal_nasty_cb() let g:buf = term_start(cmd, {'exit_cb': function('s:Nasty_exit_cb')}) let g:job = term_getjob(g:buf) - call WaitFor('job_status(g:job) == "dead"') - call WaitFor('g:buf == 0') + call WaitForAssert({-> assert_equal("dead", job_status(g:job))}) + call WaitForAssert({-> assert_equal(0, g:buf)}) unlet g:buf unlet g:job call delete('Xtext') @@ -190,12 +189,12 @@ func Test_terminal_scrape_123() call term_wait(buf) " On MS-Windows we first get a startup message of two lines, wait for the " "cls" to happen, after that we have one line with three characters. - call WaitFor({-> len(term_scrape(buf, 1)) == 3}) + call WaitForAssert({-> assert_equal(3, len(term_scrape(buf, 1)))}) call Check_123(buf) " Must still work after the job ended. let job = term_getjob(buf) - call WaitFor({-> job_status(job) == "dead"}) + call WaitForAssert({-> assert_equal("dead", job_status(job))}) call term_wait(buf) call Check_123(buf) @@ -234,7 +233,7 @@ func Test_terminal_scrape_multibyte() call assert_equal('s', l[6].chars) let job = term_getjob(buf) - call WaitFor({-> job_status(job) == "dead"}) + call WaitForAssert({-> assert_equal("dead", job_status(job))}) call term_wait(buf) exe buf . 'bwipe' @@ -251,7 +250,7 @@ func Test_terminal_scroll() let buf = term_start(cmd) let job = term_getjob(buf) - call WaitFor({-> job_status(job) == "dead"}) + call WaitForAssert({-> assert_equal("dead", job_status(job))}) call term_wait(buf) if has('win32') " TODO: this should not be needed @@ -281,7 +280,7 @@ func Test_terminal_scrollback() endif let rows = term_getsize(buf)[0] " On MS-Windows there is an empty line, check both last line and above it. - call WaitFor({-> term_getline(buf, rows - 1) . term_getline(buf, rows - 2) =~ '149'}) + call WaitForAssert({-> assert_match( '149', term_getline(buf, rows - 1) . term_getline(buf, rows - 2))}) let lines = line('$') call assert_inrange(91, 100, lines) @@ -408,16 +407,16 @@ func Test_terminal_finish_open_close() let buf = bufnr('%') call assert_equal(2, winnr('$')) " Wait for the shell to display a prompt - call WaitFor({-> term_getline(buf, 1) != ""}) + call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))}) call Stop_shell_in_terminal(buf) - call WaitFor("winnr('$') == 1", waittime) + call WaitForAssert({-> assert_equal(1, winnr('$'))}, waittime) " shell terminal that does not close automatically terminal ++noclose let buf = bufnr('%') call assert_equal(2, winnr('$')) " Wait for the shell to display a prompt - call WaitFor({-> term_getline(buf, 1) != ""}) + call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))}) call Stop_shell_in_terminal(buf) call assert_equal(2, winnr('$')) quit @@ -426,36 +425,32 @@ func Test_terminal_finish_open_close() exe 'terminal ++close ' . cmd call assert_equal(2, winnr('$')) wincmd p - call WaitFor("winnr('$') == 1", waittime) + call WaitForAssert({-> assert_equal(1, winnr('$'))}, waittime) call term_start(cmd, {'term_finish': 'close'}) call assert_equal(2, winnr('$')) wincmd p - call WaitFor("winnr('$') == 1", waittime) + call WaitForAssert({-> assert_equal(1, winnr('$'))}, waittime) call assert_equal(1, winnr('$')) exe 'terminal ++open ' . cmd close! - call WaitFor("winnr('$') == 2", waittime) - call assert_equal(2, winnr('$')) + call WaitForAssert({-> assert_equal(2, winnr('$'))}, waittime) bwipe call term_start(cmd, {'term_finish': 'open'}) close! - call WaitFor("winnr('$') == 2", waittime) - call assert_equal(2, winnr('$')) + call WaitForAssert({-> assert_equal(2, winnr('$'))}, waittime) bwipe exe 'terminal ++hidden ++open ' . cmd call assert_equal(1, winnr('$')) - call WaitFor("winnr('$') == 2", waittime) - call assert_equal(2, winnr('$')) + call WaitForAssert({-> assert_equal(2, winnr('$'))}, waittime) bwipe call term_start(cmd, {'term_finish': 'open', 'hidden': 1}) call assert_equal(1, winnr('$')) - call WaitFor("winnr('$') == 2", waittime) - call assert_equal(2, winnr('$')) + call WaitForAssert({-> assert_equal(2, winnr('$'))}, waittime) bwipe call assert_fails("call term_start(cmd, {'term_opencmd': 'open'})", 'E475:') @@ -465,8 +460,7 @@ func Test_terminal_finish_open_close() call term_start(cmd, {'term_finish': 'open', 'term_opencmd': '4split | buffer %d'}) close! - call WaitFor("winnr('$') == 2", waittime) - call assert_equal(2, winnr('$')) + call WaitForAssert({-> assert_equal(2, winnr('$'))}, waittime) call assert_equal(4, winheight(0)) bwipe endfunc @@ -477,8 +471,7 @@ func Test_terminal_cwd() endif call mkdir('Xdir') let buf = term_start('pwd', {'cwd': 'Xdir'}) - call WaitFor('"Xdir" == fnamemodify(getline(1), ":t")') - call assert_equal('Xdir', fnamemodify(getline(1), ":t")) + call WaitForAssert({-> assert_equal('Xdir', fnamemodify(getline(1), ":t"))}) exe buf . 'bwipe' call delete('Xdir', 'rf') @@ -490,7 +483,7 @@ func Test_terminal_servername() endif let buf = Run_shell_in_terminal({}) " Wait for the shell to display a prompt - call WaitFor({-> term_getline(buf, 1) != ""}) + call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))}) if has('win32') call term_sendkeys(buf, "echo %VIM_SERVERNAME%\r") else @@ -508,7 +501,7 @@ endfunc func Test_terminal_env() let buf = Run_shell_in_terminal({'env': {'TESTENV': 'correct'}}) " Wait for the shell to display a prompt - call WaitFor({-> term_getline(buf, 1) != ""}) + call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))}) if has('win32') call term_sendkeys(buf, "echo %TESTENV%\r") else @@ -516,8 +509,7 @@ func Test_terminal_env() endif call term_wait(buf) call Stop_shell_in_terminal(buf) - call WaitFor('getline(2) == "correct"') - call assert_equal('correct', getline(2)) + call WaitForAssert({-> assert_equal('correct', getline(2))}) exe buf . 'bwipe' endfunc @@ -539,8 +531,7 @@ func Test_zz_terminal_in_gui() call term_wait(buf) " closing window wipes out the terminal buffer a with finished job - call WaitFor("winnr('$') == 1") - call assert_equal(1, winnr('$')) + call WaitForAssert({-> assert_equal(1, winnr('$'))}) call assert_equal("", bufname(buf)) unlet g:job @@ -592,7 +583,7 @@ func Test_terminal_write_stdin() new call setline(1, ['one', 'two', 'three']) %term wc - call WaitFor('getline("$") =~ "3"') + call WaitForAssert({-> assert_match('3', getline("$"))}) let nrs = split(getline('$')) call assert_equal(['3', '3', '14'], nrs) bwipe @@ -600,7 +591,7 @@ func Test_terminal_write_stdin() new call setline(1, ['one', 'two', 'three', 'four']) 2,3term wc - call WaitFor('getline("$") =~ "2"') + call WaitForAssert({-> assert_match('2', getline("$"))}) let nrs = split(getline('$')) call assert_equal(['2', '2', '10'], nrs) bwipe @@ -622,7 +613,7 @@ func Test_terminal_write_stdin() new call setline(1, ['print("hello")']) 1term ++eof=<C-Z> python - call WaitFor('getline("$") =~ "Z"') + call WaitForAssert({-> assert_match('Z', getline("$"))}) call assert_equal('hello', getline(line('$') - 1)) bwipe endif @@ -646,9 +637,8 @@ func Test_terminal_no_cmd() else call system('echo "look here" > ' . pty) endif - call WaitFor({-> term_getline(buf, 1) =~ "look here"}) + call WaitForAssert({-> assert_match('look here', term_getline(buf, 1))}) - call assert_match('look here', term_getline(buf, 1)) bwipe! endfunc @@ -660,8 +650,7 @@ func Test_terminal_special_chars() call mkdir('Xdir with spaces') call writefile(['x'], 'Xdir with spaces/quoted"file') term ls Xdir\ with\ spaces/quoted\"file - call WaitFor('term_getline("", 1) =~ "quoted"') - call assert_match('quoted"file', term_getline('', 1)) + call WaitForAssert({-> assert_match('quoted"file', term_getline('', 1))}) call term_wait('') call delete('Xdir with spaces', 'rf') @@ -691,10 +680,10 @@ func Test_terminal_redir_file() let cmd = Get_cat_123_cmd() let buf = term_start(cmd, {'out_io': 'file', 'out_name': 'Xfile'}) call term_wait(buf) - call WaitFor('len(readfile("Xfile")) > 0') + call WaitForAssert({-> assert_notequal(0, len(readfile("Xfile")))}) call assert_match('123', readfile('Xfile')[0]) let g:job = term_getjob(buf) - call WaitFor('job_status(g:job) == "dead"') + call WaitForAssert({-> assert_equal("dead", job_status(g:job))}) call delete('Xfile') bwipe endif @@ -703,10 +692,9 @@ func Test_terminal_redir_file() call writefile(['one line'], 'Xfile') let buf = term_start('cat', {'in_io': 'file', 'in_name': 'Xfile'}) call term_wait(buf) - call WaitFor('term_getline(' . buf . ', 1) == "one line"') - call assert_equal('one line', term_getline(buf, 1)) + call WaitForAssert({-> assert_equal('one line', term_getline(buf, 1))}) let g:job = term_getjob(buf) - call WaitFor('job_status(g:job) == "dead"') + call WaitForAssert({-> assert_equal('dead', job_status(g:job))}) bwipe call delete('Xfile') endif @@ -726,7 +714,7 @@ func TerminalTmap(remap) call assert_equal('456', maparg('123', 't')) call assert_equal('abxde', maparg('456', 't')) call feedkeys("123", 'tx') - call WaitFor({-> term_getline(buf, term_getcursor(buf)[0]) =~ 'abxde\|456'}) + call WaitForAssert({-> assert_match('abxde\|456', term_getline(buf, term_getcursor(buf)[0]))}) let lnum = term_getcursor(buf)[0] if a:remap call assert_match('abxde', term_getline(buf, lnum)) @@ -825,8 +813,7 @@ func Test_terminal_composing_unicode() call assert_equal("\u00a0\u0308", l[3].chars) call term_sendkeys(buf, "exit\r") - call WaitFor('job_status(g:job) == "dead"') - call assert_equal('dead', job_status(g:job)) + call WaitForAssert({-> assert_equal('dead', job_status(g:job))}) bwipe! unlet g:job let &encoding = save_enc @@ -849,7 +836,7 @@ func Test_terminal_aucmd_on_close() call setline(1, ['one', 'two']) exe 'term ++close ' . cmd wincmd p - call WaitFor("winnr('$') == 2", waittime) + call WaitForAssert({-> assert_equal(2, winnr('$'))}, waittime) call assert_equal(1, s:called) bwipe! @@ -875,16 +862,16 @@ func Test_terminal_response_to_control_sequence() endif let buf = Run_shell_in_terminal({}) - call WaitFor({-> term_getline(buf, 1) != ''}) + call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))}) call term_sendkeys(buf, "cat\<CR>") - call WaitFor({-> term_getline(buf, 1) =~ 'cat'}) + call WaitForAssert({-> assert_match('cat', term_getline(buf, 1))}) " Request the cursor position. call term_sendkeys(buf, "\x1b[6n\<CR>") " Wait for output from tty to display, below an empty line. - call WaitFor({-> term_getline(buf, 4) =~ '3;1R'}) + call WaitForAssert({-> assert_match('3;1R', term_getline(buf, 4))}) " End "cat" gently. call term_sendkeys(buf, "\<CR>\<C-D>") @@ -961,14 +948,14 @@ func Test_terminal_qall_prompt() " Open a terminal window and wait for the prompt to appear call term_sendkeys(buf, ":term\<CR>") - call WaitFor({-> term_getline(buf, 10) =~ '\[running]'}) - call WaitFor({-> term_getline(buf, 1) !~ '^\s*$'}) + call WaitForAssert({-> assert_match('\[running]', term_getline(buf, 10))}) + call WaitForAssert({-> assert_notmatch('^\s*$', term_getline(buf, 1))}) " make Vim exit, it will prompt to kill the shell call term_sendkeys(buf, "\<C-W>:confirm qall\<CR>") - call WaitFor({-> term_getline(buf, 20) =~ 'ancel:'}) + call WaitForAssert({-> assert_match('ancel:', term_getline(buf, 20))}) call term_sendkeys(buf, "y") - call WaitFor({-> term_getstatus(buf) == "finished"}) + call WaitForAssert({-> assert_equal('finished', term_getstatus(buf))}) " close the terminal window where Vim was running quit @@ -1025,7 +1012,7 @@ func Test_terminal_dumpwrite_composing() let text = " a\u0300 e\u0302 o\u0308" call writefile([text], 'Xcomposing') let buf = RunVimInTerminal('Xcomposing', {}) - call WaitFor({-> term_getline(buf, 1) =~ text}) + call WaitForAssert({-> assert_match(text, term_getline(buf, 1))}) call term_dumpwrite(buf, 'Xdump') let dumpline = readfile('Xdump')[0] call assert_match('|à| |ê| |ö', dumpline) @@ -1235,7 +1222,7 @@ func Test_terminal_api_drop_oldwin() \ "set t_ts=", \ ], 'Xscript') let buf = RunVimInTerminal('-S Xscript', {'rows': 10}) - call WaitFor({-> expand('%:t') =='Xtextfile'}) + call WaitForAssert({-> assert_equal('Xtextfile', expand('%:t'))}) call assert_equal(textfile_winid, win_getid()) call StopVimInTerminal(buf) @@ -1284,7 +1271,7 @@ func Test_terminal_api_call_fails() call WriteApiCall('TryThis') call ch_logfile('Xlog', 'w') let buf = RunVimInTerminal('-S Xscript', {}) - call WaitFor({-> string(readfile('Xlog')) =~ 'Invalid function name: TryThis'}) + call WaitForAssert({-> assert_match('Invalid function name: TryThis', string(readfile('Xlog')))}) call StopVimInTerminal(buf) call delete('Xscript') @@ -1309,7 +1296,7 @@ func Test_terminal_api_call_fail_delete() call WriteApiCall('Tapi_Delete') let buf = RunVimInTerminal('-S Xscript', {}) - call WaitFor({-> s:caught_e937 == 1}) + call WaitForAssert({-> assert_equal(1, s:caught_e937)}) call StopVimInTerminal(buf) call delete('Xscript') diff --git a/src/testdir/test_timers.vim b/src/testdir/test_timers.vim index df42b2c2b..79a5ba58c 100644 --- a/src/testdir/test_timers.vim +++ b/src/testdir/test_timers.vim @@ -143,7 +143,7 @@ endfunc func Test_delete_myself() let g:called = 0 let t = timer_start(10, 'StopMyself', {'repeat': -1}) - call WaitFor('g:called == 2') + call WaitForAssert({-> assert_equal(2, g:called)}) call assert_equal(2, g:called) call assert_equal([], timer_info(t)) endfunc @@ -206,7 +206,7 @@ func Test_timer_errors() let g:call_count = 0 let timer = timer_start(10, 'FuncWithError', {'repeat': -1}) " Timer will be stopped after failing 3 out of 3 times. - call WaitFor('g:call_count == 3') + call WaitForAssert({-> assert_equal(3, g:call_count)}) sleep 50m call assert_equal(3, g:call_count) endfunc @@ -224,7 +224,7 @@ func Test_timer_catch_error() let g:call_count = 0 let timer = timer_start(10, 'FuncWithCaughtError', {'repeat': 4}) " Timer will not be stopped. - call WaitFor('g:call_count == 4') + call WaitForAssert({-> assert_equal(4, g:call_count)}) sleep 50m call assert_equal(4, g:call_count) endfunc |