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