summaryrefslogtreecommitdiff
path: root/src/testdir/shared.vim
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2017-11-04 18:48:43 +0100
committerBram Moolenaar <Bram@vim.org>2017-11-04 18:48:43 +0100
commit13deab8d08145c1f6e2a3e82cb547bc7f87a3686 (patch)
tree6d05a3eb7947f41e80d8cc4f6844ffd3ba58ddef /src/testdir/shared.vim
parent52a2f0f1da4e554a81beb45211a9d09afffde595 (diff)
downloadvim-git-13deab8d08145c1f6e2a3e82cb547bc7f87a3686.tar.gz
patch 8.0.1259: search test can be flakyv8.0.1259
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)
Diffstat (limited to 'src/testdir/shared.vim')
-rw-r--r--src/testdir/shared.vim11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/testdir/shared.vim b/src/testdir/shared.vim
index d6033d581..8042428cf 100644
--- a/src/testdir/shared.vim
+++ b/src/testdir/shared.vim
@@ -113,7 +113,9 @@ func s:kill_server(cmd)
endif
endfunc
-" Wait for up to a second for "expr" to become true.
+" Wait for up to a second for "expr" to become true. "expr" can be a
+" stringified expression to evaluate, or a funcref without arguments.
+"
" Return time slept in milliseconds. With the +reltime feature this can be
" more than the actual waiting time. Without +reltime it can also be less.
func WaitFor(expr, ...)
@@ -124,8 +126,13 @@ func WaitFor(expr, ...)
else
let slept = 0
endif
+ if type(a:expr) == v:t_func
+ let Test = a:expr
+ else
+ let Test = {-> eval(a:expr) }
+ endif
for i in range(timeout / 10)
- if eval(a:expr)
+ if Test()
if has('reltime')
return float2nr(reltimefloat(reltime(start)) * 1000)
endif