aboutsummaryrefslogtreecommitdiffstats
path: root/tests/helpers/lua/luassertx.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tests/helpers/lua/luassertx.lua')
-rw-r--r--tests/helpers/lua/luassertx.lua21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/helpers/lua/luassertx.lua b/tests/helpers/lua/luassertx.lua
index e9bc4e44..3de3bf15 100644
--- a/tests/helpers/lua/luassertx.lua
+++ b/tests/helpers/lua/luassertx.lua
@@ -2,6 +2,26 @@ local a = require "mason-core.async"
local assert = require "luassert"
local match = require "luassert.match"
+local function wait(_, arguments)
+ ---@type (fun()) Function to execute until it does not error.
+ local assertions_fn = arguments[1]
+ ---@type number Timeout in milliseconds. Defaults to 5000.
+ local timeout = arguments[2] or 5000
+
+ local err
+ if
+ not vim.wait(timeout, function()
+ local ok, err_ = pcall(assertions_fn)
+ err = err_
+ return ok
+ end, math.min(timeout, 100))
+ then
+ error(err)
+ end
+
+ return true
+end
+
local function wait_for(_, arguments)
---@type (fun()) Function to execute until it does not error.
local assertions_fn = arguments[1]
@@ -76,3 +96,4 @@ assert:register("matcher", "list_containing", list_containing)
assert:register("matcher", "instanceof", instanceof)
assert:register("matcher", "capture", capture)
assert:register("assertion", "wait_for", wait_for)
+assert:register("assertion", "wait", wait)