Mercurial > vim
comparison src/testdir/shared.vim @ 12763:7f27e9769f62 v8.0.1259
patch 8.0.1259: search test can be flaky
commit https://github.com/vim/vim/commit/13deab8d08145c1f6e2a3e82cb547bc7f87a3686
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Nov 4 18:48:43 2017 +0100
patch 8.0.1259: search test can be flaky
Problem: Search test can be flaky.
Solution: Use WaitFor() instead of a delay. Make it possible to pass a
funcref to WaitFor() to avoid the need for global variables.
(James McCoy, closes #2282)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 04 Nov 2017 19:00:05 +0100 |
parents | af961e38e508 |
children | 013c44d9dc09 |
comparison
equal
deleted
inserted
replaced
12762:50fd18c60c3d | 12763:7f27e9769f62 |
---|---|
111 else | 111 else |
112 call system("pkill -f " . a:cmd) | 112 call system("pkill -f " . a:cmd) |
113 endif | 113 endif |
114 endfunc | 114 endfunc |
115 | 115 |
116 " Wait for up to a second for "expr" to become true. | 116 " Wait for up to a second for "expr" to become true. "expr" can be a |
117 " stringified expression to evaluate, or a funcref without arguments. | |
118 " | |
117 " Return time slept in milliseconds. With the +reltime feature this can be | 119 " Return time slept in milliseconds. With the +reltime feature this can be |
118 " more than the actual waiting time. Without +reltime it can also be less. | 120 " more than the actual waiting time. Without +reltime it can also be less. |
119 func WaitFor(expr, ...) | 121 func WaitFor(expr, ...) |
120 let timeout = get(a:000, 0, 1000) | 122 let timeout = get(a:000, 0, 1000) |
121 " using reltime() is more accurate, but not always available | 123 " using reltime() is more accurate, but not always available |
122 if has('reltime') | 124 if has('reltime') |
123 let start = reltime() | 125 let start = reltime() |
124 else | 126 else |
125 let slept = 0 | 127 let slept = 0 |
126 endif | 128 endif |
129 if type(a:expr) == v:t_func | |
130 let Test = a:expr | |
131 else | |
132 let Test = {-> eval(a:expr) } | |
133 endif | |
127 for i in range(timeout / 10) | 134 for i in range(timeout / 10) |
128 if eval(a:expr) | 135 if Test() |
129 if has('reltime') | 136 if has('reltime') |
130 return float2nr(reltimefloat(reltime(start)) * 1000) | 137 return float2nr(reltimefloat(reltime(start)) * 1000) |
131 endif | 138 endif |
132 return slept | 139 return slept |
133 endif | 140 endif |