143345546SBram Moolenaar" This script is sourced while editing the .vim file with the tests. 243345546SBram Moolenaar" When the script is successful the .res file will be created. 343345546SBram Moolenaar" Errors are appended to the test.log file. 443345546SBram Moolenaar" 5befb366aSBram Moolenaar" To execute only specific test functions, add a second argument. It will be 6befb366aSBram Moolenaar" matched against the names of the Test_ funtion. E.g.: 7befb366aSBram Moolenaar" ../vim -u NONE -S runtest.vim test_channel.vim open_delay 8befb366aSBram Moolenaar" The output can be found in the "messages" file. 9befb366aSBram Moolenaar" 1043345546SBram Moolenaar" The test script may contain anything, only functions that start with 1143345546SBram Moolenaar" "Test_" are special. These will be invoked and should contain assert 1243345546SBram Moolenaar" functions. See test_assert.vim for an example. 1343345546SBram Moolenaar" 1443345546SBram Moolenaar" It is possible to source other files that contain "Test_" functions. This 1543345546SBram Moolenaar" can speed up testing, since Vim does not need to restart. But be careful 1643345546SBram Moolenaar" that the tests do not interfere with each other. 1743345546SBram Moolenaar" 1843345546SBram Moolenaar" If an error cannot be detected properly with an assert function add the 1943345546SBram Moolenaar" error to the v:errors list: 2043345546SBram Moolenaar" call add(v:errors, 'test foo failed: Cannot find xyz') 2143345546SBram Moolenaar" 2243345546SBram Moolenaar" If preparation for each Test_ function is needed, define a SetUp function. 2343345546SBram Moolenaar" It will be called before each Test_ function. 2443345546SBram Moolenaar" 2543345546SBram Moolenaar" If cleanup after each Test_ function is needed, define a TearDown function. 2643345546SBram Moolenaar" It will be called after each Test_ function. 2700af60bbSBram Moolenaar" 2800af60bbSBram Moolenaar" When debugging a test it can be useful to add messages to v:errors: 2900af60bbSBram Moolenaar" call add(v:errors, "this happened") 3000af60bbSBram Moolenaar 3143345546SBram Moolenaar 3243345546SBram Moolenaar" Without the +eval feature we can't run these tests, bail out. 334686b323SBram Moolenaarso small.vim 3443345546SBram Moolenaar 3543345546SBram Moolenaar" Check that the screen size is at least 24 x 80 characters. 3643345546SBram Moolenaarif &lines < 24 || &columns < 80 3743345546SBram Moolenaar let error = 'Screen size too small! Tests require at least 24 lines with 80 characters' 3843345546SBram Moolenaar echoerr error 3943345546SBram Moolenaar split test.log 4043345546SBram Moolenaar $put =error 41*45aa07d3SBram Moolenaar write 42*45aa07d3SBram Moolenaar split messages 43*45aa07d3SBram Moolenaar call append(line('$'), error) 44*45aa07d3SBram Moolenaar write 45*45aa07d3SBram Moolenaar qa! 4643345546SBram Moolenaarendif 4743345546SBram Moolenaar 4875ee544fSBram Moolenaarif has('reltime') 4975ee544fSBram Moolenaar let s:start_time = reltime() 5075ee544fSBram Moolenaarendif 5175ee544fSBram Moolenaar 5289b10421SBram Moolenaar" Common with all tests on all systems. 5389b10421SBram Moolenaarsource setup.vim 5489b10421SBram Moolenaar 55c0662466SBram Moolenaar" For consistency run all tests with 'nocompatible' set. 56c0662466SBram Moolenaar" This also enables use of line continuation. 57c0662466SBram Moolenaarset nocp viminfo+=nviminfo 58c0662466SBram Moolenaar 5930276f2bSBram Moolenaar" Use utf-8 by default, instead of whatever the system default happens to be. 60ed79d1e3SBram Moolenaar" Individual tests can overrule this at the top of the file and use 61ed79d1e3SBram Moolenaar" g:orig_encoding if needed. 62ed79d1e3SBram Moolenaarlet g:orig_encoding = &encoding 63ac105ed3SBram Moolenaarset encoding=utf-8 64ac105ed3SBram Moolenaar 65d8f27b30SBram Moolenaar" REDIR_TEST_TO_NULL has a very permissive SwapExists autocommand which is for 66d8f27b30SBram Moolenaar" the test_name.vim file itself. Replace it here with a more restrictive one, 67d8f27b30SBram Moolenaar" so we still catch mistakes. 68d8f27b30SBram Moolenaarlet s:test_script_fname = expand('%') 69d8f27b30SBram Moolenaarau! SwapExists * call HandleSwapExists() 70d8f27b30SBram Moolenaarfunc HandleSwapExists() 71d8f27b30SBram Moolenaar " Only ignore finding a swap file for the test script (the user might be 72d8f27b30SBram Moolenaar " editing it and do ":make test_name") and the output file. 73d8f27b30SBram Moolenaar if expand('<afile>') == 'messages' || expand('<afile>') =~ s:test_script_fname 74d8f27b30SBram Moolenaar let v:swapchoice = 'e' 75d8f27b30SBram Moolenaar endif 76d8f27b30SBram Moolenaarendfunc 77d8f27b30SBram Moolenaar 787a073549SBram Moolenaar" Avoid stopping at the "hit enter" prompt 797a073549SBram Moolenaarset nomore 807a073549SBram Moolenaar 81c0662466SBram Moolenaar" Output all messages in English. 82c0662466SBram Moolenaarlang mess C 83c0662466SBram Moolenaar 84f60b796fSBram Moolenaar" Always use forward slashes. 85f60b796fSBram Moolenaarset shellslash 86f60b796fSBram Moolenaar 8728fb79dbSBram Moolenaarlet s:srcdir = expand('%:p:h:h') 8828fb79dbSBram Moolenaar 898e8df251SBram Moolenaar" Prepare for calling test_garbagecollect_now(). 90ebf7dfa6SBram Moolenaarlet v:testing = 1 91ebf7dfa6SBram Moolenaar 9228fb79dbSBram Moolenaar" Support function: get the alloc ID by name. 9328fb79dbSBram Moolenaarfunction GetAllocId(name) 9428fb79dbSBram Moolenaar exe 'split ' . s:srcdir . '/alloc.h' 95065ee9aeSBram Moolenaar let top = search('typedef enum') 96065ee9aeSBram Moolenaar if top == 0 97065ee9aeSBram Moolenaar call add(v:errors, 'typedef not found in alloc.h') 98065ee9aeSBram Moolenaar endif 9928fb79dbSBram Moolenaar let lnum = search('aid_' . a:name . ',') 10028fb79dbSBram Moolenaar if lnum == 0 10128fb79dbSBram Moolenaar call add(v:errors, 'Alloc ID ' . a:name . ' not defined') 10228fb79dbSBram Moolenaar endif 10328fb79dbSBram Moolenaar close 104065ee9aeSBram Moolenaar return lnum - top - 1 10528fb79dbSBram Moolenaarendfunc 10628fb79dbSBram Moolenaar 10742205551SBram Moolenaarfunc RunTheTest(test) 108b5760a1cSBram Moolenaar echo 'Executing ' . a:test 10975ee544fSBram Moolenaar if has('reltime') 11075ee544fSBram Moolenaar let func_start = reltime() 11175ee544fSBram Moolenaar endif 112e5f2a075SBram Moolenaar 113e5f2a075SBram Moolenaar " Avoid stopping at the "hit enter" prompt 114e5f2a075SBram Moolenaar set nomore 115e5f2a075SBram Moolenaar 116e5f2a075SBram Moolenaar " Avoid a three second wait when a message is about to be overwritten by the 117e5f2a075SBram Moolenaar " mode message. 118e5f2a075SBram Moolenaar set noshowmode 119e5f2a075SBram Moolenaar 120eb992cb9SBram Moolenaar " Clear any overrides. 121eb992cb9SBram Moolenaar call test_override('ALL', 0) 122eb992cb9SBram Moolenaar 123cf1ba35fSBram Moolenaar " Some tests wipe out buffers. To be consistent, always wipe out all 124cf1ba35fSBram Moolenaar " buffers. 125cf1ba35fSBram Moolenaar %bwipe! 126cf1ba35fSBram Moolenaar 127209d3874SBram Moolenaar " The test may change the current directory. Save and restore the 128209d3874SBram Moolenaar " directory after executing the test. 129209d3874SBram Moolenaar let save_cwd = getcwd() 130209d3874SBram Moolenaar 131b5760a1cSBram Moolenaar if exists("*SetUp") 132cc28e2d0SBram Moolenaar try 133b5760a1cSBram Moolenaar call SetUp() 134cc28e2d0SBram Moolenaar catch 135cc28e2d0SBram Moolenaar call add(v:errors, 'Caught exception in SetUp() before ' . a:test . ': ' . v:exception . ' @ ' . v:throwpoint) 136cc28e2d0SBram Moolenaar endtry 137b5760a1cSBram Moolenaar endif 138b5760a1cSBram Moolenaar 139f204e05aSBram Moolenaar if a:test =~ 'Test_nocatch_' 140f204e05aSBram Moolenaar " Function handles errors itself. This avoids skipping commands after the 141f204e05aSBram Moolenaar " error. 142f204e05aSBram Moolenaar exe 'call ' . a:test 143f204e05aSBram Moolenaar else 144b5760a1cSBram Moolenaar try 1458903676dSBram Moolenaar let s:test = a:test 1468903676dSBram Moolenaar au VimLeavePre * call EarlyExit(s:test) 147b5760a1cSBram Moolenaar exe 'call ' . a:test 1488903676dSBram Moolenaar au! VimLeavePre 149dac1947bSBram Moolenaar catch /^\cskipped/ 150dac1947bSBram Moolenaar call add(s:messages, ' Skipped') 151dac1947bSBram Moolenaar call add(s:skipped, 'SKIPPED ' . a:test . ': ' . substitute(v:exception, '^\S*\s\+', '', '')) 152b5760a1cSBram Moolenaar catch 153b5760a1cSBram Moolenaar call add(v:errors, 'Caught exception in ' . a:test . ': ' . v:exception . ' @ ' . v:throwpoint) 154b5760a1cSBram Moolenaar endtry 155f204e05aSBram Moolenaar endif 1568ad16da7SBram Moolenaar 1578ad16da7SBram Moolenaar " In case 'insertmode' was set and something went wrong, make sure it is 1588ad16da7SBram Moolenaar " reset to avoid trouble with anything else. 1598ad16da7SBram Moolenaar set noinsertmode 160b5760a1cSBram Moolenaar 161b5760a1cSBram Moolenaar if exists("*TearDown") 162cc28e2d0SBram Moolenaar try 163b5760a1cSBram Moolenaar call TearDown() 164cc28e2d0SBram Moolenaar catch 165cc28e2d0SBram Moolenaar call add(v:errors, 'Caught exception in TearDown() after ' . a:test . ': ' . v:exception . ' @ ' . v:throwpoint) 166cc28e2d0SBram Moolenaar endtry 167b5760a1cSBram Moolenaar endif 1687cba71d7SBram Moolenaar 169cf1ba35fSBram Moolenaar " Clear any autocommands 170cf1ba35fSBram Moolenaar au! 171d8f27b30SBram Moolenaar au SwapExists * call HandleSwapExists() 172cf1ba35fSBram Moolenaar 173ce11de87SBram Moolenaar " Close any extra tab pages and windows and make the current one not modified. 174ce11de87SBram Moolenaar while tabpagenr('$') > 1 175cf1ba35fSBram Moolenaar quit! 176ce11de87SBram Moolenaar endwhile 177ce11de87SBram Moolenaar 178358308ddSBram Moolenaar while 1 179358308ddSBram Moolenaar let wincount = winnr('$') 180358308ddSBram Moolenaar if wincount == 1 181358308ddSBram Moolenaar break 182358308ddSBram Moolenaar endif 1837cba71d7SBram Moolenaar bwipe! 184358308ddSBram Moolenaar if wincount == winnr('$') 185358308ddSBram Moolenaar " Did not manage to close a window. 186358308ddSBram Moolenaar only! 187358308ddSBram Moolenaar break 188358308ddSBram Moolenaar endif 1897cba71d7SBram Moolenaar endwhile 190209d3874SBram Moolenaar 191209d3874SBram Moolenaar exe 'cd ' . save_cwd 192640d4f0cSBram Moolenaar 193640d4f0cSBram Moolenaar let message = 'Executed ' . a:test 194640d4f0cSBram Moolenaar if has('reltime') 195640d4f0cSBram Moolenaar let message ..= ' in ' .. reltimestr(reltime(func_start)) .. ' seconds' 196640d4f0cSBram Moolenaar endif 197640d4f0cSBram Moolenaar call add(s:messages, message) 198640d4f0cSBram Moolenaar let s:done += 1 199b5760a1cSBram Moolenaarendfunc 20028fb79dbSBram Moolenaar 20142205551SBram Moolenaarfunc AfterTheTest() 20243345546SBram Moolenaar if len(v:errors) > 0 20300af60bbSBram Moolenaar let s:fail += 1 20400af60bbSBram Moolenaar call add(s:errors, 'Found errors in ' . s:test . ':') 20500af60bbSBram Moolenaar call extend(s:errors, v:errors) 20643345546SBram Moolenaar let v:errors = [] 20743345546SBram Moolenaar endif 20842205551SBram Moolenaarendfunc 20942205551SBram Moolenaar 2108903676dSBram Moolenaarfunc EarlyExit(test) 2118903676dSBram Moolenaar " It's OK for the test we use to test the quit detection. 2128903676dSBram Moolenaar if a:test != 'Test_zz_quit_detected()' 2138903676dSBram Moolenaar call add(v:errors, 'Test caused Vim to exit: ' . a:test) 2148903676dSBram Moolenaar endif 2158903676dSBram Moolenaar 2168903676dSBram Moolenaar call FinishTesting() 2178903676dSBram Moolenaarendfunc 2188903676dSBram Moolenaar 21942205551SBram Moolenaar" This function can be called by a test if it wants to abort testing. 22042205551SBram Moolenaarfunc FinishTesting() 22142205551SBram Moolenaar call AfterTheTest() 22243345546SBram Moolenaar 223fc4ad616SBram Moolenaar " Don't write viminfo on exit. 224fc4ad616SBram Moolenaar set viminfo= 225fc4ad616SBram Moolenaar 226d1ee0043SBram Moolenaar " Clean up files created by setup.vim 227d1ee0043SBram Moolenaar call delete('XfakeHOME', 'rf') 228d1ee0043SBram Moolenaar 22900af60bbSBram Moolenaar if s:fail == 0 23043345546SBram Moolenaar " Success, create the .res file so that make knows it's done. 23100af60bbSBram Moolenaar exe 'split ' . fnamemodify(g:testname, ':r') . '.res' 23243345546SBram Moolenaar write 23343345546SBram Moolenaar endif 23443345546SBram Moolenaar 23500af60bbSBram Moolenaar if len(s:errors) > 0 23643345546SBram Moolenaar " Append errors to test.log 23743345546SBram Moolenaar split test.log 23843345546SBram Moolenaar call append(line('$'), '') 23900af60bbSBram Moolenaar call append(line('$'), 'From ' . g:testname . ':') 24000af60bbSBram Moolenaar call append(line('$'), s:errors) 24143345546SBram Moolenaar write 24243345546SBram Moolenaar endif 24343345546SBram Moolenaar 24429f9ed20SBram Moolenaar if s:done == 0 24529f9ed20SBram Moolenaar let message = 'NO tests executed' 24629f9ed20SBram Moolenaar else 24700af60bbSBram Moolenaar let message = 'Executed ' . s:done . (s:done > 1 ? ' tests' : ' test') 24829f9ed20SBram Moolenaar endif 24975ee544fSBram Moolenaar if has('reltime') 25075ee544fSBram Moolenaar let message ..= ' in ' .. reltimestr(reltime(s:start_time)) .. ' seconds' 25175ee544fSBram Moolenaar endif 252096c8bb4SBram Moolenaar echo message 25300af60bbSBram Moolenaar call add(s:messages, message) 25400af60bbSBram Moolenaar if s:fail > 0 25500af60bbSBram Moolenaar let message = s:fail . ' FAILED:' 256096c8bb4SBram Moolenaar echo message 25700af60bbSBram Moolenaar call add(s:messages, message) 25800af60bbSBram Moolenaar call extend(s:messages, s:errors) 25943345546SBram Moolenaar endif 26043345546SBram Moolenaar 261dac1947bSBram Moolenaar " Add SKIPPED messages 262dac1947bSBram Moolenaar call extend(s:messages, s:skipped) 263dac1947bSBram Moolenaar 264dac1947bSBram Moolenaar " Append messages to the file "messages" 265096c8bb4SBram Moolenaar split messages 266096c8bb4SBram Moolenaar call append(line('$'), '') 26700af60bbSBram Moolenaar call append(line('$'), 'From ' . g:testname . ':') 26800af60bbSBram Moolenaar call append(line('$'), s:messages) 269096c8bb4SBram Moolenaar write 270096c8bb4SBram Moolenaar 27143345546SBram Moolenaar qall! 27242205551SBram Moolenaarendfunc 27342205551SBram Moolenaar 27442205551SBram Moolenaar" Source the test script. First grab the file name, in case the script 27542205551SBram Moolenaar" navigates away. g:testname can be used by the tests. 27642205551SBram Moolenaarlet g:testname = expand('%') 27742205551SBram Moolenaarlet s:done = 0 27842205551SBram Moolenaarlet s:fail = 0 27942205551SBram Moolenaarlet s:errors = [] 28042205551SBram Moolenaarlet s:messages = [] 28142205551SBram Moolenaarlet s:skipped = [] 28242205551SBram Moolenaarif expand('%') =~ 'test_vimscript.vim' 28342205551SBram Moolenaar " this test has intentional s:errors, don't use try/catch. 28442205551SBram Moolenaar source % 28542205551SBram Moolenaarelse 28642205551SBram Moolenaar try 28742205551SBram Moolenaar source % 2889c0cec65SBram Moolenaar catch /^\cskipped/ 2899c0cec65SBram Moolenaar call add(s:messages, ' Skipped') 2909c0cec65SBram Moolenaar call add(s:skipped, 'SKIPPED ' . expand('%') . ': ' . substitute(v:exception, '^\S*\s\+', '', '')) 29142205551SBram Moolenaar catch 29242205551SBram Moolenaar let s:fail += 1 29342205551SBram Moolenaar call add(s:errors, 'Caught exception: ' . v:exception . ' @ ' . v:throwpoint) 29442205551SBram Moolenaar endtry 29542205551SBram Moolenaarendif 29642205551SBram Moolenaar 29742205551SBram Moolenaar" Names of flaky tests. 298dbc0d216SBram Moolenaarlet s:flaky_tests = [ 299c0f05d0bSBram Moolenaar \ 'Test_call()', 300c0f05d0bSBram Moolenaar \ 'Test_channel_handler()', 30142205551SBram Moolenaar \ 'Test_client_server()', 30242205551SBram Moolenaar \ 'Test_close_and_exit_cb()', 303c0f05d0bSBram Moolenaar \ 'Test_close_callback()', 304c0f05d0bSBram Moolenaar \ 'Test_close_handle()', 305c0f05d0bSBram Moolenaar \ 'Test_close_lambda()', 306d80232beSBram Moolenaar \ 'Test_close_output_buffer()', 307c0f05d0bSBram Moolenaar \ 'Test_close_partial()', 30842205551SBram Moolenaar \ 'Test_collapse_buffers()', 30942205551SBram Moolenaar \ 'Test_communicate()', 31065873846SBram Moolenaar \ 'Test_cwd()', 311218959bcSBram Moolenaar \ 'Test_diff_screen()', 312c0f05d0bSBram Moolenaar \ 'Test_exit_callback()', 31342205551SBram Moolenaar \ 'Test_exit_callback_interval()', 31442205551SBram Moolenaar \ 'Test_nb_basic()', 31542205551SBram Moolenaar \ 'Test_oneshot()', 316c0f05d0bSBram Moolenaar \ 'Test_open_delay()', 3171eca6f13SBram Moolenaar \ 'Test_out_cb()', 31824820691SBram Moolenaar \ 'Test_paused()', 31942205551SBram Moolenaar \ 'Test_pipe_through_sort_all()', 32042205551SBram Moolenaar \ 'Test_pipe_through_sort_some()', 321142ae736SBram Moolenaar \ 'Test_popup_and_window_resize()', 32242205551SBram Moolenaar \ 'Test_quoteplus()', 3237dd48506SBram Moolenaar \ 'Test_quotestar()', 324c0f05d0bSBram Moolenaar \ 'Test_raw_one_time_callback()', 32542205551SBram Moolenaar \ 'Test_reltime()', 326bfbea567SBram Moolenaar \ 'Test_repeat_three()', 327c0f05d0bSBram Moolenaar \ 'Test_server_crash()', 328c0f05d0bSBram Moolenaar \ 'Test_terminal_ansicolors_default()', 329c0f05d0bSBram Moolenaar \ 'Test_terminal_ansicolors_func()', 330c0f05d0bSBram Moolenaar \ 'Test_terminal_ansicolors_global()', 331f204e05aSBram Moolenaar \ 'Test_terminal_composing_unicode()', 3323876789bSBram Moolenaar \ 'Test_terminal_does_not_truncate_last_newlines()', 333c0f05d0bSBram Moolenaar \ 'Test_terminal_env()', 334c0f05d0bSBram Moolenaar \ 'Test_terminal_hide_buffer()', 335c0f05d0bSBram Moolenaar \ 'Test_terminal_make_change()', 3363615abb6SBram Moolenaar \ 'Test_terminal_no_cmd()', 33775a60f74SBram Moolenaar \ 'Test_terminal_noblock()', 3387dd88c51SBram Moolenaar \ 'Test_terminal_redir_file()', 339c0f05d0bSBram Moolenaar \ 'Test_terminal_response_to_control_sequence()', 340c0f05d0bSBram Moolenaar \ 'Test_terminal_scrollback()', 341c0f05d0bSBram Moolenaar \ 'Test_terminal_split_quit()', 342c0f05d0bSBram Moolenaar \ 'Test_terminal_termwinkey()', 343c0f05d0bSBram Moolenaar \ 'Test_terminal_termwinsize_mininmum()', 344c0f05d0bSBram Moolenaar \ 'Test_terminal_termwinsize_option_fixed()', 345c0f05d0bSBram Moolenaar \ 'Test_terminal_termwinsize_option_zero()', 34624820691SBram Moolenaar \ 'Test_terminal_tmap()', 347c0f05d0bSBram Moolenaar \ 'Test_terminal_wall()', 348c0f05d0bSBram Moolenaar \ 'Test_terminal_wipe_buffer()', 349c0f05d0bSBram Moolenaar \ 'Test_terminal_wqall()', 350c0f05d0bSBram Moolenaar \ 'Test_two_channels()', 351c0f05d0bSBram Moolenaar \ 'Test_unlet_handle()', 352d09be321SBram Moolenaar \ 'Test_with_partial_callback()', 353c0f05d0bSBram Moolenaar \ 'Test_zero_reply()', 354c0f05d0bSBram Moolenaar \ 'Test_zz1_terminal_in_gui()', 35542205551SBram Moolenaar \ ] 35642205551SBram Moolenaar 357dbc0d216SBram Moolenaar" Pattern indicating a common flaky test failure. 358447f6ce8SBram Moolenaarlet s:flaky_errors_re = 'StopVimInTerminal\|VerifyScreenDump' 359dbc0d216SBram Moolenaar 36042205551SBram Moolenaar" Locate Test_ functions and execute them. 36142205551SBram Moolenaarredir @q 36242205551SBram Moolenaarsilent function /^Test_ 36342205551SBram Moolenaarredir END 36442205551SBram Moolenaarlet s:tests = split(substitute(@q, 'function \(\k*()\)', '\1', 'g')) 36542205551SBram Moolenaar 36642205551SBram Moolenaar" If there is an extra argument filter the function names against it. 36742205551SBram Moolenaarif argc() > 1 36842205551SBram Moolenaar let s:tests = filter(s:tests, 'v:val =~ argv(1)') 36942205551SBram Moolenaarendif 37042205551SBram Moolenaar 37142205551SBram Moolenaar" Execute the tests in alphabetical order. 37242205551SBram Moolenaarfor s:test in sort(s:tests) 3734a6fcf80SBram Moolenaar " Silence, please! 3744a6fcf80SBram Moolenaar set belloff=all 375f77af0e6SBram Moolenaar let prev_error = '' 376f77af0e6SBram Moolenaar let total_errors = [] 377f77af0e6SBram Moolenaar let run_nr = 1 3784a6fcf80SBram Moolenaar 37942205551SBram Moolenaar call RunTheTest(s:test) 38042205551SBram Moolenaar 381f77af0e6SBram Moolenaar " Repeat a flaky test. Give up when: 382f77af0e6SBram Moolenaar " - it fails again with the same message 383f77af0e6SBram Moolenaar " - it fails five times (with a different mesage) 384dbc0d216SBram Moolenaar if len(v:errors) > 0 385dbc0d216SBram Moolenaar \ && (index(s:flaky_tests, s:test) >= 0 386dbc0d216SBram Moolenaar \ || v:errors[0] =~ s:flaky_errors_re) 387f77af0e6SBram Moolenaar while 1 3886caf606bSBram Moolenaar call add(s:messages, 'Found errors in ' . s:test . ':') 3896caf606bSBram Moolenaar call extend(s:messages, v:errors) 39015e737f7SBram Moolenaar 391f77af0e6SBram Moolenaar call add(total_errors, 'Run ' . run_nr . ':') 392f77af0e6SBram Moolenaar call extend(total_errors, v:errors) 393f77af0e6SBram Moolenaar 394f77af0e6SBram Moolenaar if run_nr == 5 || prev_error == v:errors[0] 395f77af0e6SBram Moolenaar call add(total_errors, 'Flaky test failed too often, giving up') 396f77af0e6SBram Moolenaar let v:errors = total_errors 397f77af0e6SBram Moolenaar break 398f77af0e6SBram Moolenaar endif 399f77af0e6SBram Moolenaar 400f77af0e6SBram Moolenaar call add(s:messages, 'Flaky test failed, running it again') 401f77af0e6SBram Moolenaar 402f77af0e6SBram Moolenaar " Flakiness is often caused by the system being very busy. Sleep a 403f77af0e6SBram Moolenaar " couple of seconds to have a higher chance of succeeding the second 404f77af0e6SBram Moolenaar " time. 40555058601SBram Moolenaar sleep 2 40655058601SBram Moolenaar 407f77af0e6SBram Moolenaar let prev_error = v:errors[0] 40842205551SBram Moolenaar let v:errors = [] 409f77af0e6SBram Moolenaar let run_nr += 1 410f77af0e6SBram Moolenaar 41142205551SBram Moolenaar call RunTheTest(s:test) 412f77af0e6SBram Moolenaar 413f77af0e6SBram Moolenaar if len(v:errors) == 0 414f77af0e6SBram Moolenaar " Test passed on rerun. 415f77af0e6SBram Moolenaar break 41615e737f7SBram Moolenaar endif 417f77af0e6SBram Moolenaar endwhile 41842205551SBram Moolenaar endif 41942205551SBram Moolenaar 42042205551SBram Moolenaar call AfterTheTest() 42142205551SBram Moolenaarendfor 42242205551SBram Moolenaar 42342205551SBram Moolenaarcall FinishTesting() 424cc28e2d0SBram Moolenaar 425cc28e2d0SBram Moolenaar" vim: shiftwidth=2 sts=2 expandtab 426