aboutsummaryrefslogtreecommitdiffstats
path: root/tests/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
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')
-rw-r--r--tests/helpers/lua/dummy_package.lua14
-rw-r--r--tests/helpers/lua/luassertx.lua10
-rw-r--r--tests/helpers/lua/test_helpers.lua66
3 files changed, 42 insertions, 48 deletions
diff --git a/tests/helpers/lua/dummy_package.lua b/tests/helpers/lua/dummy_package.lua
new file mode 100644
index 00000000..961f0959
--- /dev/null
+++ b/tests/helpers/lua/dummy_package.lua
@@ -0,0 +1,14 @@
+local Pkg = require "mason.core.package"
+
+return Pkg.new {
+ name = "dummy",
+ desc = [[This is a dummy package.]],
+ categories = { Pkg.Cat.LSP },
+ languages = { Pkg.Lang.DummyLang },
+ homepage = "https://example.com",
+ ---@async
+ ---@param ctx InstallContext
+ install = function(ctx)
+ ctx.receipt:with_primary_source { type = "dummy" }
+ end,
+}
diff --git a/tests/helpers/lua/luassertx.lua b/tests/helpers/lua/luassertx.lua
index 06d08ede..f4c9e702 100644
--- a/tests/helpers/lua/luassertx.lua
+++ b/tests/helpers/lua/luassertx.lua
@@ -1,6 +1,6 @@
local assert = require "luassert"
local match = require "luassert.match"
-local a = require "nvim-lsp-installer.core.async"
+local a = require "mason.core.async"
local function wait_for(_, arguments)
---@type fun() @Function to execute until it does not error.
@@ -57,6 +57,14 @@ local function list_containing(_, arguments, _)
end
end
+local function instanceof(_, arguments, _)
+ return function(value)
+ local expected_mt = arguments[1]
+ return getmetatable(value) == expected_mt
+ end
+end
+
assert:register("matcher", "tbl_containing", tbl_containing)
assert:register("matcher", "list_containing", list_containing)
+assert:register("matcher", "instanceof", instanceof)
assert:register("assertion", "wait_for", wait_for)
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