diff options
| author | William Boman <william@redwill.se> | 2022-07-21 14:15:11 +0200 |
|---|---|---|
| committer | William Boman <william@redwill.se> | 2022-07-22 03:03:23 +0200 |
| commit | 1d459b6d19118b9944d5313e4439cb361d607366 (patch) | |
| tree | d48a07eaa5fddebc75ade8bb1d3861992e0c11a3 /tests/helpers/lua/test_helpers.lua | |
| download | mason-lspconfig-1d459b6d19118b9944d5313e4439cb361d607366.tar mason-lspconfig-1d459b6d19118b9944d5313e4439cb361d607366.tar.gz mason-lspconfig-1d459b6d19118b9944d5313e4439cb361d607366.tar.bz2 mason-lspconfig-1d459b6d19118b9944d5313e4439cb361d607366.tar.lz mason-lspconfig-1d459b6d19118b9944d5313e4439cb361d607366.tar.xz mason-lspconfig-1d459b6d19118b9944d5313e4439cb361d607366.tar.zst mason-lspconfig-1d459b6d19118b9944d5313e4439cb361d607366.zip | |
init
Diffstat (limited to 'tests/helpers/lua/test_helpers.lua')
| -rw-r--r-- | tests/helpers/lua/test_helpers.lua | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/helpers/lua/test_helpers.lua b/tests/helpers/lua/test_helpers.lua new file mode 100644 index 0000000..57c0b4f --- /dev/null +++ b/tests/helpers/lua/test_helpers.lua @@ -0,0 +1,49 @@ +---@diagnostic disable: lowercase-global +local util = require "luassert.util" +local spy = require "luassert.spy" + +local a = require "mason-core.async" +local InstallHandle = require "mason-core.installer.handle" +local InstallContext = require "mason-core.installer.context" +local registry = require "mason-registry" + +function async_test(suspend_fn) + return function() + local ok, err = pcall(a.run_blocking, suspend_fn) + if not ok then + error(err, util.errorlevel()) + end + end +end + +mockx = { + just_runs = function() end, + returns = function(val) + return function() + return val + end + end, + throws = function(exception) + return function() + error(exception, 2) + end + end, +} + +---@param package_name string +function InstallHandleGenerator(package_name) + return InstallHandle.new(registry.get_package(package_name)) +end + +---@param handle InstallHandle +---@param opts InstallContextOpts | nil +function InstallContextGenerator(handle, opts) + local context = InstallContext.new(handle, opts or {}) + context.spawn = setmetatable({}, { + __index = function(s, cmd) + s[cmd] = spy.new(mockx.just_runs()) + return s[cmd] + end, + }) + return context +end |
