aboutsummaryrefslogtreecommitdiff
path: root/test/functional/helpers.lua
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2016-12-07 13:01:03 +0100
committerJustin M. Keyes <justinkz@gmail.com>2016-12-07 17:03:52 +0100
commit1a4f13ba8f93dc006d3c24de10f406367724573c (patch)
tree5fb0a7424dc1ee371e0e388b3a6fc0c75f27aad9 /test/functional/helpers.lua
parent8da23cb919e55825bc89f0ebfcebcc07374d9d18 (diff)
downloadrneovim-1a4f13ba8f93dc006d3c24de10f406367724573c.tar.gz
rneovim-1a4f13ba8f93dc006d3c24de10f406367724573c.tar.bz2
rneovim-1a4f13ba8f93dc006d3c24de10f406367724573c.zip
test: helpers.retry()
Diffstat (limited to 'test/functional/helpers.lua')
-rw-r--r--test/functional/helpers.lua14
1 files changed, 14 insertions, 0 deletions
diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua
index ff62b4de86..d1ab02f361 100644
--- a/test/functional/helpers.lua
+++ b/test/functional/helpers.lua
@@ -243,6 +243,19 @@ local function connect(file_or_address)
return Session.new(stream)
end
+-- Calls fn() until it returns without error, up to `max` times.
+local function retry(fn, max)
+ local retries = max and (max - 1) or 2
+ for _ = 1, retries do
+ local success = pcall(fn)
+ if success then
+ return
+ end
+ end
+ -- pcall() is not used for the final attempt so failure can bubble up.
+ fn()
+end
+
local function clear(...)
local args = {unpack(nvim_argv)}
local new_args
@@ -530,6 +543,7 @@ return function(after_each)
prepend_argv = prepend_argv,
clear = clear,
connect = connect,
+ retry = retry,
spawn = spawn,
dedent = dedent,
source = source,