Bram Moolenaar | 4334554 | 2015-11-29 17:35:35 +0100 | [diff] [blame] | 1 | " This script is sourced while editing the .vim file with the tests. |
| 2 | " When the script is successful the .res file will be created. |
| 3 | " Errors are appended to the test.log file. |
| 4 | " |
Bram Moolenaar | befb366 | 2016-02-20 14:41:40 +0100 | [diff] [blame] | 5 | " To execute only specific test functions, add a second argument. It will be |
| 6 | " matched against the names of the Test_ funtion. E.g.: |
| 7 | " ../vim -u NONE -S runtest.vim test_channel.vim open_delay |
| 8 | " The output can be found in the "messages" file. |
| 9 | " |
Bram Moolenaar | 4334554 | 2015-11-29 17:35:35 +0100 | [diff] [blame] | 10 | " The test script may contain anything, only functions that start with |
| 11 | " "Test_" are special. These will be invoked and should contain assert |
| 12 | " functions. See test_assert.vim for an example. |
| 13 | " |
| 14 | " It is possible to source other files that contain "Test_" functions. This |
| 15 | " can speed up testing, since Vim does not need to restart. But be careful |
| 16 | " that the tests do not interfere with each other. |
| 17 | " |
| 18 | " If an error cannot be detected properly with an assert function add the |
| 19 | " error to the v:errors list: |
| 20 | " call add(v:errors, 'test foo failed: Cannot find xyz') |
| 21 | " |
| 22 | " If preparation for each Test_ function is needed, define a SetUp function. |
| 23 | " It will be called before each Test_ function. |
| 24 | " |
| 25 | " If cleanup after each Test_ function is needed, define a TearDown function. |
| 26 | " It will be called after each Test_ function. |
Bram Moolenaar | 00af60b | 2016-02-13 14:06:14 +0100 | [diff] [blame] | 27 | " |
| 28 | " When debugging a test it can be useful to add messages to v:errors: |
| 29 | " call add(v:errors, "this happened") |
| 30 | |
Bram Moolenaar | 4334554 | 2015-11-29 17:35:35 +0100 | [diff] [blame] | 31 | |
| 32 | " Without the +eval feature we can't run these tests, bail out. |
Bram Moolenaar | 4686b32 | 2015-12-28 14:44:10 +0100 | [diff] [blame] | 33 | so small.vim |
Bram Moolenaar | 4334554 | 2015-11-29 17:35:35 +0100 | [diff] [blame] | 34 | |
| 35 | " Check that the screen size is at least 24 x 80 characters. |
| 36 | if &lines < 24 || &columns < 80 |
| 37 | let error = 'Screen size too small! Tests require at least 24 lines with 80 characters' |
| 38 | echoerr error |
| 39 | split test.log |
| 40 | $put =error |
| 41 | w |
| 42 | cquit |
| 43 | endif |
| 44 | |
Bram Moolenaar | 89b1042 | 2016-07-12 22:51:22 +0200 | [diff] [blame] | 45 | " Common with all tests on all systems. |
| 46 | source setup.vim |
| 47 | |
Bram Moolenaar | c066246 | 2015-12-30 15:49:05 +0100 | [diff] [blame] | 48 | " For consistency run all tests with 'nocompatible' set. |
| 49 | " This also enables use of line continuation. |
| 50 | set nocp viminfo+=nviminfo |
| 51 | |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 52 | " Use utf-8 or latin1 by default, instead of whatever the system default |
Bram Moolenaar | ac105ed | 2016-07-21 20:33:32 +0200 | [diff] [blame] | 53 | " happens to be. Individual tests can overrule this at the top of the file. |
| 54 | if has('multi_byte') |
| 55 | set encoding=utf-8 |
| 56 | else |
| 57 | set encoding=latin1 |
| 58 | endif |
| 59 | |
Bram Moolenaar | d8f27b3 | 2018-10-07 15:42:07 +0200 | [diff] [blame] | 60 | " REDIR_TEST_TO_NULL has a very permissive SwapExists autocommand which is for |
| 61 | " the test_name.vim file itself. Replace it here with a more restrictive one, |
| 62 | " so we still catch mistakes. |
| 63 | let s:test_script_fname = expand('%') |
| 64 | au! SwapExists * call HandleSwapExists() |
| 65 | func HandleSwapExists() |
| 66 | " Only ignore finding a swap file for the test script (the user might be |
| 67 | " editing it and do ":make test_name") and the output file. |
| 68 | if expand('<afile>') == 'messages' || expand('<afile>') =~ s:test_script_fname |
| 69 | let v:swapchoice = 'e' |
| 70 | endif |
| 71 | endfunc |
| 72 | |
Bram Moolenaar | 7a07354 | 2017-02-01 23:17:36 +0100 | [diff] [blame] | 73 | " Avoid stopping at the "hit enter" prompt |
| 74 | set nomore |
| 75 | |
Bram Moolenaar | c066246 | 2015-12-30 15:49:05 +0100 | [diff] [blame] | 76 | " Output all messages in English. |
| 77 | lang mess C |
| 78 | |
Bram Moolenaar | f60b796 | 2016-01-16 22:47:23 +0100 | [diff] [blame] | 79 | " Always use forward slashes. |
| 80 | set shellslash |
| 81 | |
Bram Moolenaar | 28fb79d | 2016-01-09 22:28:33 +0100 | [diff] [blame] | 82 | let s:srcdir = expand('%:p:h:h') |
| 83 | |
Bram Moolenaar | 8e8df25 | 2016-05-25 21:23:21 +0200 | [diff] [blame] | 84 | " Prepare for calling test_garbagecollect_now(). |
Bram Moolenaar | ebf7dfa | 2016-04-14 12:46:51 +0200 | [diff] [blame] | 85 | let v:testing = 1 |
| 86 | |
Bram Moolenaar | 28fb79d | 2016-01-09 22:28:33 +0100 | [diff] [blame] | 87 | " Support function: get the alloc ID by name. |
| 88 | function GetAllocId(name) |
| 89 | exe 'split ' . s:srcdir . '/alloc.h' |
Bram Moolenaar | 065ee9a | 2016-01-15 20:53:38 +0100 | [diff] [blame] | 90 | let top = search('typedef enum') |
| 91 | if top == 0 |
| 92 | call add(v:errors, 'typedef not found in alloc.h') |
| 93 | endif |
Bram Moolenaar | 28fb79d | 2016-01-09 22:28:33 +0100 | [diff] [blame] | 94 | let lnum = search('aid_' . a:name . ',') |
| 95 | if lnum == 0 |
| 96 | call add(v:errors, 'Alloc ID ' . a:name . ' not defined') |
| 97 | endif |
| 98 | close |
Bram Moolenaar | 065ee9a | 2016-01-15 20:53:38 +0100 | [diff] [blame] | 99 | return lnum - top - 1 |
Bram Moolenaar | 28fb79d | 2016-01-09 22:28:33 +0100 | [diff] [blame] | 100 | endfunc |
| 101 | |
Bram Moolenaar | 4220555 | 2017-03-18 19:42:22 +0100 | [diff] [blame] | 102 | func RunTheTest(test) |
Bram Moolenaar | b5760a1 | 2016-03-03 13:10:44 +0100 | [diff] [blame] | 103 | echo 'Executing ' . a:test |
Bram Moolenaar | e5f2a07 | 2017-02-01 22:31:49 +0100 | [diff] [blame] | 104 | |
| 105 | " Avoid stopping at the "hit enter" prompt |
| 106 | set nomore |
| 107 | |
| 108 | " Avoid a three second wait when a message is about to be overwritten by the |
| 109 | " mode message. |
| 110 | set noshowmode |
| 111 | |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 112 | " Clear any overrides. |
| 113 | call test_override('ALL', 0) |
| 114 | |
Bram Moolenaar | cf1ba35 | 2017-10-27 00:55:04 +0200 | [diff] [blame] | 115 | " Some tests wipe out buffers. To be consistent, always wipe out all |
| 116 | " buffers. |
| 117 | %bwipe! |
| 118 | |
Bram Moolenaar | 209d387 | 2017-11-16 21:52:51 +0100 | [diff] [blame] | 119 | " The test may change the current directory. Save and restore the |
| 120 | " directory after executing the test. |
| 121 | let save_cwd = getcwd() |
| 122 | |
Bram Moolenaar | b5760a1 | 2016-03-03 13:10:44 +0100 | [diff] [blame] | 123 | if exists("*SetUp") |
Bram Moolenaar | cc28e2d | 2016-11-17 17:56:13 +0100 | [diff] [blame] | 124 | try |
| 125 | call SetUp() |
| 126 | catch |
| 127 | call add(v:errors, 'Caught exception in SetUp() before ' . a:test . ': ' . v:exception . ' @ ' . v:throwpoint) |
| 128 | endtry |
Bram Moolenaar | b5760a1 | 2016-03-03 13:10:44 +0100 | [diff] [blame] | 129 | endif |
| 130 | |
| 131 | call add(s:messages, 'Executing ' . a:test) |
| 132 | let s:done += 1 |
Bram Moolenaar | f204e05 | 2017-10-26 17:14:01 +0200 | [diff] [blame] | 133 | |
| 134 | if a:test =~ 'Test_nocatch_' |
| 135 | " Function handles errors itself. This avoids skipping commands after the |
| 136 | " error. |
Bram Moolenaar | b5760a1 | 2016-03-03 13:10:44 +0100 | [diff] [blame] | 137 | exe 'call ' . a:test |
Bram Moolenaar | f204e05 | 2017-10-26 17:14:01 +0200 | [diff] [blame] | 138 | else |
| 139 | try |
Bram Moolenaar | 8903676 | 2018-06-12 14:58:39 +0200 | [diff] [blame] | 140 | let s:test = a:test |
| 141 | au VimLeavePre * call EarlyExit(s:test) |
Bram Moolenaar | f204e05 | 2017-10-26 17:14:01 +0200 | [diff] [blame] | 142 | exe 'call ' . a:test |
Bram Moolenaar | 8903676 | 2018-06-12 14:58:39 +0200 | [diff] [blame] | 143 | au! VimLeavePre |
Bram Moolenaar | f204e05 | 2017-10-26 17:14:01 +0200 | [diff] [blame] | 144 | catch /^\cskipped/ |
| 145 | call add(s:messages, ' Skipped') |
| 146 | call add(s:skipped, 'SKIPPED ' . a:test . ': ' . substitute(v:exception, '^\S*\s\+', '', '')) |
| 147 | catch |
| 148 | call add(v:errors, 'Caught exception in ' . a:test . ': ' . v:exception . ' @ ' . v:throwpoint) |
| 149 | endtry |
| 150 | endif |
Bram Moolenaar | b5760a1 | 2016-03-03 13:10:44 +0100 | [diff] [blame] | 151 | |
| 152 | if exists("*TearDown") |
Bram Moolenaar | cc28e2d | 2016-11-17 17:56:13 +0100 | [diff] [blame] | 153 | try |
| 154 | call TearDown() |
| 155 | catch |
| 156 | call add(v:errors, 'Caught exception in TearDown() after ' . a:test . ': ' . v:exception . ' @ ' . v:throwpoint) |
| 157 | endtry |
Bram Moolenaar | b5760a1 | 2016-03-03 13:10:44 +0100 | [diff] [blame] | 158 | endif |
Bram Moolenaar | 7cba71d | 2016-08-02 23:04:49 +0200 | [diff] [blame] | 159 | |
Bram Moolenaar | cf1ba35 | 2017-10-27 00:55:04 +0200 | [diff] [blame] | 160 | " Clear any autocommands |
| 161 | au! |
Bram Moolenaar | d8f27b3 | 2018-10-07 15:42:07 +0200 | [diff] [blame] | 162 | au SwapExists * call HandleSwapExists() |
Bram Moolenaar | cf1ba35 | 2017-10-27 00:55:04 +0200 | [diff] [blame] | 163 | |
Bram Moolenaar | ce11de8 | 2017-10-26 22:00:00 +0200 | [diff] [blame] | 164 | " Close any extra tab pages and windows and make the current one not modified. |
| 165 | while tabpagenr('$') > 1 |
Bram Moolenaar | cf1ba35 | 2017-10-27 00:55:04 +0200 | [diff] [blame] | 166 | quit! |
Bram Moolenaar | ce11de8 | 2017-10-26 22:00:00 +0200 | [diff] [blame] | 167 | endwhile |
| 168 | |
Bram Moolenaar | 358308d | 2016-08-24 21:21:26 +0200 | [diff] [blame] | 169 | while 1 |
| 170 | let wincount = winnr('$') |
| 171 | if wincount == 1 |
| 172 | break |
| 173 | endif |
Bram Moolenaar | 7cba71d | 2016-08-02 23:04:49 +0200 | [diff] [blame] | 174 | bwipe! |
Bram Moolenaar | 358308d | 2016-08-24 21:21:26 +0200 | [diff] [blame] | 175 | if wincount == winnr('$') |
| 176 | " Did not manage to close a window. |
| 177 | only! |
| 178 | break |
| 179 | endif |
Bram Moolenaar | 7cba71d | 2016-08-02 23:04:49 +0200 | [diff] [blame] | 180 | endwhile |
Bram Moolenaar | 209d387 | 2017-11-16 21:52:51 +0100 | [diff] [blame] | 181 | |
| 182 | exe 'cd ' . save_cwd |
Bram Moolenaar | b5760a1 | 2016-03-03 13:10:44 +0100 | [diff] [blame] | 183 | endfunc |
Bram Moolenaar | 28fb79d | 2016-01-09 22:28:33 +0100 | [diff] [blame] | 184 | |
Bram Moolenaar | 4220555 | 2017-03-18 19:42:22 +0100 | [diff] [blame] | 185 | func AfterTheTest() |
| 186 | if len(v:errors) > 0 |
| 187 | let s:fail += 1 |
| 188 | call add(s:errors, 'Found errors in ' . s:test . ':') |
| 189 | call extend(s:errors, v:errors) |
| 190 | let v:errors = [] |
| 191 | endif |
| 192 | endfunc |
| 193 | |
Bram Moolenaar | 8903676 | 2018-06-12 14:58:39 +0200 | [diff] [blame] | 194 | func EarlyExit(test) |
| 195 | " It's OK for the test we use to test the quit detection. |
| 196 | if a:test != 'Test_zz_quit_detected()' |
| 197 | call add(v:errors, 'Test caused Vim to exit: ' . a:test) |
| 198 | endif |
| 199 | |
| 200 | call FinishTesting() |
| 201 | endfunc |
| 202 | |
Bram Moolenaar | 4220555 | 2017-03-18 19:42:22 +0100 | [diff] [blame] | 203 | " This function can be called by a test if it wants to abort testing. |
| 204 | func FinishTesting() |
| 205 | call AfterTheTest() |
| 206 | |
| 207 | " Don't write viminfo on exit. |
| 208 | set viminfo= |
| 209 | |
Bram Moolenaar | d1ee004 | 2017-07-29 20:39:53 +0200 | [diff] [blame] | 210 | " Clean up files created by setup.vim |
| 211 | call delete('XfakeHOME', 'rf') |
| 212 | |
Bram Moolenaar | 4220555 | 2017-03-18 19:42:22 +0100 | [diff] [blame] | 213 | if s:fail == 0 |
| 214 | " Success, create the .res file so that make knows it's done. |
| 215 | exe 'split ' . fnamemodify(g:testname, ':r') . '.res' |
| 216 | write |
| 217 | endif |
| 218 | |
| 219 | if len(s:errors) > 0 |
| 220 | " Append errors to test.log |
| 221 | split test.log |
| 222 | call append(line('$'), '') |
| 223 | call append(line('$'), 'From ' . g:testname . ':') |
| 224 | call append(line('$'), s:errors) |
| 225 | write |
| 226 | endif |
| 227 | |
Bram Moolenaar | 29f9ed2 | 2018-04-10 19:20:31 +0200 | [diff] [blame] | 228 | if s:done == 0 |
| 229 | let message = 'NO tests executed' |
| 230 | else |
| 231 | let message = 'Executed ' . s:done . (s:done > 1 ? ' tests' : ' test') |
| 232 | endif |
Bram Moolenaar | 4220555 | 2017-03-18 19:42:22 +0100 | [diff] [blame] | 233 | echo message |
| 234 | call add(s:messages, message) |
| 235 | if s:fail > 0 |
| 236 | let message = s:fail . ' FAILED:' |
| 237 | echo message |
| 238 | call add(s:messages, message) |
| 239 | call extend(s:messages, s:errors) |
| 240 | endif |
| 241 | |
| 242 | " Add SKIPPED messages |
| 243 | call extend(s:messages, s:skipped) |
| 244 | |
| 245 | " Append messages to the file "messages" |
| 246 | split messages |
| 247 | call append(line('$'), '') |
| 248 | call append(line('$'), 'From ' . g:testname . ':') |
| 249 | call append(line('$'), s:messages) |
| 250 | write |
| 251 | |
| 252 | qall! |
| 253 | endfunc |
| 254 | |
Bram Moolenaar | 4334554 | 2015-11-29 17:35:35 +0100 | [diff] [blame] | 255 | " Source the test script. First grab the file name, in case the script |
Bram Moolenaar | 00af60b | 2016-02-13 14:06:14 +0100 | [diff] [blame] | 256 | " navigates away. g:testname can be used by the tests. |
| 257 | let g:testname = expand('%') |
| 258 | let s:done = 0 |
| 259 | let s:fail = 0 |
| 260 | let s:errors = [] |
| 261 | let s:messages = [] |
Bram Moolenaar | dac1947 | 2016-09-03 22:35:40 +0200 | [diff] [blame] | 262 | let s:skipped = [] |
Bram Moolenaar | b544f3c | 2017-02-23 19:03:28 +0100 | [diff] [blame] | 263 | if expand('%') =~ 'test_vimscript.vim' |
Bram Moolenaar | 00af60b | 2016-02-13 14:06:14 +0100 | [diff] [blame] | 264 | " this test has intentional s:errors, don't use try/catch. |
Bram Moolenaar | 4686b32 | 2015-12-28 14:44:10 +0100 | [diff] [blame] | 265 | source % |
Bram Moolenaar | a2cce86 | 2016-01-02 19:50:04 +0100 | [diff] [blame] | 266 | else |
| 267 | try |
| 268 | source % |
| 269 | catch |
Bram Moolenaar | 00af60b | 2016-02-13 14:06:14 +0100 | [diff] [blame] | 270 | let s:fail += 1 |
| 271 | call add(s:errors, 'Caught exception: ' . v:exception . ' @ ' . v:throwpoint) |
Bram Moolenaar | a2cce86 | 2016-01-02 19:50:04 +0100 | [diff] [blame] | 272 | endtry |
| 273 | endif |
Bram Moolenaar | 4334554 | 2015-11-29 17:35:35 +0100 | [diff] [blame] | 274 | |
Bram Moolenaar | b5760a1 | 2016-03-03 13:10:44 +0100 | [diff] [blame] | 275 | " Names of flaky tests. |
Bram Moolenaar | dbc0d21 | 2018-11-16 18:22:45 +0100 | [diff] [blame] | 276 | let s:flaky_tests = [ |
Bram Moolenaar | c0f05d0 | 2018-11-16 17:44:48 +0100 | [diff] [blame] | 277 | \ 'Test_call()', |
| 278 | \ 'Test_channel_handler()', |
Bram Moolenaar | 4220555 | 2017-03-18 19:42:22 +0100 | [diff] [blame] | 279 | \ 'Test_client_server()', |
Bram Moolenaar | 6fe2eb4 | 2017-01-29 21:49:51 +0100 | [diff] [blame] | 280 | \ 'Test_close_and_exit_cb()', |
Bram Moolenaar | c0f05d0 | 2018-11-16 17:44:48 +0100 | [diff] [blame] | 281 | \ 'Test_close_callback()', |
| 282 | \ 'Test_close_handle()', |
| 283 | \ 'Test_close_lambda()', |
| 284 | \ 'Test_close_partial()', |
Bram Moolenaar | b245559 | 2017-02-01 18:00:13 +0100 | [diff] [blame] | 285 | \ 'Test_collapse_buffers()', |
| 286 | \ 'Test_communicate()', |
Bram Moolenaar | 6587384 | 2018-03-25 17:12:58 +0200 | [diff] [blame] | 287 | \ 'Test_cwd()', |
Bram Moolenaar | 218959b | 2018-11-11 18:51:42 +0100 | [diff] [blame] | 288 | \ 'Test_diff_screen()', |
Bram Moolenaar | c0f05d0 | 2018-11-16 17:44:48 +0100 | [diff] [blame] | 289 | \ 'Test_exit_callback()', |
Bram Moolenaar | 0529b3e | 2017-03-16 22:30:37 +0100 | [diff] [blame] | 290 | \ 'Test_exit_callback_interval()', |
Bram Moolenaar | b245559 | 2017-02-01 18:00:13 +0100 | [diff] [blame] | 291 | \ 'Test_nb_basic()', |
Bram Moolenaar | d512e17 | 2017-02-27 21:35:53 +0100 | [diff] [blame] | 292 | \ 'Test_oneshot()', |
Bram Moolenaar | c0f05d0 | 2018-11-16 17:44:48 +0100 | [diff] [blame] | 293 | \ 'Test_open_delay()', |
Bram Moolenaar | 1eca6f1 | 2017-12-05 14:04:27 +0100 | [diff] [blame] | 294 | \ 'Test_out_cb()', |
Bram Moolenaar | 2482069 | 2017-12-02 16:38:12 +0100 | [diff] [blame] | 295 | \ 'Test_paused()', |
Bram Moolenaar | c79d6aa | 2016-09-25 22:27:37 +0200 | [diff] [blame] | 296 | \ 'Test_pipe_through_sort_all()', |
Bram Moolenaar | 4e032e1 | 2017-02-01 20:48:13 +0100 | [diff] [blame] | 297 | \ 'Test_pipe_through_sort_some()', |
Bram Moolenaar | 142ae73 | 2018-08-19 17:04:01 +0200 | [diff] [blame] | 298 | \ 'Test_popup_and_window_resize()', |
Bram Moolenaar | 0fbff64 | 2017-03-05 14:30:52 +0100 | [diff] [blame] | 299 | \ 'Test_quoteplus()', |
Bram Moolenaar | 7dd4850 | 2017-03-19 20:04:22 +0100 | [diff] [blame] | 300 | \ 'Test_quotestar()', |
Bram Moolenaar | c0f05d0 | 2018-11-16 17:44:48 +0100 | [diff] [blame] | 301 | \ 'Test_raw_one_time_callback()', |
Bram Moolenaar | b245559 | 2017-02-01 18:00:13 +0100 | [diff] [blame] | 302 | \ 'Test_reltime()', |
Bram Moolenaar | bfbea56 | 2018-02-12 21:31:35 +0100 | [diff] [blame] | 303 | \ 'Test_repeat_three()', |
Bram Moolenaar | c0f05d0 | 2018-11-16 17:44:48 +0100 | [diff] [blame] | 304 | \ 'Test_server_crash()', |
| 305 | \ 'Test_terminal_ansicolors_default()', |
| 306 | \ 'Test_terminal_ansicolors_func()', |
| 307 | \ 'Test_terminal_ansicolors_global()', |
Bram Moolenaar | f204e05 | 2017-10-26 17:14:01 +0200 | [diff] [blame] | 308 | \ 'Test_terminal_composing_unicode()', |
Bram Moolenaar | c0f05d0 | 2018-11-16 17:44:48 +0100 | [diff] [blame] | 309 | \ 'Test_terminal_env()', |
| 310 | \ 'Test_terminal_hide_buffer()', |
| 311 | \ 'Test_terminal_make_change()', |
Bram Moolenaar | 75a60f7 | 2017-09-07 22:24:41 +0200 | [diff] [blame] | 312 | \ 'Test_terminal_noblock()', |
Bram Moolenaar | 7dd88c5 | 2017-11-04 20:46:40 +0100 | [diff] [blame] | 313 | \ 'Test_terminal_redir_file()', |
Bram Moolenaar | c0f05d0 | 2018-11-16 17:44:48 +0100 | [diff] [blame] | 314 | \ 'Test_terminal_response_to_control_sequence()', |
| 315 | \ 'Test_terminal_scrollback()', |
| 316 | \ 'Test_terminal_split_quit()', |
| 317 | \ 'Test_terminal_termwinkey()', |
| 318 | \ 'Test_terminal_termwinsize_mininmum()', |
| 319 | \ 'Test_terminal_termwinsize_option_fixed()', |
| 320 | \ 'Test_terminal_termwinsize_option_zero()', |
Bram Moolenaar | 2482069 | 2017-12-02 16:38:12 +0100 | [diff] [blame] | 321 | \ 'Test_terminal_tmap()', |
Bram Moolenaar | c0f05d0 | 2018-11-16 17:44:48 +0100 | [diff] [blame] | 322 | \ 'Test_terminal_wall()', |
| 323 | \ 'Test_terminal_wipe_buffer()', |
| 324 | \ 'Test_terminal_wqall()', |
| 325 | \ 'Test_two_channels()', |
| 326 | \ 'Test_unlet_handle()', |
Bram Moolenaar | d09be32 | 2017-07-30 21:37:58 +0200 | [diff] [blame] | 327 | \ 'Test_with_partial_callback()', |
Bram Moolenaar | c0f05d0 | 2018-11-16 17:44:48 +0100 | [diff] [blame] | 328 | \ 'Test_zero_reply()', |
| 329 | \ 'Test_zz1_terminal_in_gui()', |
Bram Moolenaar | e1c8c7a | 2016-09-11 16:48:50 +0200 | [diff] [blame] | 330 | \ ] |
Bram Moolenaar | b5760a1 | 2016-03-03 13:10:44 +0100 | [diff] [blame] | 331 | |
Bram Moolenaar | dbc0d21 | 2018-11-16 18:22:45 +0100 | [diff] [blame] | 332 | " Pattern indicating a common flaky test failure. |
Bram Moolenaar | 447f6ce | 2018-11-16 18:50:19 +0100 | [diff] [blame] | 333 | let s:flaky_errors_re = 'StopVimInTerminal\|VerifyScreenDump' |
Bram Moolenaar | dbc0d21 | 2018-11-16 18:22:45 +0100 | [diff] [blame] | 334 | |
Bram Moolenaar | 4334554 | 2015-11-29 17:35:35 +0100 | [diff] [blame] | 335 | " Locate Test_ functions and execute them. |
| 336 | redir @q |
Bram Moolenaar | 93bf558 | 2016-02-18 22:25:47 +0100 | [diff] [blame] | 337 | silent function /^Test_ |
Bram Moolenaar | 4334554 | 2015-11-29 17:35:35 +0100 | [diff] [blame] | 338 | redir END |
Bram Moolenaar | 00af60b | 2016-02-13 14:06:14 +0100 | [diff] [blame] | 339 | let s:tests = split(substitute(@q, 'function \(\k*()\)', '\1', 'g')) |
Bram Moolenaar | 4334554 | 2015-11-29 17:35:35 +0100 | [diff] [blame] | 340 | |
Bram Moolenaar | befb366 | 2016-02-20 14:41:40 +0100 | [diff] [blame] | 341 | " If there is an extra argument filter the function names against it. |
| 342 | if argc() > 1 |
| 343 | let s:tests = filter(s:tests, 'v:val =~ argv(1)') |
| 344 | endif |
| 345 | |
Bram Moolenaar | cfc0a35 | 2016-01-09 20:23:00 +0100 | [diff] [blame] | 346 | " Execute the tests in alphabetical order. |
Bram Moolenaar | 93bf558 | 2016-02-18 22:25:47 +0100 | [diff] [blame] | 347 | for s:test in sort(s:tests) |
Bram Moolenaar | 4a6fcf8 | 2017-10-12 21:29:22 +0200 | [diff] [blame] | 348 | " Silence, please! |
| 349 | set belloff=all |
Bram Moolenaar | f77af0e | 2018-11-16 16:52:16 +0100 | [diff] [blame] | 350 | let prev_error = '' |
| 351 | let total_errors = [] |
| 352 | let run_nr = 1 |
Bram Moolenaar | 4a6fcf8 | 2017-10-12 21:29:22 +0200 | [diff] [blame] | 353 | |
Bram Moolenaar | b5760a1 | 2016-03-03 13:10:44 +0100 | [diff] [blame] | 354 | call RunTheTest(s:test) |
Bram Moolenaar | 4334554 | 2015-11-29 17:35:35 +0100 | [diff] [blame] | 355 | |
Bram Moolenaar | f77af0e | 2018-11-16 16:52:16 +0100 | [diff] [blame] | 356 | " Repeat a flaky test. Give up when: |
| 357 | " - it fails again with the same message |
| 358 | " - it fails five times (with a different mesage) |
Bram Moolenaar | dbc0d21 | 2018-11-16 18:22:45 +0100 | [diff] [blame] | 359 | if len(v:errors) > 0 |
| 360 | \ && (index(s:flaky_tests, s:test) >= 0 |
| 361 | \ || v:errors[0] =~ s:flaky_errors_re) |
Bram Moolenaar | f77af0e | 2018-11-16 16:52:16 +0100 | [diff] [blame] | 362 | while 1 |
| 363 | call add(s:messages, 'Found errors in ' . s:test . ':') |
| 364 | call extend(s:messages, v:errors) |
Bram Moolenaar | 15e737f | 2017-03-18 21:22:47 +0100 | [diff] [blame] | 365 | |
Bram Moolenaar | f77af0e | 2018-11-16 16:52:16 +0100 | [diff] [blame] | 366 | call add(total_errors, 'Run ' . run_nr . ':') |
| 367 | call extend(total_errors, v:errors) |
Bram Moolenaar | 5505860 | 2017-11-21 15:14:51 +0100 | [diff] [blame] | 368 | |
Bram Moolenaar | f77af0e | 2018-11-16 16:52:16 +0100 | [diff] [blame] | 369 | if run_nr == 5 || prev_error == v:errors[0] |
| 370 | call add(total_errors, 'Flaky test failed too often, giving up') |
| 371 | let v:errors = total_errors |
| 372 | break |
| 373 | endif |
| 374 | |
| 375 | call add(s:messages, 'Flaky test failed, running it again') |
| 376 | |
| 377 | " Flakiness is often caused by the system being very busy. Sleep a |
| 378 | " couple of seconds to have a higher chance of succeeding the second |
| 379 | " time. |
| 380 | sleep 2 |
| 381 | |
| 382 | let prev_error = v:errors[0] |
| 383 | let v:errors = [] |
| 384 | let run_nr += 1 |
| 385 | |
| 386 | call RunTheTest(s:test) |
| 387 | |
| 388 | if len(v:errors) == 0 |
| 389 | " Test passed on rerun. |
| 390 | break |
| 391 | endif |
| 392 | endwhile |
Bram Moolenaar | b5760a1 | 2016-03-03 13:10:44 +0100 | [diff] [blame] | 393 | endif |
Bram Moolenaar | 4334554 | 2015-11-29 17:35:35 +0100 | [diff] [blame] | 394 | |
Bram Moolenaar | 4220555 | 2017-03-18 19:42:22 +0100 | [diff] [blame] | 395 | call AfterTheTest() |
Bram Moolenaar | 4334554 | 2015-11-29 17:35:35 +0100 | [diff] [blame] | 396 | endfor |
| 397 | |
Bram Moolenaar | 4220555 | 2017-03-18 19:42:22 +0100 | [diff] [blame] | 398 | call FinishTesting() |
Bram Moolenaar | cc28e2d | 2016-11-17 17:56:13 +0100 | [diff] [blame] | 399 | |
| 400 | " vim: shiftwidth=2 sts=2 expandtab |