summaryrefslogtreecommitdiff
path: root/src/testdir/shared.vim
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2016-08-22 21:40:29 +0200
committerBram Moolenaar <Bram@vim.org>2016-08-22 21:40:29 +0200
commitf267f8bdf777073e392ada5b31d837c7b6090eb4 (patch)
tree304b0775c08e167320e8d9c6f15c61baafa493a0 /src/testdir/shared.vim
parent9baf297c99cc35adb921bee04369499d76438889 (diff)
downloadvim-f267f8bdf777073e392ada5b31d837c7b6090eb4.zip
patch 7.4.2240
Problem: Tests using the sleep time can be flaky. Solution: Use reltime() if available. (Partly by Shane Harper)
Diffstat (limited to 'src/testdir/shared.vim')
-rw-r--r--src/testdir/shared.vim18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/testdir/shared.vim b/src/testdir/shared.vim
index edc3c386a..24b05bec6 100644
--- a/src/testdir/shared.vim
+++ b/src/testdir/shared.vim
@@ -109,19 +109,31 @@ func s:kill_server(cmd)
endfunc
" Wait for up to a second for "expr" to become true.
-" Return time slept in milliseconds.
+" 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)
- let slept = 0
+ " using reltime() is more accurate, but not always available
+ if has('reltime')
+ let start = reltime()
+ else
+ let slept = 0
+ endif
for i in range(100)
try
if eval(a:expr)
+ if has('reltime')
+ return float2nr(reltimefloat(reltime(start)) * 1000)
+ endif
return slept
endif
catch
endtry
- let slept += 10
+ if !has('reltime')
+ let slept += 10
+ endif
sleep 10m
endfor
+ return 1000
endfunc
" Run Vim, using the "vimcmd" file and "-u NORC".