aboutsummaryrefslogtreecommitdiffstats
path: root/tests/helpers/lua/test_helpers.lua
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2022-07-06 19:41:43 +0200
committerWilliam Boman <william@redwill.se>2022-07-07 00:39:59 +0200
commit5f634e0c37e723fc0c33e06b4fd5c2180178db40 (patch)
treefa4f09363adefa8259e23e4d1ea036db628b1243 /tests/helpers/lua/test_helpers.lua
parentfeat(health): use stderr for java version, also check for JAVA_HOME (#765) (diff)
downloadmason-5f634e0c37e723fc0c33e06b4fd5c2180178db40.tar
mason-5f634e0c37e723fc0c33e06b4fd5c2180178db40.tar.gz
mason-5f634e0c37e723fc0c33e06b4fd5c2180178db40.tar.bz2
mason-5f634e0c37e723fc0c33e06b4fd5c2180178db40.tar.lz
mason-5f634e0c37e723fc0c33e06b4fd5c2180178db40.tar.xz
mason-5f634e0c37e723fc0c33e06b4fd5c2180178db40.tar.zst
mason-5f634e0c37e723fc0c33e06b4fd5c2180178db40.zip
mason.nvim
Diffstat (limited to 'tests/helpers/lua/test_helpers.lua')
-rw-r--r--tests/helpers/lua/test_helpers.lua66
1 files changed, 19 insertions, 47 deletions
diff --git a/tests/helpers/lua/test_helpers.lua b/tests/helpers/lua/test_helpers.lua
index 7b9b7647..d45a66b9 100644
--- a/tests/helpers/lua/test_helpers.lua
+++ b/tests/helpers/lua/test_helpers.lua
@@ -1,12 +1,12 @@
---@diagnostic disable: lowercase-global
-local mock = require "luassert.mock"
local util = require "luassert.util"
+local mock = require "luassert.mock"
+local spy = require "luassert.spy"
-local a = require "nvim-lsp-installer.core.async"
-local process = require "nvim-lsp-installer.core.process"
-local server = require "nvim-lsp-installer.server"
-local Optional = require "nvim-lsp-installer.core.optional"
-local receipt = require "nvim-lsp-installer.core.receipt"
+local a = require "mason.core.async"
+local InstallHandle = require "mason.core.installer.handle"
+local InstallContext = require "mason.core.installer.context"
+local indexer = require "mason.core.package.indexer"
function async_test(suspend_fn)
return function()
@@ -31,48 +31,20 @@ mockx = {
end,
}
-function ServerGenerator(opts)
- local name = opts.name or "dummy"
- return server.Server:new(vim.tbl_deep_extend("force", {
- name = name,
- languages = { "dummylang" },
- root_dir = server.get_server_root_path(name),
- homepage = "https://dummylang.org",
- installer = function(ctx)
- ctx.stdio_sink.stdout "Installing dummy!\n"
- end,
- }, opts))
+---@param package_name string
+function InstallHandleGenerator(package_name)
+ return InstallHandle.new(indexer.get_package(package_name))
end
-function FailingServerGenerator(opts)
- return ServerGenerator(vim.tbl_deep_extend("force", {
- installer = function(ctx)
- ctx.stdio_sink.stdout "Installing failing dummy!\n"
- error "Failed to do something."
+---@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,
- }, opts))
-end
-
-function InstallContextGenerator(opts)
- ---@type InstallContext
- local default_opts = {
- name = "mock",
- fs = mock.new {
- append_file = mockx.just_runs,
- dir_exists = mockx.returns(true),
- file_exists = mockx.returns(true),
- },
- spawn = mock.new {},
- cwd = mock.new {
- get = mockx.returns "/tmp/install-dir",
- set = mockx.just_runs,
- },
- destination_dir = "/opt/install-dir",
- stdio_sink = process.empty_sink(),
- promote_cwd = mockx.just_runs,
- receipt = receipt.InstallReceiptBuilder.new(),
- requested_version = Optional.empty(),
- }
- local merged_opts = vim.tbl_deep_extend("force", default_opts, opts)
- return mock.new(merged_opts)
+ })
+ return context
end