diff options
| author | William Boman <william@redwill.se> | 2021-12-25 15:11:42 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-25 15:11:42 +0100 |
| commit | d7e233566543d4c83199f5644f90bb116d7070f2 (patch) | |
| tree | ecfcb6e5abb937ee976eed6daac1bf2ab3bac51d /tests/luassertx/lua/luassertx.lua | |
| parent | fix: dont pass nil opts (diff) | |
| download | mason-d7e233566543d4c83199f5644f90bb116d7070f2.tar mason-d7e233566543d4c83199f5644f90bb116d7070f2.tar.gz mason-d7e233566543d4c83199f5644f90bb116d7070f2.tar.bz2 mason-d7e233566543d4c83199f5644f90bb116d7070f2.tar.lz mason-d7e233566543d4c83199f5644f90bb116d7070f2.tar.xz mason-d7e233566543d4c83199f5644f90bb116d7070f2.tar.zst mason-d7e233566543d4c83199f5644f90bb116d7070f2.zip | |
add some tests (#360)
Diffstat (limited to 'tests/luassertx/lua/luassertx.lua')
| -rw-r--r-- | tests/luassertx/lua/luassertx.lua | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/luassertx/lua/luassertx.lua b/tests/luassertx/lua/luassertx.lua new file mode 100644 index 00000000..33fa9957 --- /dev/null +++ b/tests/luassertx/lua/luassertx.lua @@ -0,0 +1,27 @@ +local a = require "plenary.async" +local assert = require "luassert" + +local function wait_for(_, 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] + timeout = timeout or 15000 + + local start = vim.loop.hrtime() + local is_ok, err + repeat + is_ok, err = pcall(assertions_fn) + if not is_ok then + a.util.sleep(math.min(timeout, 100)) + end + until is_ok or ((vim.loop.hrtime() - start) / 1e6) > timeout + + if not is_ok then + error(err) + end + + return is_ok +end + +assert:register("assertion", "wait_for", wait_for) |
