Bram Moolenaar | 321efdd | 2016-07-15 17:09:11 +0200 | [diff] [blame] | 1 | " Functions shared by several tests. |
| 2 | |
Bram Moolenaar | a5e6621 | 2017-09-29 22:42:33 +0200 | [diff] [blame] | 3 | " Only load this script once. |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 4 | if exists('*PythonProg') |
Bram Moolenaar | a5e6621 | 2017-09-29 22:42:33 +0200 | [diff] [blame] | 5 | finish |
| 6 | endif |
| 7 | |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 8 | source view_util.vim |
| 9 | |
Bram Moolenaar | 321efdd | 2016-07-15 17:09:11 +0200 | [diff] [blame] | 10 | " Get the name of the Python executable. |
| 11 | " Also keeps it in s:python. |
| 12 | func PythonProg() |
| 13 | " This test requires the Python command to run the test server. |
| 14 | " This most likely only works on Unix and Windows. |
| 15 | if has('unix') |
| 16 | " We also need the job feature or the pkill command to make sure the server |
| 17 | " can be stopped. |
LemonBoy | cc766a8 | 2022-04-04 15:46:58 +0100 | [diff] [blame] | 18 | if !(has('job') || executable('pkill')) |
Bram Moolenaar | 321efdd | 2016-07-15 17:09:11 +0200 | [diff] [blame] | 19 | return '' |
| 20 | endif |
LemonBoy | cc766a8 | 2022-04-04 15:46:58 +0100 | [diff] [blame] | 21 | if executable('python') |
| 22 | let s:python = 'python' |
| 23 | elseif executable('python3') |
| 24 | let s:python = 'python3' |
| 25 | else |
| 26 | return '' |
| 27 | end |
Bram Moolenaar | 321efdd | 2016-07-15 17:09:11 +0200 | [diff] [blame] | 28 | elseif has('win32') |
| 29 | " Use Python Launcher for Windows (py.exe) if available. |
Bram Moolenaar | 1bb0da2 | 2021-05-02 19:15:05 +0200 | [diff] [blame] | 30 | " NOTE: if you get a "Python was not found" error, disable the Python |
| 31 | " shortcuts in "Windows menu / Settings / Manage App Execution Aliases". |
Bram Moolenaar | 321efdd | 2016-07-15 17:09:11 +0200 | [diff] [blame] | 32 | if executable('py.exe') |
| 33 | let s:python = 'py.exe' |
| 34 | elseif executable('python.exe') |
| 35 | let s:python = 'python.exe' |
| 36 | else |
| 37 | return '' |
| 38 | endif |
| 39 | else |
| 40 | return '' |
| 41 | endif |
| 42 | return s:python |
| 43 | endfunc |
| 44 | |
| 45 | " Run "cmd". Returns the job if using a job. |
| 46 | func RunCommand(cmd) |
Bram Moolenaar | 4a070cc | 2020-05-07 18:16:35 +0200 | [diff] [blame] | 47 | " Running an external command can occasionally be slow or fail. |
| 48 | let g:test_is_flaky = 1 |
| 49 | |
Bram Moolenaar | 321efdd | 2016-07-15 17:09:11 +0200 | [diff] [blame] | 50 | let job = 0 |
| 51 | if has('job') |
| 52 | let job = job_start(a:cmd, {"stoponexit": "hup"}) |
| 53 | call job_setoptions(job, {"stoponexit": "kill"}) |
| 54 | elseif has('win32') |
| 55 | exe 'silent !start cmd /c start "test_channel" ' . a:cmd |
| 56 | else |
| 57 | exe 'silent !' . a:cmd . '&' |
| 58 | endif |
| 59 | return job |
| 60 | endfunc |
| 61 | |
| 62 | " Read the port number from the Xportnr file. |
| 63 | func GetPort() |
| 64 | let l = [] |
Bram Moolenaar | 453ce7c | 2018-10-12 22:15:12 +0200 | [diff] [blame] | 65 | " with 200 it sometimes failed |
| 66 | for i in range(400) |
Bram Moolenaar | 321efdd | 2016-07-15 17:09:11 +0200 | [diff] [blame] | 67 | try |
| 68 | let l = readfile("Xportnr") |
| 69 | catch |
| 70 | endtry |
| 71 | if len(l) >= 1 |
| 72 | break |
| 73 | endif |
| 74 | sleep 10m |
| 75 | endfor |
| 76 | call delete("Xportnr") |
| 77 | |
| 78 | if len(l) == 0 |
| 79 | " Can't make the connection, give up. |
| 80 | return 0 |
| 81 | endif |
| 82 | return l[0] |
| 83 | endfunc |
| 84 | |
| 85 | " Run a Python server for "cmd" and call "testfunc". |
| 86 | " Always kills the server before returning. |
| 87 | func RunServer(cmd, testfunc, args) |
| 88 | " The Python program writes the port number in Xportnr. |
| 89 | call delete("Xportnr") |
| 90 | |
| 91 | if len(a:args) == 1 |
| 92 | let arg = ' ' . a:args[0] |
| 93 | else |
| 94 | let arg = '' |
| 95 | endif |
| 96 | let pycmd = s:python . " " . a:cmd . arg |
| 97 | |
| 98 | try |
| 99 | let g:currentJob = RunCommand(pycmd) |
| 100 | |
| 101 | " Wait for up to 2 seconds for the port number to be there. |
| 102 | let port = GetPort() |
| 103 | if port == 0 |
| 104 | call assert_false(1, "Can't start " . a:cmd) |
| 105 | return |
| 106 | endif |
| 107 | |
| 108 | call call(function(a:testfunc), [port]) |
| 109 | catch |
Bram Moolenaar | 4b785f6 | 2016-11-29 21:54:44 +0100 | [diff] [blame] | 110 | call assert_false(1, 'Caught exception: "' . v:exception . '" in ' . v:throwpoint) |
Bram Moolenaar | 321efdd | 2016-07-15 17:09:11 +0200 | [diff] [blame] | 111 | finally |
| 112 | call s:kill_server(a:cmd) |
| 113 | endtry |
| 114 | endfunc |
| 115 | |
| 116 | func s:kill_server(cmd) |
| 117 | if has('job') |
| 118 | if exists('g:currentJob') |
| 119 | call job_stop(g:currentJob) |
| 120 | unlet g:currentJob |
| 121 | endif |
| 122 | elseif has('win32') |
| 123 | let cmd = substitute(a:cmd, ".py", '', '') |
| 124 | call system('taskkill /IM ' . s:python . ' /T /F /FI "WINDOWTITLE eq ' . cmd . '"') |
| 125 | else |
| 126 | call system("pkill -f " . a:cmd) |
| 127 | endif |
| 128 | endfunc |
| 129 | |
Bram Moolenaar | 769e9d2 | 2018-04-11 20:53:49 +0200 | [diff] [blame] | 130 | " Wait for up to five seconds for "expr" to become true. "expr" can be a |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 131 | " stringified expression to evaluate, or a funcref without arguments. |
Bram Moolenaar | 50182fa | 2018-04-28 21:34:40 +0200 | [diff] [blame] | 132 | " Using a lambda works best. Example: |
| 133 | " call WaitFor({-> status == "ok"}) |
| 134 | " |
Bram Moolenaar | 5d7ead3 | 2018-02-27 17:17:42 +0100 | [diff] [blame] | 135 | " A second argument can be used to specify a different timeout in msec. |
Bram Moolenaar | 13deab8 | 2017-11-04 18:48:43 +0100 | [diff] [blame] | 136 | " |
Bram Moolenaar | 50182fa | 2018-04-28 21:34:40 +0200 | [diff] [blame] | 137 | " When successful the time slept is returned. |
| 138 | " When running into the timeout an exception is thrown, thus the function does |
| 139 | " not return. |
Bram Moolenaar | cdb7e1b | 2017-07-19 19:55:58 +0200 | [diff] [blame] | 140 | func WaitFor(expr, ...) |
Bram Moolenaar | 769e9d2 | 2018-04-11 20:53:49 +0200 | [diff] [blame] | 141 | let timeout = get(a:000, 0, 5000) |
Bram Moolenaar | 50182fa | 2018-04-28 21:34:40 +0200 | [diff] [blame] | 142 | let slept = s:WaitForCommon(a:expr, v:null, timeout) |
| 143 | if slept < 0 |
| 144 | throw 'WaitFor() timed out after ' . timeout . ' msec' |
| 145 | endif |
| 146 | return slept |
| 147 | endfunc |
| 148 | |
| 149 | " Wait for up to five seconds for "assert" to return zero. "assert" must be a |
| 150 | " (lambda) function containing one assert function. Example: |
| 151 | " call WaitForAssert({-> assert_equal("dead", job_status(job)}) |
| 152 | " |
| 153 | " A second argument can be used to specify a different timeout in msec. |
| 154 | " |
| 155 | " Return zero for success, one for failure (like the assert function). |
| 156 | func WaitForAssert(assert, ...) |
| 157 | let timeout = get(a:000, 0, 5000) |
| 158 | if s:WaitForCommon(v:null, a:assert, timeout) < 0 |
| 159 | return 1 |
| 160 | endif |
| 161 | return 0 |
| 162 | endfunc |
| 163 | |
| 164 | " Common implementation of WaitFor() and WaitForAssert(). |
| 165 | " Either "expr" or "assert" is not v:null |
| 166 | " Return the waiting time for success, -1 for failure. |
| 167 | func s:WaitForCommon(expr, assert, timeout) |
Bram Moolenaar | f267f8b | 2016-08-22 21:40:29 +0200 | [diff] [blame] | 168 | " using reltime() is more accurate, but not always available |
Bram Moolenaar | 50182fa | 2018-04-28 21:34:40 +0200 | [diff] [blame] | 169 | let slept = 0 |
Bram Moolenaar | 5feabe0 | 2020-01-30 18:24:53 +0100 | [diff] [blame] | 170 | if exists('*reltimefloat') |
Bram Moolenaar | f267f8b | 2016-08-22 21:40:29 +0200 | [diff] [blame] | 171 | let start = reltime() |
Bram Moolenaar | f267f8b | 2016-08-22 21:40:29 +0200 | [diff] [blame] | 172 | endif |
Bram Moolenaar | 50182fa | 2018-04-28 21:34:40 +0200 | [diff] [blame] | 173 | |
| 174 | while 1 |
| 175 | if type(a:expr) == v:t_func |
| 176 | let success = a:expr() |
| 177 | elseif type(a:assert) == v:t_func |
| 178 | let success = a:assert() == 0 |
| 179 | else |
| 180 | let success = eval(a:expr) |
| 181 | endif |
| 182 | if success |
Bram Moolenaar | c20e0d5 | 2017-11-02 18:19:19 +0100 | [diff] [blame] | 183 | return slept |
| 184 | endif |
Bram Moolenaar | 50182fa | 2018-04-28 21:34:40 +0200 | [diff] [blame] | 185 | |
| 186 | if slept >= a:timeout |
| 187 | break |
| 188 | endif |
| 189 | if type(a:assert) == v:t_func |
| 190 | " Remove the error added by the assert function. |
| 191 | call remove(v:errors, -1) |
| 192 | endif |
| 193 | |
| 194 | sleep 10m |
Bram Moolenaar | 5feabe0 | 2020-01-30 18:24:53 +0100 | [diff] [blame] | 195 | if exists('*reltimefloat') |
Bram Moolenaar | 50182fa | 2018-04-28 21:34:40 +0200 | [diff] [blame] | 196 | let slept = float2nr(reltimefloat(reltime(start)) * 1000) |
| 197 | else |
Bram Moolenaar | f267f8b | 2016-08-22 21:40:29 +0200 | [diff] [blame] | 198 | let slept += 10 |
| 199 | endif |
Bram Moolenaar | 50182fa | 2018-04-28 21:34:40 +0200 | [diff] [blame] | 200 | endwhile |
| 201 | |
| 202 | return -1 " timed out |
Bram Moolenaar | 321efdd | 2016-07-15 17:09:11 +0200 | [diff] [blame] | 203 | endfunc |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 204 | |
Bram Moolenaar | 50182fa | 2018-04-28 21:34:40 +0200 | [diff] [blame] | 205 | |
Bram Moolenaar | 01688ad | 2016-10-27 20:00:07 +0200 | [diff] [blame] | 206 | " Wait for up to a given milliseconds. |
| 207 | " With the +timers feature this waits for key-input by getchar(), Resume() |
| 208 | " feeds key-input and resumes process. Return time waited in milliseconds. |
| 209 | " Without +timers it uses simply :sleep. |
| 210 | func Standby(msec) |
Bram Moolenaar | 5feabe0 | 2020-01-30 18:24:53 +0100 | [diff] [blame] | 211 | if has('timers') && exists('*reltimefloat') |
Bram Moolenaar | 01688ad | 2016-10-27 20:00:07 +0200 | [diff] [blame] | 212 | let start = reltime() |
| 213 | let g:_standby_timer = timer_start(a:msec, function('s:feedkeys')) |
| 214 | call getchar() |
| 215 | return float2nr(reltimefloat(reltime(start)) * 1000) |
| 216 | else |
| 217 | execute 'sleep ' a:msec . 'm' |
| 218 | return a:msec |
| 219 | endif |
| 220 | endfunc |
| 221 | |
| 222 | func Resume() |
| 223 | if exists('g:_standby_timer') |
| 224 | call timer_stop(g:_standby_timer) |
| 225 | call s:feedkeys(0) |
| 226 | unlet g:_standby_timer |
| 227 | endif |
| 228 | endfunc |
| 229 | |
| 230 | func s:feedkeys(timer) |
| 231 | call feedkeys('x', 'nt') |
| 232 | endfunc |
| 233 | |
Bram Moolenaar | 2228689 | 2020-11-05 20:50:51 +0100 | [diff] [blame] | 234 | " Get $VIMPROG to run the Vim executable. |
Bram Moolenaar | 6318205 | 2017-10-07 20:03:23 +0200 | [diff] [blame] | 235 | " The Makefile writes it as the first line in the "vimcmd" file. |
| 236 | func GetVimProg() |
| 237 | if !filereadable('vimcmd') |
Bram Moolenaar | da65058 | 2018-02-20 15:51:40 +0100 | [diff] [blame] | 238 | " Assume the script was sourced instead of running "make". |
| 239 | return '../vim' |
Bram Moolenaar | 6318205 | 2017-10-07 20:03:23 +0200 | [diff] [blame] | 240 | endif |
| 241 | return readfile('vimcmd')[0] |
| 242 | endfunc |
| 243 | |
Bram Moolenaar | 248be5c | 2018-05-05 15:47:19 +0200 | [diff] [blame] | 244 | let g:valgrind_cnt = 1 |
| 245 | |
Bram Moolenaar | 15bf76d | 2017-03-18 16:18:37 +0100 | [diff] [blame] | 246 | " Get the command to run Vim, with -u NONE and --not-a-term arguments. |
Bram Moolenaar | 9d95420 | 2017-09-04 20:34:19 +0200 | [diff] [blame] | 247 | " If there is an argument use it instead of "NONE". |
Bram Moolenaar | 9d95420 | 2017-09-04 20:34:19 +0200 | [diff] [blame] | 248 | func GetVimCommand(...) |
Bram Moolenaar | 15bf76d | 2017-03-18 16:18:37 +0100 | [diff] [blame] | 249 | if !filereadable('vimcmd') |
Bram Moolenaar | da65058 | 2018-02-20 15:51:40 +0100 | [diff] [blame] | 250 | echo 'Cannot read the "vimcmd" file, falling back to ../vim.' |
Christian Brabandt | dfbdadc | 2022-05-05 20:46:47 +0100 | [diff] [blame] | 251 | if !has("win32") |
| 252 | let lines = ['../vim'] |
| 253 | else |
| 254 | let lines = ['..\vim.exe'] |
| 255 | endif |
Bram Moolenaar | da65058 | 2018-02-20 15:51:40 +0100 | [diff] [blame] | 256 | else |
| 257 | let lines = readfile('vimcmd') |
Bram Moolenaar | 15bf76d | 2017-03-18 16:18:37 +0100 | [diff] [blame] | 258 | endif |
Bram Moolenaar | 9d95420 | 2017-09-04 20:34:19 +0200 | [diff] [blame] | 259 | if a:0 == 0 |
| 260 | let name = 'NONE' |
| 261 | else |
| 262 | let name = a:1 |
| 263 | endif |
Bram Moolenaar | 6318205 | 2017-10-07 20:03:23 +0200 | [diff] [blame] | 264 | " For Unix Makefile writes the command to use in the second line of the |
| 265 | " "vimcmd" file, including environment options. |
| 266 | " Other Makefiles just write the executable in the first line, so fall back |
Bram Moolenaar | 248be5c | 2018-05-05 15:47:19 +0200 | [diff] [blame] | 267 | " to that if there is no second line or it is empty. |
| 268 | if len(lines) > 1 && lines[1] != '' |
| 269 | let cmd = lines[1] |
| 270 | else |
| 271 | let cmd = lines[0] |
| 272 | endif |
| 273 | |
Bram Moolenaar | 9d95420 | 2017-09-04 20:34:19 +0200 | [diff] [blame] | 274 | let cmd = substitute(cmd, '-u \f\+', '-u ' . name, '') |
| 275 | if cmd !~ '-u '. name |
| 276 | let cmd = cmd . ' -u ' . name |
Bram Moolenaar | 15bf76d | 2017-03-18 16:18:37 +0100 | [diff] [blame] | 277 | endif |
| 278 | let cmd .= ' --not-a-term' |
Bram Moolenaar | 41a8260 | 2019-07-14 21:54:26 +0200 | [diff] [blame] | 279 | let cmd = substitute(cmd, 'VIMRUNTIME=\S\+', '', '') |
Bram Moolenaar | 248be5c | 2018-05-05 15:47:19 +0200 | [diff] [blame] | 280 | |
| 281 | " If using valgrind, make sure every run uses a different log file. |
| 282 | if cmd =~ 'valgrind.*--log-file=' |
Bram Moolenaar | 657a826 | 2020-07-15 18:29:18 +0200 | [diff] [blame] | 283 | let cmd = substitute(cmd, '--log-file=\(\S*\)', '--log-file=\1.' . g:valgrind_cnt, '') |
Bram Moolenaar | 248be5c | 2018-05-05 15:47:19 +0200 | [diff] [blame] | 284 | let g:valgrind_cnt += 1 |
| 285 | endif |
| 286 | |
Bram Moolenaar | 15bf76d | 2017-03-18 16:18:37 +0100 | [diff] [blame] | 287 | return cmd |
| 288 | endfunc |
| 289 | |
Bram Moolenaar | f169996 | 2019-08-31 17:48:19 +0200 | [diff] [blame] | 290 | " Get the command to run Vim, with --clean instead of "-u NONE". |
Bram Moolenaar | da65058 | 2018-02-20 15:51:40 +0100 | [diff] [blame] | 291 | func GetVimCommandClean() |
| 292 | let cmd = GetVimCommand() |
| 293 | let cmd = substitute(cmd, '-u NONE', '--clean', '') |
| 294 | let cmd = substitute(cmd, '--not-a-term', '', '') |
Bram Moolenaar | 453ce7c | 2018-10-12 22:15:12 +0200 | [diff] [blame] | 295 | |
Bram Moolenaar | 0fdddee | 2019-09-01 15:26:23 +0200 | [diff] [blame] | 296 | " Force using utf-8, Vim may pick up something else from the environment. |
| 297 | let cmd ..= ' --cmd "set enc=utf8" ' |
| 298 | |
Bram Moolenaar | 453ce7c | 2018-10-12 22:15:12 +0200 | [diff] [blame] | 299 | " Optionally run Vim under valgrind |
| 300 | " let cmd = 'valgrind --tool=memcheck --leak-check=yes --num-callers=25 --log-file=valgrind ' . cmd |
| 301 | |
Bram Moolenaar | da65058 | 2018-02-20 15:51:40 +0100 | [diff] [blame] | 302 | return cmd |
| 303 | endfunc |
| 304 | |
Bram Moolenaar | 0d70202 | 2019-07-04 14:20:41 +0200 | [diff] [blame] | 305 | " Get the command to run Vim, with --clean, and force to run in terminal so it |
| 306 | " won't start a new GUI. |
| 307 | func GetVimCommandCleanTerm() |
| 308 | " Add -v to have gvim run in the terminal (if possible) |
| 309 | return GetVimCommandClean() .. ' -v ' |
| 310 | endfunc |
| 311 | |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 312 | " Run Vim, using the "vimcmd" file and "-u NORC". |
Bram Moolenaar | 3a93838 | 2016-08-07 16:36:40 +0200 | [diff] [blame] | 313 | " "before" is a list of Vim commands to be executed before loading plugins. |
| 314 | " "after" is a list of Vim commands to be executed after loading plugins. |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 315 | " Plugins are not loaded, unless 'loadplugins' is set in "before". |
| 316 | " Return 1 if Vim could be executed. |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 317 | func RunVim(before, after, arguments) |
Bram Moolenaar | 7a9a5f4 | 2016-08-08 22:34:14 +0200 | [diff] [blame] | 318 | return RunVimPiped(a:before, a:after, a:arguments, '') |
Bram Moolenaar | 3a93838 | 2016-08-07 16:36:40 +0200 | [diff] [blame] | 319 | endfunc |
| 320 | |
| 321 | func RunVimPiped(before, after, arguments, pipecmd) |
Bram Moolenaar | 15bf76d | 2017-03-18 16:18:37 +0100 | [diff] [blame] | 322 | let cmd = GetVimCommand() |
Bram Moolenaar | ba98bef | 2016-08-07 15:51:39 +0200 | [diff] [blame] | 323 | let args = '' |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 324 | if len(a:before) > 0 |
| 325 | call writefile(a:before, 'Xbefore.vim') |
| 326 | let args .= ' --cmd "so Xbefore.vim"' |
| 327 | endif |
| 328 | if len(a:after) > 0 |
| 329 | call writefile(a:after, 'Xafter.vim') |
| 330 | let args .= ' -S Xafter.vim' |
| 331 | endif |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 332 | |
Bram Moolenaar | f48ee3c | 2019-12-06 22:18:20 +0100 | [diff] [blame] | 333 | " Optionally run Vim under valgrind |
| 334 | " let cmd = 'valgrind --tool=memcheck --leak-check=yes --num-callers=25 --log-file=valgrind ' . cmd |
| 335 | |
Bram Moolenaar | 3a93838 | 2016-08-07 16:36:40 +0200 | [diff] [blame] | 336 | exe "silent !" . a:pipecmd . cmd . args . ' ' . a:arguments |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 337 | |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 338 | if len(a:before) > 0 |
| 339 | call delete('Xbefore.vim') |
| 340 | endif |
| 341 | if len(a:after) > 0 |
| 342 | call delete('Xafter.vim') |
| 343 | endif |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 344 | return 1 |
| 345 | endfunc |
Bram Moolenaar | 07282f0 | 2019-10-10 16:46:17 +0200 | [diff] [blame] | 346 | |
| 347 | func IsRoot() |
| 348 | if !has('unix') |
| 349 | return v:false |
| 350 | elseif $USER == 'root' || system('id -un') =~ '\<root\>' |
| 351 | return v:true |
| 352 | endif |
| 353 | return v:false |
| 354 | endfunc |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 355 | |
Bram Moolenaar | 88e6cc2 | 2020-04-30 19:19:29 +0200 | [diff] [blame] | 356 | " Get all messages but drop the maintainer entry. |
| 357 | func GetMessages() |
| 358 | redir => result |
| 359 | redraw | messages |
| 360 | redir END |
| 361 | let msg_list = split(result, "\n") |
| 362 | if msg_list->len() > 0 && msg_list[0] =~ 'Messages maintainer:' |
| 363 | return msg_list[1:] |
| 364 | endif |
| 365 | return msg_list |
| 366 | endfunc |
| 367 | |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 368 | " Run the list of commands in 'cmds' and look for 'errstr' in exception. |
| 369 | " Note that assert_fails() cannot be used in some places and this function |
| 370 | " can be used. |
| 371 | func AssertException(cmds, errstr) |
| 372 | let save_exception = '' |
| 373 | try |
| 374 | for cmd in a:cmds |
| 375 | exe cmd |
| 376 | endfor |
| 377 | catch |
| 378 | let save_exception = v:exception |
| 379 | endtry |
| 380 | call assert_match(a:errstr, save_exception) |
| 381 | endfunc |
| 382 | |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 383 | " vim: shiftwidth=2 sts=2 expandtab |