aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/README.md1
-rw-r--r--tests/core/async_spec.lua31
-rw-r--r--tests/core/clients/eclipse_spec.lua2
-rw-r--r--tests/core/fetch_spec.lua59
-rw-r--r--tests/core/fs_spec.lua8
-rw-r--r--tests/core/functional/data_spec.lua2
-rw-r--r--tests/core/functional/function_spec.lua2
-rw-r--r--tests/core/functional/list_spec.lua70
-rw-r--r--tests/core/functional/logic_spec.lua16
-rw-r--r--tests/core/functional/number_spec.lua2
-rw-r--r--tests/core/functional/relation_spec.lua2
-rw-r--r--tests/core/functional/string_spec.lua19
-rw-r--r--tests/core/functional/table_spec.lua46
-rw-r--r--tests/core/functional/type_spec.lua2
-rw-r--r--tests/core/installer_spec.lua107
-rw-r--r--tests/core/managers/cargo_spec.lua44
-rw-r--r--tests/core/managers/composer_spec.lua39
-rw-r--r--tests/core/managers/dotnet_spec.lua22
-rw-r--r--tests/core/managers/gem_spec.lua26
-rw-r--r--tests/core/managers/git_spec.lua49
-rw-r--r--tests/core/managers/github_client_spec.lua2
-rw-r--r--tests/core/managers/go_spec.lua48
-rw-r--r--tests/core/managers/luarocks_spec.lua31
-rw-r--r--tests/core/managers/npm_spec.lua45
-rw-r--r--tests/core/managers/opam_spec.lua22
-rw-r--r--tests/core/managers/pip3_spec.lua74
-rw-r--r--tests/core/optional_spec.lua2
-rw-r--r--tests/core/path_spec.lua6
-rw-r--r--tests/core/platform_spec.lua4
-rw-r--r--tests/core/process_spec.lua122
-rw-r--r--tests/core/result_spec.lua2
-rw-r--r--tests/core/spawn_spec.lua10
-rw-r--r--tests/core/ui_spec.lua84
-rw-r--r--tests/dispatcher_spec.lua48
-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
-rw-r--r--tests/middleware_spec.lua71
-rw-r--r--tests/minimal_debug_init.lua8
-rw-r--r--tests/minimal_init.vim10
-rw-r--r--tests/server_spec.lua55
-rw-r--r--tests/setup/automatic_installation_exclude_spec.lua44
-rw-r--r--tests/setup/automatic_installation_spec.lua43
-rw-r--r--tests/setup/ensure_installed_spec.lua39
-rw-r--r--tests/ui_status_win_spec.lua49
45 files changed, 570 insertions, 888 deletions
diff --git a/tests/README.md b/tests/README.md
deleted file mode 100644
index bd9259d4..00000000
--- a/tests/README.md
+++ /dev/null
@@ -1 +0,0 @@
-Refer to https://github.com/williamboman/nvim-lspconfig-test for system tests.
diff --git a/tests/core/async_spec.lua b/tests/core/async_spec.lua
index ce55c5ab..330a014e 100644
--- a/tests/core/async_spec.lua
+++ b/tests/core/async_spec.lua
@@ -1,8 +1,8 @@
local assert = require "luassert"
local spy = require "luassert.spy"
local match = require "luassert.match"
-local a = require "nvim-lsp-installer.core.async"
-local process = require "nvim-lsp-installer.core.process"
+local a = require "mason.core.async"
+local process = require "mason.core.process"
local function timestamp()
local seconds, microseconds = vim.loop.gettimeofday()
@@ -169,4 +169,31 @@ describe("async", function()
assert.equals(5, five)
end)
)
+
+ it(
+ "should run all suspending functions concurrently",
+ async_test(function()
+ local start = timestamp()
+ local called = spy.new()
+ local function sleep(ms, ret_val)
+ return function()
+ a.sleep(ms)
+ called()
+ return ret_val
+ end
+ end
+ local first = a.wait_first {
+ sleep(150, 1),
+ sleep(50, "first"),
+ sleep(150, "three"),
+ sleep(150, 4),
+ sleep(150, 5),
+ }
+ local grace = 50
+ local delta = timestamp() - start
+ assert.is_true(delta <= (100 + grace))
+ assert.is_true(delta >= (100 - grace))
+ assert.equals("first", first)
+ end)
+ )
end)
diff --git a/tests/core/clients/eclipse_spec.lua b/tests/core/clients/eclipse_spec.lua
index bd7fac1d..4a013c48 100644
--- a/tests/core/clients/eclipse_spec.lua
+++ b/tests/core/clients/eclipse_spec.lua
@@ -1,4 +1,4 @@
-local eclipse = require "nvim-lsp-installer.core.clients.eclipse"
+local eclipse = require "mason.core.clients.eclipse"
describe("eclipse client", function()
it("parses jdtls version strings", function()
diff --git a/tests/core/fetch_spec.lua b/tests/core/fetch_spec.lua
index b4929167..e2506f89 100644
--- a/tests/core/fetch_spec.lua
+++ b/tests/core/fetch_spec.lua
@@ -1,7 +1,8 @@
local stub = require "luassert.stub"
-local fetch = require "nvim-lsp-installer.core.fetch"
-local spawn = require "nvim-lsp-installer.core.spawn"
-local Result = require "nvim-lsp-installer.core.result"
+local match = require "luassert.match"
+local fetch = require "mason.core.fetch"
+local spawn = require "mason.core.spawn"
+local Result = require "mason.core.result"
describe("fetch", function()
it(
@@ -12,26 +13,43 @@ describe("fetch", function()
spawn.wget.returns(Result.failure "wget failure")
spawn.curl.returns(Result.failure "curl failure")
- local result = fetch "https://api.github.com"
+ local result = fetch("https://api.github.com", {
+ headers = { ["X-Custom-Header"] = "here" },
+ })
assert.is_true(result:is_failure())
assert.spy(spawn.wget).was_called(1)
assert.spy(spawn.curl).was_called(1)
assert.spy(spawn.wget).was_called_with {
{
- "--header",
- "User-Agent: nvim-lsp-installer (+https://github.com/williamboman/nvim-lsp-installer)",
+ "--header='User-Agent: mason.nvim (+https://github.com/williamboman/mason.nvim)'",
+ "--header='X-Custom-Header: here'",
},
"-nv",
"-O",
"-",
+ "--method=GET",
+ vim.NIL, -- body-data
"https://api.github.com",
}
- assert.spy(spawn.curl).was_called_with {
- { "-H", "User-Agent: nvim-lsp-installer (+https://github.com/williamboman/nvim-lsp-installer)" },
+
+ assert.spy(spawn.curl).was_called_with(match.tbl_containing {
+ match.same {
+ {
+ "-H",
+ "User-Agent: mason.nvim (+https://github.com/williamboman/mason.nvim)",
+ },
+ {
+ "-H",
+ "X-Custom-Header: here",
+ },
+ },
"-fsSL",
- vim.NIL,
+ match.same { "-X", "GET" },
+ vim.NIL, -- data
+ vim.NIL, -- out file
"https://api.github.com",
- }
+ on_spawn = match.is_function(),
+ })
end)
)
@@ -59,21 +77,30 @@ describe("fetch", function()
assert.spy(spawn.wget).was_called_with {
{
- "--header",
- "User-Agent: nvim-lsp-installer (+https://github.com/williamboman/nvim-lsp-installer)",
+ "--header='User-Agent: mason.nvim (+https://github.com/williamboman/mason.nvim)'",
},
"-nv",
"-O",
"/test.json",
+ "--method=GET",
+ vim.NIL, -- body-data
"https://api.github.com/data",
}
- assert.spy(spawn.curl).was_called_with {
- { "-H", "User-Agent: nvim-lsp-installer (+https://github.com/williamboman/nvim-lsp-installer)" },
+ assert.spy(spawn.curl).was_called_with(match.tbl_containing {
+ match.same {
+ {
+ "-H",
+ "User-Agent: mason.nvim (+https://github.com/williamboman/mason.nvim)",
+ },
+ },
"-fsSL",
- { "-o", "/test.json" },
+ match.same { "-X", "GET" },
+ vim.NIL, -- data
+ match.same { "-o", "/test.json" },
"https://api.github.com/data",
- }
+ on_spawn = match.is_function(),
+ })
end)
)
end)
diff --git a/tests/core/fs_spec.lua b/tests/core/fs_spec.lua
index 0202df64..9fa59189 100644
--- a/tests/core/fs_spec.lua
+++ b/tests/core/fs_spec.lua
@@ -1,9 +1,9 @@
-local fs = require "nvim-lsp-installer.core.fs"
-local lsp_installer = require "nvim-lsp-installer"
+local fs = require "mason.core.fs"
+local mason = require "mason"
describe("fs", function()
before_each(function()
- lsp_installer.settings {
+ mason.setup {
install_root_dir = "/foo",
}
end)
@@ -16,7 +16,7 @@ describe("fs", function()
end)
assert.equal(
- [[Refusing to rmrf "/thisisa/path" which is outside of the allowed boundary "/foo". Please report this error at https://github.com/williamboman/nvim-lsp-installer/issues/new]],
+ [[Refusing to rmrf "/thisisa/path" which is outside of the allowed boundary "/foo". Please report this error at https://github.com/williamboman/mason.nvim/issues/new]],
e
)
end)
diff --git a/tests/core/functional/data_spec.lua b/tests/core/functional/data_spec.lua
index b89176e2..cdc26809 100644
--- a/tests/core/functional/data_spec.lua
+++ b/tests/core/functional/data_spec.lua
@@ -1,4 +1,4 @@
-local _ = require "nvim-lsp-installer.core.functional"
+local _ = require "mason.core.functional"
describe("functional: data", function()
it("creates enums", function()
diff --git a/tests/core/functional/function_spec.lua b/tests/core/functional/function_spec.lua
index 4b9cbba6..21951dc3 100644
--- a/tests/core/functional/function_spec.lua
+++ b/tests/core/functional/function_spec.lua
@@ -1,6 +1,6 @@
local spy = require "luassert.spy"
local match = require "luassert.match"
-local _ = require "nvim-lsp-installer.core.functional"
+local _ = require "mason.core.functional"
describe("functional: function", function()
it("curries functions", function()
diff --git a/tests/core/functional/list_spec.lua b/tests/core/functional/list_spec.lua
index 21aa4e69..a03fee68 100644
--- a/tests/core/functional/list_spec.lua
+++ b/tests/core/functional/list_spec.lua
@@ -1,5 +1,6 @@
local spy = require "luassert.spy"
-local _ = require "nvim-lsp-installer.core.functional"
+local _ = require "mason.core.functional"
+local Optional = require "mason.core.optional"
describe("functional: list", function()
it("should produce list without nils", function()
@@ -41,6 +42,24 @@ describe("functional: list", function()
assert.same({ "BLUE", "YELLOW", "RED" }, colors)
end)
+ it("filter_map over list", function()
+ local colors = { "BROWN", "BLUE", "YELLOW", "GREEN", "CYAN" }
+ assert.same(
+ {
+ "BROWN EYES",
+ "BLUE EYES",
+ "GREEN EYES",
+ },
+ _.filter_map(function(color)
+ if _.any_pass({ _.equals "BROWN", _.equals "BLUE", _.equals "GREEN" }, color) then
+ return Optional.of(("%s EYES"):format(color))
+ else
+ return Optional.empty()
+ end
+ end, colors)
+ )
+ end)
+
it("finds first item that fulfills predicate", function()
local predicate = spy.new(function(item)
return item == "Waldo"
@@ -122,4 +141,53 @@ describe("functional: list", function()
assert.equals(1, _.length { "" })
assert.equals(4, _.length "fire")
end)
+
+ it("should sort by comparator", function()
+ local list = {
+ {
+ name = "William",
+ },
+ {
+ name = "Boman",
+ },
+ }
+ assert.same({
+ {
+ name = "Boman",
+ },
+ {
+ name = "William",
+ },
+ }, _.sort_by(_.prop "name", list))
+
+ -- Should not mutate original list
+ assert.same({
+ {
+ name = "William",
+ },
+ {
+ name = "Boman",
+ },
+ }, list)
+ end)
+
+ it("should append to list", function()
+ local list = { "Earth", "Wind" }
+ assert.same({ "Earth", "Wind", { "Fire" } }, _.append({ "Fire" }, list))
+
+ -- Does not mutate original list
+ assert.same({ "Earth", "Wind" }, list)
+ end)
+
+ it("should prepend to list", function()
+ local list = { "Fire" }
+ assert.same({ { "Earth", "Wind" }, "Fire" }, _.prepend({ "Earth", "Wind" }, list))
+
+ -- Does not mutate original list
+ assert.same({ "Fire" }, list)
+ end)
+
+ it("joins lists", function()
+ assert.equals("Hello, John", _.join(", ", { "Hello", "John" }))
+ end)
end)
diff --git a/tests/core/functional/logic_spec.lua b/tests/core/functional/logic_spec.lua
index 291d8979..073ca52c 100644
--- a/tests/core/functional/logic_spec.lua
+++ b/tests/core/functional/logic_spec.lua
@@ -1,16 +1,24 @@
local spy = require "luassert.spy"
-local _ = require "nvim-lsp-installer.core.functional"
+local _ = require "mason.core.functional"
describe("functional: logic", function()
it("should check that all_pass checks that all predicates pass", function()
- local is_waldo = function(i)
- return i == "waldo"
- end
+ local is_waldo = _.equals "waldo"
assert.is_true(_.all_pass { _.T, _.T, is_waldo, _.T } "waldo")
assert.is_false(_.all_pass { _.T, _.T, is_waldo, _.F } "waldo")
assert.is_false(_.all_pass { _.T, _.T, is_waldo, _.T } "waldina")
end)
+ it("should check that any_pass checks that any predicates pass", function()
+ local is_waldo = _.equals "waldo"
+ local is_waldina = _.equals "waldina"
+ local is_luigi = _.equals "luigi"
+
+ assert.is_true(_.any_pass { is_waldo, is_waldina } "waldo")
+ assert.is_false(_.any_pass { is_waldina, is_luigi } "waldo")
+ assert.is_true(_.any_pass { is_waldina, is_luigi } "waldina")
+ end)
+
it("should branch if_else", function()
local a = spy.new()
local b = spy.new()
diff --git a/tests/core/functional/number_spec.lua b/tests/core/functional/number_spec.lua
index 644547fb..f23156fe 100644
--- a/tests/core/functional/number_spec.lua
+++ b/tests/core/functional/number_spec.lua
@@ -1,4 +1,4 @@
-local _ = require "nvim-lsp-installer.core.functional"
+local _ = require "mason.core.functional"
describe("functional: number", function()
it("should negate numbers", function()
diff --git a/tests/core/functional/relation_spec.lua b/tests/core/functional/relation_spec.lua
index 41325cf2..4c92ffb5 100644
--- a/tests/core/functional/relation_spec.lua
+++ b/tests/core/functional/relation_spec.lua
@@ -1,4 +1,4 @@
-local _ = require "nvim-lsp-installer.core.functional"
+local _ = require "mason.core.functional"
describe("functional: relation", function()
it("should check equality", function()
diff --git a/tests/core/functional/string_spec.lua b/tests/core/functional/string_spec.lua
index cbee0617..4f9f4722 100644
--- a/tests/core/functional/string_spec.lua
+++ b/tests/core/functional/string_spec.lua
@@ -1,4 +1,4 @@
-local _ = require "nvim-lsp-installer.core.functional"
+local _ = require "mason.core.functional"
describe("functional: string", function()
it("matches string patterns", function()
@@ -23,4 +23,21 @@ describe("functional: string", function()
it("should gsub strings", function()
assert.same("predator", _.gsub("^apex%s*", "", "apex predator"))
end)
+
+ it("should dedent strings", function()
+ assert.equals(
+ [[Lorem
+Ipsum
+ Dolor
+ Sit
+ Amet]],
+ _.dedent [[
+ Lorem
+ Ipsum
+ Dolor
+ Sit
+ Amet
+]]
+ )
+ end)
end)
diff --git a/tests/core/functional/table_spec.lua b/tests/core/functional/table_spec.lua
index 25adff59..b10527f1 100644
--- a/tests/core/functional/table_spec.lua
+++ b/tests/core/functional/table_spec.lua
@@ -1,7 +1,51 @@
-local _ = require "nvim-lsp-installer.core.functional"
+local _ = require "mason.core.functional"
describe("functional: table", function()
it("retrieves property of table", function()
assert.equals("hello", _.prop("a", { a = "hello" }))
end)
+
+ it("picks properties of table", function()
+ local function fn() end
+ assert.same(
+ {
+ ["key1"] = 1,
+ [fn] = 2,
+ },
+ _.pick({ "key1", fn }, {
+ ["key1"] = 1,
+ [fn] = 2,
+ [3] = 3,
+ })
+ )
+ end)
+
+ it("converts table to pairs", function()
+ assert.same(
+ _.sort_by(_.nth(1), {
+ {
+ "skies",
+ "cloudy",
+ },
+ {
+ "temperature",
+ "20°",
+ },
+ }),
+ _.sort_by(_.nth(1), _.to_pairs { skies = "cloudy", temperature = "20°" })
+ )
+ end)
+
+ it("should invert tables", function()
+ assert.same(
+ {
+ val1 = "key1",
+ val2 = "key2",
+ },
+ _.invert {
+ key1 = "val1",
+ key2 = "val2",
+ }
+ )
+ end)
end)
diff --git a/tests/core/functional/type_spec.lua b/tests/core/functional/type_spec.lua
index b99262b5..8e8068df 100644
--- a/tests/core/functional/type_spec.lua
+++ b/tests/core/functional/type_spec.lua
@@ -1,4 +1,4 @@
-local _ = require "nvim-lsp-installer.core.functional"
+local _ = require "mason.core.functional"
describe("functional: type", function()
it("should check nil value", function()
diff --git a/tests/core/installer_spec.lua b/tests/core/installer_spec.lua
index 0e42f9e7..62e5421e 100644
--- a/tests/core/installer_spec.lua
+++ b/tests/core/installer_spec.lua
@@ -1,11 +1,10 @@
local spy = require "luassert.spy"
local match = require "luassert.match"
-local fs = require "nvim-lsp-installer.core.fs"
-local a = require "nvim-lsp-installer.core.async"
-local installer = require "nvim-lsp-installer.core.installer"
-local InstallContext = require "nvim-lsp-installer.core.installer.context"
-local process = require "nvim-lsp-installer.core.process"
-local Optional = require "nvim-lsp-installer.core.optional"
+local fs = require "mason.core.fs"
+local a = require "mason.core.async"
+local path = require "mason.core.path"
+local installer = require "mason.core.installer"
+local InstallContext = require "mason.core.installer.context"
local function timestamp()
local seconds, microseconds = vim.loop.gettimeofday()
@@ -13,35 +12,25 @@ local function timestamp()
end
describe("installer", function()
+ before_each(function()
+ package.loaded["dummy_package"] = nil
+ end)
+
it(
"should call installer",
async_test(function()
spy.on(fs.async, "mkdirp")
spy.on(fs.async, "rename")
- local installer_fn = spy.new(
- ---@param c InstallContext
- function(c)
- c.receipt:with_primary_source(c.receipt.npm "the-pkg")
- end
- )
- local destination_dir = ("%s/installer_spec"):format(os.getenv "INSTALL_ROOT_DIR")
- local ctx = InstallContext.new {
- name = "installer_spec_success",
- destination_dir = destination_dir,
- boundary_path = os.getenv "INSTALL_ROOT_DIR",
- stdio_sink = process.empty_sink(),
- requested_version = Optional.empty(),
- }
- local result = installer.execute(ctx, function(...)
- installer_fn(...)
- end)
+
+ local handle = InstallHandleGenerator "dummy"
+ spy.on(handle.package.spec, "install")
+ local result = installer.execute(handle, {})
+
assert.is_nil(result:err_or_nil())
- assert.spy(installer_fn).was_called(1)
- assert.spy(installer_fn).was_called_with(match.ref(ctx))
- assert.spy(fs.async.mkdirp).was_called(1)
- assert.spy(fs.async.mkdirp).was_called_with(destination_dir .. ".tmp")
- assert.spy(fs.async.rename).was_called(1)
- assert.spy(fs.async.rename).was_called_with(destination_dir .. ".tmp", destination_dir)
+ assert.spy(handle.package.spec.install).was_called(1)
+ assert.spy(handle.package.spec.install).was_called_with(match.instanceof(InstallContext))
+ assert.spy(fs.async.mkdirp).was_called_with(path.package_build_prefix "dummy")
+ assert.spy(fs.async.rename).was_called_with(path.package_build_prefix "dummy", path.package_prefix "dummy")
end)
)
@@ -49,27 +38,18 @@ describe("installer", function()
"should return failure if installer errors",
async_test(function()
spy.on(fs.async, "rmrf")
+ spy.on(fs.async, "rename")
local installer_fn = spy.new(function()
- error("something went wrong. don't try again.", 4) -- 4 because spy.new callstack
- end)
- local destination_dir = ("%s/installer_spec_failure"):format(os.getenv "INSTALL_ROOT_DIR")
- local ctx = InstallContext.new {
- name = "installer_spec_failure",
- destination_dir = destination_dir,
- boundary_path = os.getenv "INSTALL_ROOT_DIR",
- stdio_sink = process.empty_sink(),
- requested_version = Optional.empty(),
- }
- local result = installer.execute(ctx, function(...)
- installer_fn(...)
+ error("something went wrong. don't try again.", 0)
end)
+ local handler = InstallHandleGenerator "dummy"
+ handler.package.spec.install = installer_fn
+ local result = installer.execute(handler, {})
assert.spy(installer_fn).was_called(1)
- assert.spy(installer_fn).was_called_with(match.ref(ctx))
assert.is_true(result:is_failure())
- assert.equals("something went wrong. don't try again.", result:err_or_nil())
- assert.spy(fs.async.rmrf).was_called(2)
- assert.spy(fs.async.rmrf).was_called_with(destination_dir .. ".tmp")
- assert.spy(fs.async.rmrf).was_not_called_with(destination_dir)
+ assert.is_true(match.has_match "^.*: something went wrong. don't try again.$"(result:err_or_nil()))
+ assert.spy(fs.async.rmrf).was_called_with(path.package_build_prefix "dummy")
+ assert.spy(fs.async.rename).was_not_called()
end)
)
@@ -77,20 +57,11 @@ describe("installer", function()
"should write receipt",
async_test(function()
spy.on(fs.async, "write_file")
- local destination_dir = ("%s/installer_spec_receipt"):format(os.getenv "INSTALL_ROOT_DIR")
- local ctx = InstallContext.new {
- name = "installer_spec_receipt",
- destination_dir = destination_dir,
- boundary_path = os.getenv "INSTALL_ROOT_DIR",
- stdio_sink = process.empty_sink(),
- requested_version = Optional.empty(),
- }
- installer.execute(ctx, function(c)
- c.receipt:with_primary_source(c.receipt.npm "my-pkg")
- end)
+ local handle = InstallHandleGenerator "dummy"
+ installer.execute(handle, {})
assert.spy(fs.async.write_file).was_called(1)
assert.spy(fs.async.write_file).was_called_with(
- ("%s.tmp/nvim-lsp-installer-receipt.json"):format(destination_dir),
+ ("%s/mason-receipt.json"):format(handle.package:get_install_path()),
match.is_string()
)
end)
@@ -100,18 +71,11 @@ describe("installer", function()
"should run async functions concurrently",
async_test(function()
spy.on(fs.async, "write_file")
- local destination_dir = ("%s/installer_spec_concurrent"):format(os.getenv "INSTALL_ROOT_DIR")
- local ctx = InstallContext.new {
- name = "installer_spec_receipt",
- destination_dir = destination_dir,
- boundary_path = os.getenv "INSTALL_ROOT_DIR",
- stdio_sink = process.empty_sink(),
- requested_version = Optional.empty(),
- }
local capture = spy.new()
local start = timestamp()
- installer.run_installer(ctx, function(c)
- capture(c:run_concurrently {
+ local handle = InstallHandleGenerator "dummy"
+ handle.package.spec.install = function(ctx)
+ capture(installer.run_concurrently {
function()
a.sleep(100)
return installer.context()
@@ -125,12 +89,13 @@ describe("installer", function()
return "three"
end,
})
- c.receipt:with_primary_source(c.receipt.npm "my-pkg")
- end)
+ ctx.receipt:with_primary_source { type = "dummy" }
+ end
+ installer.execute(handle, {})
local stop = timestamp()
local grace_ms = 25
assert.is_true((stop - start) >= (100 - grace_ms))
- assert.spy(capture).was_called_with(match.is_ref(ctx), "two", "three")
+ assert.spy(capture).was_called_with(match.instanceof(InstallContext), "two", "three")
end)
)
end)
diff --git a/tests/core/managers/cargo_spec.lua b/tests/core/managers/cargo_spec.lua
index a473fe75..59bb75da 100644
--- a/tests/core/managers/cargo_spec.lua
+++ b/tests/core/managers/cargo_spec.lua
@@ -1,27 +1,19 @@
local spy = require "luassert.spy"
local match = require "luassert.match"
local mock = require "luassert.mock"
-local Optional = require "nvim-lsp-installer.core.optional"
-local installer = require "nvim-lsp-installer.core.installer"
-local cargo = require "nvim-lsp-installer.core.managers.cargo"
-local Result = require "nvim-lsp-installer.core.result"
-local spawn = require "nvim-lsp-installer.core.spawn"
+local Optional = require "mason.core.optional"
+local installer = require "mason.core.installer"
+local cargo = require "mason.core.managers.cargo"
+local Result = require "mason.core.result"
+local spawn = require "mason.core.spawn"
+local path = require "mason.core.path"
describe("cargo manager", function()
- ---@type InstallContext
- local ctx
- before_each(function()
- ctx = InstallContextGenerator {
- spawn = mock.new {
- cargo = mockx.returns {},
- },
- }
- end)
-
it(
"should call cargo install",
async_test(function()
- ctx.requested_version = Optional.of "42.13.37"
+ local handle = InstallHandleGenerator "dummy"
+ local ctx = InstallContextGenerator(handle, { requested_version = "42.13.37" })
installer.run_installer(ctx, cargo.crate "my-crate")
assert.spy(ctx.spawn.cargo).was_called(1)
assert.spy(ctx.spawn.cargo).was_called_with {
@@ -39,6 +31,8 @@ describe("cargo manager", function()
it(
"should call cargo install with git source",
async_test(function()
+ local handle = InstallHandleGenerator "dummy"
+ local ctx = InstallContextGenerator(handle)
installer.run_installer(ctx, cargo.crate("https://my-crate.git", { git = true }))
assert.spy(ctx.spawn.cargo).was_called(1)
assert.spy(ctx.spawn.cargo).was_called_with {
@@ -56,6 +50,8 @@ describe("cargo manager", function()
it(
"should call cargo install with git source and a specific crate",
async_test(function()
+ local handle = InstallHandleGenerator "dummy"
+ local ctx = InstallContextGenerator(handle)
installer.run_installer(ctx, cargo.crate("crate-name", { git = "https://my-crate.git" }))
assert.spy(ctx.spawn.cargo).was_called(1)
assert.spy(ctx.spawn.cargo).was_called_with {
@@ -73,7 +69,8 @@ describe("cargo manager", function()
it(
"should respect options",
async_test(function()
- ctx.requested_version = Optional.of "42.13.37"
+ local handle = InstallHandleGenerator "dummy"
+ local ctx = InstallContextGenerator(handle, { requested_version = "42.13.37" })
installer.run_installer(ctx, cargo.crate("my-crate", { features = "lsp" }))
assert.spy(ctx.spawn.cargo).was_called(1)
assert.spy(ctx.spawn.cargo).was_called_with {
@@ -91,7 +88,8 @@ describe("cargo manager", function()
it(
"should not allow combining version with git crate",
async_test(function()
- ctx.requested_version = Optional.of "42.13.37"
+ local handle = InstallHandleGenerator "dummy"
+ local ctx = InstallContextGenerator(handle, { requested_version = "42.13.37" })
local err = assert.has_error(function()
installer.run_installer(
ctx,
@@ -108,6 +106,8 @@ describe("cargo manager", function()
it(
"should provide receipt information",
async_test(function()
+ local handle = InstallHandleGenerator "dummy"
+ local ctx = InstallContextGenerator(handle)
installer.run_installer(ctx, cargo.crate "main-package")
assert.same({
type = "cargo",
@@ -165,7 +165,7 @@ zoxide v0.5.0:
package = "https://github.com/influxdata/flux-lsp",
},
},
- "/tmp/install/dir"
+ path.package_prefix "dummy"
)
assert.spy(spawn.cargo).was_called(1)
@@ -174,7 +174,7 @@ zoxide v0.5.0:
"--list",
"--root",
".",
- cwd = "/tmp/install/dir",
+ cwd = path.package_prefix "dummy",
})
assert.is_true(result:is_success())
assert.equals("0.8.8", result:get_or_nil())
@@ -202,7 +202,7 @@ zoxide v0.5.0:
package = "lelwel",
},
},
- "/tmp/install/dir"
+ path.package_prefix "dummy"
)
assert.spy(spawn.cargo).was_called(1)
@@ -211,7 +211,7 @@ zoxide v0.5.0:
"--list",
"--root",
".",
- cwd = "/tmp/install/dir",
+ cwd = path.package_prefix "dummy",
})
assert.is_true(result:is_success())
assert.is_true(match.tbl_containing {
diff --git a/tests/core/managers/composer_spec.lua b/tests/core/managers/composer_spec.lua
index cd3d7556..48cb4784 100644
--- a/tests/core/managers/composer_spec.lua
+++ b/tests/core/managers/composer_spec.lua
@@ -1,27 +1,19 @@
local spy = require "luassert.spy"
local mock = require "luassert.mock"
-local installer = require "nvim-lsp-installer.core.installer"
-local Optional = require "nvim-lsp-installer.core.optional"
-local composer = require "nvim-lsp-installer.core.managers.composer"
-local Result = require "nvim-lsp-installer.core.result"
-local spawn = require "nvim-lsp-installer.core.spawn"
+local installer = require "mason.core.installer"
+local Optional = require "mason.core.optional"
+local composer = require "mason.core.managers.composer"
+local Result = require "mason.core.result"
+local spawn = require "mason.core.spawn"
+local path = require "mason.core.path"
describe("composer manager", function()
- ---@type InstallContext
- local ctx
- before_each(function()
- ctx = InstallContextGenerator {
- spawn = mock.new {
- composer = mockx.returns {},
- },
- }
- end)
-
it(
"should call composer require",
async_test(function()
- ctx.fs.file_exists = mockx.returns(false)
- ctx.requested_version = Optional.of "42.13.37"
+ local handle = InstallHandleGenerator "dummy"
+ local ctx = InstallContextGenerator(handle, { requested_version = "42.13.37" })
+ ctx.fs.file_exists = spy.new(mockx.returns(false))
installer.run_installer(
ctx,
composer.packages { "main-package", "supporting-package", "supporting-package2" }
@@ -46,7 +38,8 @@ describe("composer manager", function()
it(
"should provide receipt information",
async_test(function()
- ctx.requested_version = Optional.of "42.13.37"
+ local handle = InstallHandleGenerator "dummy"
+ local ctx = InstallContextGenerator(handle, { requested_version = "42.13.37" })
installer.run_installer(
ctx,
composer.packages { "main-package", "supporting-package", "supporting-package2" }
@@ -93,7 +86,7 @@ describe("composer version check", function()
package = "vimeo/psalm",
},
},
- "/tmp/install/dir"
+ path.package_prefix "dummy"
)
assert.spy(spawn.composer).was_called(1)
@@ -101,7 +94,7 @@ describe("composer version check", function()
"info",
"--format=json",
"vimeo/psalm",
- cwd = "/tmp/install/dir",
+ cwd = path.package_prefix "dummy",
}
assert.is_true(result:is_success())
assert.equals("4.0.0", result:get_or_nil())
@@ -138,7 +131,7 @@ describe("composer version check", function()
package = "vimeo/psalm",
},
},
- "/tmp/install/dir"
+ path.package_prefix "dummy"
)
assert.spy(spawn.composer).was_called(1)
@@ -146,7 +139,7 @@ describe("composer version check", function()
"outdated",
"--no-interaction",
"--format=json",
- cwd = "/tmp/install/dir",
+ cwd = path.package_prefix "dummy",
}
assert.is_true(result:is_success())
assert.same({
@@ -175,7 +168,7 @@ describe("composer version check", function()
package = "vimeo/psalm",
},
},
- "/tmp/install/dir"
+ path.package_prefix "dummy"
)
assert.is_true(result:is_failure())
diff --git a/tests/core/managers/dotnet_spec.lua b/tests/core/managers/dotnet_spec.lua
index d900bd17..ff922720 100644
--- a/tests/core/managers/dotnet_spec.lua
+++ b/tests/core/managers/dotnet_spec.lua
@@ -1,23 +1,12 @@
-local mock = require "luassert.mock"
-local Optional = require "nvim-lsp-installer.core.optional"
-local installer = require "nvim-lsp-installer.core.installer"
-local dotnet = require "nvim-lsp-installer.core.managers.dotnet"
+local installer = require "mason.core.installer"
+local dotnet = require "mason.core.managers.dotnet"
describe("dotnet manager", function()
- ---@type InstallContext
- local ctx
- before_each(function()
- ctx = InstallContextGenerator {
- spawn = mock.new {
- dotnet = mockx.returns {},
- },
- }
- end)
-
it(
"should call dotnet tool update",
async_test(function()
- ctx.requested_version = Optional.of "42.13.37"
+ local handle = InstallHandleGenerator "dummy"
+ local ctx = InstallContextGenerator(handle, { requested_version = "42.13.37" })
installer.run_installer(ctx, dotnet.package "main-package")
assert.spy(ctx.spawn.dotnet).was_called(1)
assert.spy(ctx.spawn.dotnet).was_called_with {
@@ -34,7 +23,8 @@ describe("dotnet manager", function()
it(
"should provide receipt information",
async_test(function()
- ctx.requested_version = Optional.of "42.13.37"
+ local handle = InstallHandleGenerator "dummy"
+ local ctx = InstallContextGenerator(handle, { requested_version = "42.13.37" })
installer.run_installer(ctx, dotnet.package "main-package")
assert.same({
type = "dotnet",
diff --git a/tests/core/managers/gem_spec.lua b/tests/core/managers/gem_spec.lua
index 5e8d92bb..5beb6c95 100644
--- a/tests/core/managers/gem_spec.lua
+++ b/tests/core/managers/gem_spec.lua
@@ -1,27 +1,18 @@
local spy = require "luassert.spy"
local match = require "luassert.match"
local mock = require "luassert.mock"
-local installer = require "nvim-lsp-installer.core.installer"
-local Optional = require "nvim-lsp-installer.core.optional"
-local gem = require "nvim-lsp-installer.core.managers.gem"
-local Result = require "nvim-lsp-installer.core.result"
-local spawn = require "nvim-lsp-installer.core.spawn"
+local installer = require "mason.core.installer"
+local Optional = require "mason.core.optional"
+local gem = require "mason.core.managers.gem"
+local Result = require "mason.core.result"
+local spawn = require "mason.core.spawn"
describe("gem manager", function()
- ---@type InstallContext
- local ctx
- before_each(function()
- ctx = InstallContextGenerator {
- spawn = mock.new {
- gem = mockx.returns {},
- },
- }
- end)
-
it(
"should call gem install",
async_test(function()
- ctx.requested_version = Optional.of "42.13.37"
+ local handle = InstallHandleGenerator "dummy"
+ local ctx = InstallContextGenerator(handle, { requested_version = "42.13.37" })
installer.run_installer(ctx, gem.packages { "main-package", "supporting-package", "supporting-package2" })
assert.spy(ctx.spawn.gem).was_called(1)
assert.spy(ctx.spawn.gem).was_called_with(match.tbl_containing {
@@ -42,7 +33,8 @@ describe("gem manager", function()
it(
"should provide receipt information",
async_test(function()
- ctx.requested_version = Optional.of "42.13.37"
+ local handle = InstallHandleGenerator "dummy"
+ local ctx = InstallContextGenerator(handle, { requested_version = "42.13.37" })
installer.run_installer(ctx, gem.packages { "main-package", "supporting-package", "supporting-package2" })
assert.same({
type = "gem",
diff --git a/tests/core/managers/git_spec.lua b/tests/core/managers/git_spec.lua
index 1b73c5f6..f6a3f9d1 100644
--- a/tests/core/managers/git_spec.lua
+++ b/tests/core/managers/git_spec.lua
@@ -1,26 +1,18 @@
local spy = require "luassert.spy"
local mock = require "luassert.mock"
-local spawn = require "nvim-lsp-installer.core.spawn"
-local Result = require "nvim-lsp-installer.core.result"
-local installer = require "nvim-lsp-installer.core.installer"
+local spawn = require "mason.core.spawn"
+local Result = require "mason.core.result"
+local installer = require "mason.core.installer"
-local git = require "nvim-lsp-installer.core.managers.git"
-local Optional = require "nvim-lsp-installer.core.optional"
+local git = require "mason.core.managers.git"
+local Optional = require "mason.core.optional"
describe("git manager", function()
- ---@type InstallContext
- local ctx
- before_each(function()
- ctx = InstallContextGenerator {
- spawn = mock.new {
- git = mockx.returns {},
- },
- }
- end)
-
it(
"should fail if no git repo provided",
async_test(function()
+ local handle = InstallHandleGenerator "dummy"
+ local ctx = InstallContextGenerator(handle)
local err = assert.has_errors(function()
installer.run_installer(ctx, function()
git.clone {}
@@ -34,8 +26,10 @@ describe("git manager", function()
it(
"should clone provided repo",
async_test(function()
+ local handle = InstallHandleGenerator "dummy"
+ local ctx = InstallContextGenerator(handle)
installer.run_installer(ctx, function()
- git.clone { "https://github.com/williamboman/nvim-lsp-installer.git" }
+ git.clone { "https://github.com/williamboman/mason.nvim.git" }
end)
assert.spy(ctx.spawn.git).was_called(1)
assert.spy(ctx.spawn.git).was_called_with {
@@ -43,7 +37,7 @@ describe("git manager", function()
"--depth",
"1",
vim.NIL,
- "https://github.com/williamboman/nvim-lsp-installer.git",
+ "https://github.com/williamboman/mason.nvim.git",
".",
}
end)
@@ -52,9 +46,10 @@ describe("git manager", function()
it(
"should fetch and checkout revision if requested",
async_test(function()
- ctx.requested_version = Optional.of "1337"
+ local handle = InstallHandleGenerator "dummy"
+ local ctx = InstallContextGenerator(handle, { requested_version = "1337" })
installer.run_installer(ctx, function()
- git.clone { "https://github.com/williamboman/nvim-lsp-installer.git" }
+ git.clone { "https://github.com/williamboman/mason.nvim.git" }
end)
assert.spy(ctx.spawn.git).was_called(3)
assert.spy(ctx.spawn.git).was_called_with {
@@ -62,7 +57,7 @@ describe("git manager", function()
"--depth",
"1",
vim.NIL,
- "https://github.com/williamboman/nvim-lsp-installer.git",
+ "https://github.com/williamboman/mason.nvim.git",
".",
}
assert.spy(ctx.spawn.git).was_called_with {
@@ -79,12 +74,14 @@ describe("git manager", function()
it(
"should provide receipt information",
async_test(function()
+ local handle = InstallHandleGenerator "dummy"
+ local ctx = InstallContextGenerator(handle)
installer.run_installer(ctx, function()
- git.clone({ "https://github.com/williamboman/nvim-lsp-installer.git" }).with_receipt()
+ git.clone({ "https://github.com/williamboman/mason.nvim.git" }).with_receipt()
end)
assert.same({
type = "git",
- remote = "https://github.com/williamboman/nvim-lsp-installer.git",
+ remote = "https://github.com/williamboman/mason.nvim.git",
}, ctx.receipt.primary_source)
assert.is_true(#ctx.receipt.secondary_sources == 0)
end)
@@ -101,7 +98,7 @@ describe("git version check", function()
}
end)
- local result = git.get_installed_revision "/tmp/install/dir"
+ local result = git.get_installed_revision({ type = "git" }, "/tmp/install/dir")
assert.spy(spawn.git).was_called(1)
assert.spy(spawn.git).was_called_with { "rev-parse", "--short", "HEAD", cwd = "/tmp/install/dir" }
@@ -126,7 +123,7 @@ describe("git version check", function()
mock.new {
primary_source = mock.new {
type = "git",
- remote = "https://github.com/williamboman/nvim-lsp-installer.git",
+ remote = "https://github.com/williamboman/mason.nvim.git",
},
},
"/tmp/install/dir"
@@ -147,7 +144,7 @@ describe("git version check", function()
}
assert.is_true(result:is_success())
assert.same({
- name = "https://github.com/williamboman/nvim-lsp-installer.git",
+ name = "https://github.com/williamboman/mason.nvim.git",
current_version = "19c668cd10695b243b09452f0dfd53570c1a2e7d",
latest_version = "728307a74cd5f2dec7ca2ca164785c25673d6328",
}, result:get_or_nil())
@@ -170,7 +167,7 @@ describe("git version check", function()
mock.new {
primary_source = mock.new {
type = "git",
- remote = "https://github.com/williamboman/nvim-lsp-installer.git",
+ remote = "https://github.com/williamboman/mason.nvim.git",
},
},
"/tmp/install/dir"
diff --git a/tests/core/managers/github_client_spec.lua b/tests/core/managers/github_client_spec.lua
index 47ee960e..11e8c392 100644
--- a/tests/core/managers/github_client_spec.lua
+++ b/tests/core/managers/github_client_spec.lua
@@ -1,4 +1,4 @@
-local client = require "nvim-lsp-installer.core.managers.github.client"
+local client = require "mason.core.managers.github.client"
describe("github client", function()
---@type GitHubRelease
diff --git a/tests/core/managers/go_spec.lua b/tests/core/managers/go_spec.lua
index fdaf7f85..62c8e8d4 100644
--- a/tests/core/managers/go_spec.lua
+++ b/tests/core/managers/go_spec.lua
@@ -1,46 +1,37 @@
local mock = require "luassert.mock"
local stub = require "luassert.stub"
local spy = require "luassert.spy"
-local Optional = require "nvim-lsp-installer.core.optional"
-local Result = require "nvim-lsp-installer.core.result"
-local go = require "nvim-lsp-installer.core.managers.go"
-local spawn = require "nvim-lsp-installer.core.spawn"
-local installer = require "nvim-lsp-installer.core.installer"
+local Result = require "mason.core.result"
+local go = require "mason.core.managers.go"
+local spawn = require "mason.core.spawn"
+local installer = require "mason.core.installer"
+local path = require "mason.core.path"
describe("go manager", function()
- ---@type InstallContext
- local ctx
- before_each(function()
- ctx = InstallContextGenerator {
- spawn = mock.new {
- go = mockx.returns {},
- },
- }
- end)
-
it(
"should call go install",
async_test(function()
- ctx.requested_version = Optional.of "42.13.37"
+ local handle = InstallHandleGenerator "dummy"
+ local ctx = InstallContextGenerator(handle, { requested_version = "42.13.37" })
installer.run_installer(ctx, go.packages { "main-package", "supporting-package", "supporting-package2" })
assert.spy(ctx.spawn.go).was_called(3)
assert.spy(ctx.spawn.go).was_called_with {
"install",
"-v",
"main-package@42.13.37",
- env = { GOBIN = "/tmp/install-dir" },
+ env = { GOBIN = path.package_build_prefix "dummy" },
}
assert.spy(ctx.spawn.go).was_called_with {
"install",
"-v",
"supporting-package@latest",
- env = { GOBIN = "/tmp/install-dir" },
+ env = { GOBIN = path.package_build_prefix "dummy" },
}
assert.spy(ctx.spawn.go).was_called_with {
"install",
"-v",
"supporting-package2@latest",
- env = { GOBIN = "/tmp/install-dir" },
+ env = { GOBIN = path.package_build_prefix "dummy" },
}
end)
)
@@ -48,7 +39,8 @@ describe("go manager", function()
it(
"should provide receipt information",
async_test(function()
- ctx.requested_version = Optional.of "42.13.37"
+ local handle = InstallHandleGenerator "dummy"
+ local ctx = InstallContextGenerator(handle, { requested_version = "42.13.37" })
installer.run_installer(ctx, go.packages { "main-package", "supporting-package", "supporting-package2" })
assert.same({
type = "go",
@@ -103,7 +95,7 @@ gopls: go1.18
package = "golang.org/x/tools/gopls",
},
},
- "/tmp/install/dir"
+ path.package_prefix "dummy"
)
assert.spy(spawn.go).was_called(1)
@@ -111,7 +103,7 @@ gopls: go1.18
"version",
"-m",
"gopls",
- cwd = "/tmp/install/dir",
+ cwd = path.package_prefix "dummy",
}
assert.is_true(result:is_success())
assert.equals("v0.8.1", result:get_or_nil())
@@ -129,20 +121,20 @@ gopls: go1.18
"-json",
"-m",
"golang.org/x/tools/gopls@latest",
- cwd = "/tmp/install/dir",
+ cwd = path.package_prefix "dummy",
}).returns(Result.success {
- stdout = [[
+ stdout = ([[
{
- "Path": "/tmp/install/dir",
+ "Path": %q,
"Version": "v2.0.0"
}
- ]],
+ ]]):format(path.package_prefix "dummy"),
})
spawn.go.on_call_with({
"version",
"-m",
"gopls",
- cwd = "/tmp/install/dir",
+ cwd = path.package_prefix "dummy",
}).returns(Result.success {
stdout = go_version_output,
})
@@ -154,7 +146,7 @@ gopls: go1.18
package = "golang.org/x/tools/gopls",
},
},
- "/tmp/install/dir"
+ path.package_prefix "dummy"
)
assert.is_true(result:is_success())
diff --git a/tests/core/managers/luarocks_spec.lua b/tests/core/managers/luarocks_spec.lua
index 9c7e9f70..b7321130 100644
--- a/tests/core/managers/luarocks_spec.lua
+++ b/tests/core/managers/luarocks_spec.lua
@@ -1,28 +1,20 @@
-local mock = require "luassert.mock"
-local installer = require "nvim-lsp-installer.core.installer"
-local luarocks = require "nvim-lsp-installer.core.managers.luarocks"
-local Optional = require "nvim-lsp-installer.core.optional"
+local installer = require "mason.core.installer"
+local luarocks = require "mason.core.managers.luarocks"
+local path = require "mason.core.path"
describe("luarocks manager", function()
- ---@type InstallContext
- local ctx
- before_each(function()
- ctx = InstallContextGenerator {
- spawn = mock.new {
- luarocks = mockx.returns {},
- },
- }
- end)
-
it(
"should install provided package",
async_test(function()
+ local handle = InstallHandleGenerator "dummy"
+ local ctx = InstallContextGenerator(handle)
installer.run_installer(ctx, luarocks.package "lua-cjson")
assert.spy(ctx.spawn.luarocks).was_called(1)
+ print(vim.inspect(ctx.spawn.luarocks))
assert.spy(ctx.spawn.luarocks).was_called_with {
"install",
"--tree",
- "/tmp/install-dir",
+ path.package_prefix "dummy",
vim.NIL, -- --dev flag
"lua-cjson",
vim.NIL, -- version
@@ -33,13 +25,14 @@ describe("luarocks manager", function()
it(
"should install provided version",
async_test(function()
- ctx.requested_version = Optional.of "1.2.3"
+ local handle = InstallHandleGenerator "dummy"
+ local ctx = InstallContextGenerator(handle, { requested_version = "1.2.3"})
installer.run_installer(ctx, luarocks.package "lua-cjson")
assert.spy(ctx.spawn.luarocks).was_called(1)
assert.spy(ctx.spawn.luarocks).was_called_with {
"install",
"--tree",
- "/tmp/install-dir",
+ path.package_prefix "dummy",
vim.NIL, -- --dev flag
"lua-cjson",
"1.2.3",
@@ -50,12 +43,14 @@ describe("luarocks manager", function()
it(
"should provide --dev flag",
async_test(function()
+ local handle = InstallHandleGenerator "dummy"
+ local ctx = InstallContextGenerator(handle)
installer.run_installer(ctx, luarocks.package("lua-cjson", { dev = true }))
assert.spy(ctx.spawn.luarocks).was_called(1)
assert.spy(ctx.spawn.luarocks).was_called_with {
"install",
"--tree",
- "/tmp/install-dir",
+ path.package_prefix "dummy",
"--dev",
"lua-cjson",
vim.NIL, -- version
diff --git a/tests/core/managers/npm_spec.lua b/tests/core/managers/npm_spec.lua
index ab2cb1f4..a2170a63 100644
--- a/tests/core/managers/npm_spec.lua
+++ b/tests/core/managers/npm_spec.lua
@@ -1,29 +1,19 @@
local spy = require "luassert.spy"
local match = require "luassert.match"
local mock = require "luassert.mock"
-local Optional = require "nvim-lsp-installer.core.optional"
-local installer = require "nvim-lsp-installer.core.installer"
-local npm = require "nvim-lsp-installer.core.managers.npm"
-local Result = require "nvim-lsp-installer.core.result"
-local spawn = require "nvim-lsp-installer.core.spawn"
+local installer = require "mason.core.installer"
+local npm = require "mason.core.managers.npm"
+local Result = require "mason.core.result"
+local spawn = require "mason.core.spawn"
+local path = require "mason.core.path"
describe("npm manager", function()
- ---@type InstallContext
- local ctx
- before_each(function()
- ctx = InstallContextGenerator {
- spawn = mock.new {
- npm = mockx.returns {},
- },
- }
- end)
-
it(
"should call npm install",
async_test(function()
- ctx.requested_version = Optional.of "42.13.37"
+ local handle = InstallHandleGenerator "dummy"
+ local ctx = InstallContextGenerator(handle, { requested_version = "42.13.37" })
installer.run_installer(ctx, npm.packages { "main-package", "supporting-package", "supporting-package2" })
- assert.spy(ctx.spawn.npm).was_called(1)
assert.spy(ctx.spawn.npm).was_called_with(match.tbl_containing {
"install",
match.tbl_containing {
@@ -38,6 +28,8 @@ describe("npm manager", function()
it(
"should call npm init if node_modules and package.json doesnt exist",
async_test(function()
+ local handle = InstallHandleGenerator "dummy"
+ local ctx = InstallContextGenerator(handle)
ctx.fs.file_exists = mockx.returns(false)
ctx.fs.dir_exists = mockx.returns(false)
installer.run_installer(ctx, function()
@@ -46,7 +38,7 @@ describe("npm manager", function()
assert.spy(ctx.spawn.npm).was_called_with {
"init",
"--yes",
- "--scope=lsp-installer",
+ "--scope=mason",
}
end)
)
@@ -54,7 +46,9 @@ describe("npm manager", function()
it(
"should append .npmrc file",
async_test(function()
- ctx.requested_version = Optional.of "42.13.37"
+ local handle = InstallHandleGenerator "dummy"
+ local ctx = InstallContextGenerator(handle, { requested_version = "42.13.37" })
+ ctx.fs.append_file = spy.new(mockx.just_runs())
installer.run_installer(ctx, npm.packages { "main-package", "supporting-package", "supporting-package2" })
assert.spy(ctx.fs.append_file).was_called(1)
assert.spy(ctx.fs.append_file).was_called_with(ctx.fs, ".npmrc", "global-style=true")
@@ -64,7 +58,8 @@ describe("npm manager", function()
it(
"should provide receipt information",
async_test(function()
- ctx.requested_version = Optional.of "42.13.37"
+ local handle = InstallHandleGenerator "dummy"
+ local ctx = InstallContextGenerator(handle, { requested_version = "42.13.37" })
installer.run_installer(ctx, npm.packages { "main-package", "supporting-package", "supporting-package2" })
assert.same({
type = "npm",
@@ -111,11 +106,11 @@ describe("npm version check", function()
package = "bash-language-server",
},
},
- "/tmp/install/dir"
+ path.package_prefix "dummy"
)
assert.spy(spawn.npm).was_called(1)
- assert.spy(spawn.npm).was_called_with { "ls", "--json", cwd = "/tmp/install/dir" }
+ assert.spy(spawn.npm).was_called_with { "ls", "--json", cwd = path.package_prefix "dummy" }
assert.is_true(result:is_success())
assert.equals("2.0.0", result:get_or_nil())
@@ -151,7 +146,7 @@ describe("npm version check", function()
package = "bash-language-server",
},
},
- "/tmp/install/dir"
+ path.package_prefix "dummy"
)
assert.spy(spawn.npm).was_called(1)
@@ -159,7 +154,7 @@ describe("npm version check", function()
"outdated",
"--json",
"bash-language-server",
- cwd = "/tmp/install/dir",
+ cwd = path.package_prefix "dummy",
}
assert.is_true(result:is_success())
assert.same({
@@ -188,7 +183,7 @@ describe("npm version check", function()
package = "bash-language-server",
},
},
- "/tmp/install/dir"
+ path.package_prefix "dummy"
)
assert.is_true(result:is_failure())
diff --git a/tests/core/managers/opam_spec.lua b/tests/core/managers/opam_spec.lua
index 8f1ebe5d..1a279fde 100644
--- a/tests/core/managers/opam_spec.lua
+++ b/tests/core/managers/opam_spec.lua
@@ -1,24 +1,15 @@
local match = require "luassert.match"
local mock = require "luassert.mock"
-local Optional = require "nvim-lsp-installer.core.optional"
-local installer = require "nvim-lsp-installer.core.installer"
-local opam = require "nvim-lsp-installer.core.managers.opam"
+local Optional = require "mason.core.optional"
+local installer = require "mason.core.installer"
+local opam = require "mason.core.managers.opam"
describe("opam manager", function()
- ---@type InstallContext
- local ctx
- before_each(function()
- ctx = InstallContextGenerator {
- spawn = mock.new {
- opam = mockx.returns {},
- },
- }
- end)
-
it(
"should call opam install",
async_test(function()
- ctx.requested_version = Optional.of "42.13.37"
+ local handle = InstallHandleGenerator "dummy"
+ local ctx = InstallContextGenerator(handle, { requested_version = "42.13.37" })
installer.run_installer(ctx, opam.packages { "main-package", "supporting-package", "supporting-package2" })
assert.spy(ctx.spawn.opam).was_called(1)
assert.spy(ctx.spawn.opam).was_called_with(match.tbl_containing {
@@ -38,7 +29,8 @@ describe("opam manager", function()
it(
"should provide receipt information",
async_test(function()
- ctx.requested_version = Optional.of "42.13.37"
+ local handle = InstallHandleGenerator "dummy"
+ local ctx = InstallContextGenerator(handle, { requested_version = "42.13.37" })
installer.run_installer(ctx, opam.packages { "main-package", "supporting-package", "supporting-package2" })
assert.same({
type = "opam",
diff --git a/tests/core/managers/pip3_spec.lua b/tests/core/managers/pip3_spec.lua
index 7a6a94c5..17489fe9 100644
--- a/tests/core/managers/pip3_spec.lua
+++ b/tests/core/managers/pip3_spec.lua
@@ -1,25 +1,15 @@
local mock = require "luassert.mock"
local spy = require "luassert.spy"
+local path = require "mason.core.path"
-local pip3 = require "nvim-lsp-installer.core.managers.pip3"
-local Optional = require "nvim-lsp-installer.core.optional"
-local installer = require "nvim-lsp-installer.core.installer"
-local Result = require "nvim-lsp-installer.core.result"
-local settings = require "nvim-lsp-installer.settings"
-local spawn = require "nvim-lsp-installer.core.spawn"
+local pip3 = require "mason.core.managers.pip3"
+local Optional = require "mason.core.optional"
+local installer = require "mason.core.installer"
+local Result = require "mason.core.result"
+local settings = require "mason.settings"
+local spawn = require "mason.core.spawn"
describe("pip3 manager", function()
- ---@type InstallContext
- local ctx
- before_each(function()
- ctx = InstallContextGenerator {
- spawn = mock.new {
- python = mockx.returns {},
- python3 = mockx.returns {},
- },
- }
- end)
-
it("normalizes pip3 packages", function()
local normalize = pip3.normalize_package
assert.equal("python-lsp-server", normalize "python-lsp-server[all]")
@@ -30,9 +20,10 @@ describe("pip3 manager", function()
it(
"should create venv and call pip3 install",
async_test(function()
- ctx.requested_version = Optional.of "42.13.37"
+ local handle = InstallHandleGenerator "dummy"
+ local ctx = InstallContextGenerator(handle, { requested_version = "42.13.37" })
installer.run_installer(ctx, pip3.packages { "main-package", "supporting-package", "supporting-package2" })
- assert.spy(ctx.promote_cwd).was_called(1)
+ assert.equals(path.package_prefix "dummy", ctx.cwd:get()) -- should've promoted cwd
assert.spy(ctx.spawn.python3).was_called(1)
assert.spy(ctx.spawn.python3).was_called_with {
"-m",
@@ -43,6 +34,7 @@ describe("pip3 manager", function()
assert.spy(ctx.spawn.python).was_called_with {
"-m",
"pip",
+ "--disable-pip-version-check",
"install",
"-U",
{},
@@ -51,7 +43,7 @@ describe("pip3 manager", function()
"supporting-package",
"supporting-package2",
},
- with_paths = { "/tmp/install-dir/venv/bin" },
+ with_paths = { path.concat { path.package_prefix "dummy", "venv", "bin" } },
}
end)
)
@@ -60,11 +52,11 @@ describe("pip3 manager", function()
"should exhaust python3 executable candidates if all fail",
async_test(function()
vim.g.python3_host_prog = "/my/python3"
- ctx.spawn = mock.new {
- python3 = mockx.throws(),
- python = mockx.throws(),
- [vim.g.python3_host_prog] = mockx.throws(),
- }
+ local handle = InstallHandleGenerator "dummy"
+ local ctx = InstallContextGenerator(handle)
+ ctx.spawn.python3 = spy.new(mockx.throws())
+ ctx.spawn.python = spy.new(mockx.throws())
+ ctx.spawn[vim.g.python3_host_prog] = spy.new(mockx.throws())
local err = assert.has_error(function()
installer.run_installer(ctx, pip3.packages { "package" })
end)
@@ -81,11 +73,12 @@ describe("pip3 manager", function()
"should not exhaust python3 executable if one succeeds",
async_test(function()
vim.g.python3_host_prog = "/my/python3"
- ctx.spawn = mock.new {
- python3 = mockx.throws(),
- python = mockx.returns {},
- [vim.g.python3_host_prog] = mockx.returns {},
- }
+ local handle = InstallHandleGenerator "dummy"
+ local ctx = InstallContextGenerator(handle)
+ ctx.spawn.python3 = spy.new(mockx.throws())
+ ctx.spawn.python = spy.new(mockx.returns {})
+ ctx.spawn[vim.g.python3_host_prog] = spy.new(mockx.returns {})
+
installer.run_installer(ctx, pip3.packages { "package" })
vim.g.python3_host_prog = nil
assert.spy(ctx.spawn.python3).was_called(0)
@@ -102,16 +95,18 @@ describe("pip3 manager", function()
install_args = { "--proxy", "http://localhost:8080" },
},
}
+ local handle = InstallHandleGenerator "dummy"
+ local ctx = InstallContextGenerator(handle)
installer.run_installer(ctx, pip3.packages { "package" })
- settings.set(settings._DEFAULT_SETTINGS)
assert.spy(ctx.spawn.python).was_called_with {
"-m",
"pip",
+ "--disable-pip-version-check",
"install",
"-U",
{ "--proxy", "http://localhost:8080" },
{ "package" },
- with_paths = { "/tmp/install-dir/venv/bin" },
+ with_paths = { path.concat { path.package_prefix "dummy", "venv", "bin" } },
}
end)
)
@@ -119,7 +114,8 @@ describe("pip3 manager", function()
it(
"should provide receipt information",
async_test(function()
- ctx.requested_version = Optional.of "42.13.37"
+ local handle = InstallHandleGenerator "dummy"
+ local ctx = InstallContextGenerator(handle, { requested_version = "42.13.37" })
installer.run_installer(ctx, pip3.packages { "main-package", "supporting-package", "supporting-package2" })
assert.same({
type = "pip3",
@@ -158,7 +154,7 @@ describe("pip3 version check", function()
package = "python-lsp-server",
},
},
- "/tmp/install/dir"
+ path.package_prefix "dummy"
)
assert.spy(spawn.python).was_called(1)
@@ -167,8 +163,8 @@ describe("pip3 version check", function()
"pip",
"list",
"--format=json",
- cwd = "/tmp/install/dir",
- with_paths = { "/tmp/install/dir/venv/bin" },
+ cwd = path.package_prefix "dummy",
+ with_paths = { path.concat { path.package_prefix "dummy", "venv", "bin" } },
}
assert.is_true(result:is_success())
assert.equals("1.3.0", result:get_or_nil())
@@ -195,7 +191,7 @@ describe("pip3 version check", function()
package = "python-lsp-server",
},
},
- "/tmp/install/dir"
+ path.package_prefix "dummy"
)
assert.spy(spawn.python).was_called(1)
@@ -205,8 +201,8 @@ describe("pip3 version check", function()
"list",
"--outdated",
"--format=json",
- cwd = "/tmp/install/dir",
- with_paths = { "/tmp/install/dir/venv/bin" },
+ cwd = path.package_prefix "dummy",
+ with_paths = { path.concat { path.package_prefix "dummy", "venv", "bin" } },
}
assert.is_true(result:is_success())
assert.same({
diff --git a/tests/core/optional_spec.lua b/tests/core/optional_spec.lua
index 02f8800e..8a33def4 100644
--- a/tests/core/optional_spec.lua
+++ b/tests/core/optional_spec.lua
@@ -1,4 +1,4 @@
-local Optional = require "nvim-lsp-installer.core.optional"
+local Optional = require "mason.core.optional"
local spy = require "luassert.spy"
describe("Optional.of_nilable", function()
diff --git a/tests/core/path_spec.lua b/tests/core/path_spec.lua
index e4e964d9..3d05fd14 100644
--- a/tests/core/path_spec.lua
+++ b/tests/core/path_spec.lua
@@ -1,4 +1,4 @@
-local path = require "nvim-lsp-installer.core.path"
+local path = require "mason.core.path"
describe("path", function()
it("concatenates paths", function()
@@ -8,8 +8,8 @@ describe("path", function()
it("concatenates paths on Windows", function()
local old_os = jit.os
jit.os = "windows"
- package.loaded["nvim-lsp-installer.core.path"] = nil
- local path = require "nvim-lsp-installer.core.path"
+ package.loaded["mason.core.path"] = nil
+ local path = require "mason.core.path"
assert.equal([[foo\bar\baz\~]], path.concat { "foo", "bar", "baz", "~" })
jit.os = old_os
end)
diff --git a/tests/core/platform_spec.lua b/tests/core/platform_spec.lua
index 96d3b879..54a06f7a 100644
--- a/tests/core/platform_spec.lua
+++ b/tests/core/platform_spec.lua
@@ -4,8 +4,8 @@ local match = require "luassert.match"
describe("platform", function()
local function platform()
- package.loaded["nvim-lsp-installer.core.platform"] = nil
- return require "nvim-lsp-installer.core.platform"
+ package.loaded["mason.core.platform"] = nil
+ return require "mason.core.platform"
end
local function stub_mac(arch)
diff --git a/tests/core/process_spec.lua b/tests/core/process_spec.lua
index 277f082b..8eb79e05 100644
--- a/tests/core/process_spec.lua
+++ b/tests/core/process_spec.lua
@@ -1,64 +1,6 @@
local spy = require "luassert.spy"
-local process = require "nvim-lsp-installer.core.process"
-
-describe("process.attempt", function()
- it("should attempt job variants until first successful one", function()
- local on_finish = spy.new()
- local on_iterate = spy.new()
- local success = function(cb)
- cb(true)
- end
- local fail = function(cb)
- cb(false)
- end
-
- local job1 = spy.new(fail)
- local job2 = spy.new(fail)
- local job3 = spy.new(success)
- local job4 = spy.new(success)
- local job5 = spy.new(fail)
-
- process.attempt {
- jobs = { job1, job2, job3, job4, job5 },
- on_iterate = on_iterate,
- on_finish = on_finish,
- }
-
- assert.spy(job1).was_called(1)
- assert.spy(job2).was_called(1)
- assert.spy(job3).was_called(1)
- assert.spy(job4).was_called(0)
- assert.spy(job5).was_called(0)
- assert.spy(on_iterate).was_called(2)
- assert.spy(on_finish).was_called(1)
- assert.spy(on_finish).was_called_with(true)
- end)
-
- it("should call on_finish with false if all variants fail", function()
- local on_finish = spy.new()
- local on_iterate = spy.new()
- local fail = function(cb)
- cb(false)
- end
-
- local job1 = spy.new(fail)
- local job2 = spy.new(fail)
- local job3 = spy.new(fail)
-
- process.attempt {
- jobs = { job1, job2, job3 },
- on_iterate = on_iterate,
- on_finish = on_finish,
- }
-
- assert.spy(job1).was_called(1)
- assert.spy(job2).was_called(1)
- assert.spy(job3).was_called(1)
- assert.spy(on_iterate).was_called(2)
- assert.spy(on_finish).was_called(1)
- assert.spy(on_finish).was_called_with(false)
- end)
-end)
+local match = require "luassert.match"
+local process = require "mason.core.process"
describe("process.spawn", function()
-- Unix only
@@ -78,66 +20,8 @@ describe("process.spawn", function()
assert.wait_for(function()
assert.spy(callback).was_called(1)
- assert.spy(callback).was_called_with(true, 0)
- assert.equal(table.concat(stdio.buffers.stdout, ""), "HELLO=world\nMY_ENV=var\n")
- end)
- end)
- )
-end)
-
-describe("process.chain", function()
- -- Unix only
- it(
- "should chain commands",
- async_test(function()
- local stdio = process.in_memory_sink()
- local callback = spy.new()
-
- local c = process.chain {
- env = {
- "HELLO=world",
- "MY_ENV=var",
- },
- stdio_sink = stdio.sink,
- }
-
- c.run("env", {})
- c.run("bash", { "-c", "echo Hello $HELLO" })
- c.spawn(callback)
-
- assert.wait_for(function()
- assert.spy(callback).was_called(1)
- assert.spy(callback).was_called_with(true)
- assert.equal(table.concat(stdio.buffers.stdout, ""), "HELLO=world\nMY_ENV=var\nHello world\n")
- end)
- end)
- )
-
- -- Unix only
- it(
- "should abort chain commands should one fail",
- async_test(function()
- local stdio = process.in_memory_sink()
- local callback = spy.new()
-
- local c = process.chain {
- env = {
- "HELLO=world",
- "MY_ENV=var",
- },
- stdio_sink = stdio.sink,
- }
-
- c.run("env", {})
- c.run("bash", { "-c", ">&2 echo Uh oh; exit 1" })
- c.run("bash", { "-c", "echo Hello $HELLO" })
- c.spawn(callback)
-
- assert.wait_for(function()
- assert.spy(callback).was_called(1)
- assert.spy(callback).was_called_with(false)
+ assert.spy(callback).was_called_with(true, 0, match.is_number())
assert.equal(table.concat(stdio.buffers.stdout, ""), "HELLO=world\nMY_ENV=var\n")
- assert.equal(table.concat(stdio.buffers.stderr, ""), "Uh oh\n")
end)
end)
)
diff --git a/tests/core/result_spec.lua b/tests/core/result_spec.lua
index 97c7da06..bb884314 100644
--- a/tests/core/result_spec.lua
+++ b/tests/core/result_spec.lua
@@ -1,4 +1,4 @@
-local Result = require "nvim-lsp-installer.core.result"
+local Result = require "mason.core.result"
local match = require "luassert.match"
local spy = require "luassert.spy"
diff --git a/tests/core/spawn_spec.lua b/tests/core/spawn_spec.lua
index ce6e4684..744dfa6d 100644
--- a/tests/core/spawn_spec.lua
+++ b/tests/core/spawn_spec.lua
@@ -1,8 +1,8 @@
local spy = require "luassert.spy"
local stub = require "luassert.stub"
local match = require "luassert.match"
-local spawn = require "nvim-lsp-installer.core.spawn"
-local process = require "nvim-lsp-installer.core.process"
+local spawn = require "mason.core.spawn"
+local process = require "mason.core.process"
describe("async spawn", function()
it(
@@ -112,7 +112,7 @@ describe("async spawn", function()
}
assert.spy(on_spawn).was_called(1)
- assert.spy(on_spawn).was_called_with(match.is_not.is_nil(), match.is_not.is_nil())
+ assert.spy(on_spawn).was_called_with(match.is_not.is_nil(), match.is_table(), match.is_number())
assert.is_true(result:is_success())
assert.equals("im so piped rn", result:get_or_nil().stdout)
end)
@@ -156,7 +156,7 @@ describe("async spawn", function()
local result = spawn.bash {}
assert.is_true(result:is_failure())
assert.equals(
- "spawn: bash failed with exit code 127. This is an error message for bash!",
+ "spawn: bash failed with exit code 127 and signal -. This is an error message for bash!",
tostring(result:err_or_nil())
)
end)
@@ -168,7 +168,7 @@ describe("async spawn", function()
local result = spawn.my_cmd {}
assert.is_true(result:is_failure())
assert.equals(
- "spawn: my_cmd failed with no exit code. my_cmd is not executable",
+ "spawn: my_cmd failed with exit code - and signal -. my_cmd is not executable",
tostring(result:err_or_nil())
)
end)
diff --git a/tests/core/ui_spec.lua b/tests/core/ui_spec.lua
index c591a66d..b60ba6a1 100644
--- a/tests/core/ui_spec.lua
+++ b/tests/core/ui_spec.lua
@@ -1,8 +1,8 @@
local match = require "luassert.match"
local spy = require "luassert.spy"
-local display = require "nvim-lsp-installer.core.ui.display"
-local Ui = require "nvim-lsp-installer.core.ui"
-local a = require "nvim-lsp-installer.core.async"
+local display = require "mason.core.ui.display"
+local Ui = require "mason.core.ui"
+local a = require "mason.core.async"
describe("ui", function()
it("produces a correct tree", function()
@@ -80,6 +80,7 @@ describe("ui", function()
{ "Install something idk", "Stuff" },
},
},
+ Ui.StickyCursor { id = "sticky" },
Ui.Keybind("<CR>", "INSTALL_SERVER", { "tsserver" }, false),
Ui.DiagnosticsNode {
message = "yeah this one's outdated",
@@ -113,6 +114,7 @@ describe("ui", function()
},
lines = { " Hello World!", " Another Line", " Install something idk", " I'm a text node" },
virt_texts = {},
+ sticky_cursors = { line_map = { [3] = "sticky" }, id_map = { ["sticky"] = 3 } },
keybinds = {
{
effect = "INSTALL_SERVER",
@@ -143,7 +145,7 @@ describe("integration test", function()
it(
"calls vim APIs as expected during rendering",
async_test(function()
- local window = display.new_view_only_win "test"
+ local window = display.new_view_only_win("test", "my-filetype")
window.view(function(state)
return Ui.Node {
@@ -161,29 +163,34 @@ describe("integration test", function()
}
end)
- local mutate_state = window.init { text = "Initial state" }
-
- window.open {
- effects = {
- ["EFFECT"] = function() end,
- ["R_EFFECT"] = function() end,
- },
- highlight_groups = {
- "hi def MyHighlight gui=bold",
- },
- }
+ local mutate_state = window.state { text = "Initial state" }
local clear_namespace = spy.on(vim.api, "nvim_buf_clear_namespace")
local buf_set_option = spy.on(vim.api, "nvim_buf_set_option")
local win_set_option = spy.on(vim.api, "nvim_win_set_option")
local set_lines = spy.on(vim.api, "nvim_buf_set_lines")
local set_extmark = spy.on(vim.api, "nvim_buf_set_extmark")
+ local set_hl = spy.on(vim.api, "nvim_set_hl")
local add_highlight = spy.on(vim.api, "nvim_buf_add_highlight")
local set_keymap = spy.on(vim.keymap, "set")
+ window.init {
+ effects = {
+ ["EFFECT"] = function() end,
+ ["R_EFFECT"] = function() end,
+ },
+ highlight_groups = {
+ MyHighlight = { bold = true },
+ },
+ }
+ window.open { border = "none" }
+
-- Initial window and buffer creation + initial render
a.scheduler()
+ assert.spy(set_hl).was_called(1)
+ assert.spy(set_hl).was_called_with(match.is_number(), "MyHighlight", match.same { bold = true })
+
assert.spy(win_set_option).was_called(8)
assert.spy(win_set_option).was_called_with(match.is_number(), "number", false)
assert.spy(win_set_option).was_called_with(match.is_number(), "relativenumber", false)
@@ -201,7 +208,7 @@ describe("integration test", function()
assert.spy(buf_set_option).was_called_with(match.is_number(), "buftype", "nofile")
assert.spy(buf_set_option).was_called_with(match.is_number(), "bufhidden", "wipe")
assert.spy(buf_set_option).was_called_with(match.is_number(), "buflisted", false)
- assert.spy(buf_set_option).was_called_with(match.is_number(), "filetype", "lsp-installer")
+ assert.spy(buf_set_option).was_called_with(match.is_number(), "filetype", "my-filetype")
assert.spy(buf_set_option).was_called_with(match.is_number(), "undolevels", -1)
assert.spy(set_lines).was_called(1)
@@ -259,4 +266,49 @@ describe("integration test", function()
)
end)
)
+
+ it(
+ "anchors to sticky cursor",
+ async_test(function()
+ local window = display.new_view_only_win("test", "my-filetype")
+ window.view(function(state)
+ local extra_lines = state.show_extra_lines
+ and Ui.Text {
+ "More",
+ "Lines",
+ "Here",
+ }
+ or Ui.Node {}
+ return Ui.Node {
+ extra_lines,
+ Ui.Text {
+ "Line 1",
+ "Line 2",
+ "Line 3",
+ "Line 4",
+ "Special line",
+ },
+ Ui.StickyCursor { id = "special" },
+ Ui.Text {
+ "Line 6",
+ "Line 7",
+ "Line 8",
+ "Line 9",
+ "Line 10",
+ },
+ }
+ end)
+ local mutate_state = window.state { show_extra_lines = false }
+ window.init {}
+ window.open { border = "none" }
+ a.scheduler()
+ window.set_cursor { 5, 3 } -- move cursor to sticky line
+ mutate_state(function(state)
+ state.show_extra_lines = true
+ end)
+ a.scheduler()
+ local cursor = window.get_cursor()
+ assert.same({ 8, 3 }, cursor)
+ end)
+ )
end)
diff --git a/tests/dispatcher_spec.lua b/tests/dispatcher_spec.lua
deleted file mode 100644
index 0a2384e9..00000000
--- a/tests/dispatcher_spec.lua
+++ /dev/null
@@ -1,48 +0,0 @@
-local dispatcher = require "nvim-lsp-installer.dispatcher"
-local spy = require "luassert.spy"
-local match = require "luassert.match"
-
-describe("dispatcher", function()
- it("calls registered callbacks", function()
- local server = {}
- local callback = spy.new()
- dispatcher.register_server_ready_callback(callback)
- dispatcher.dispatch_server_ready(server)
-
- assert.spy(callback).was_called(1)
- assert.spy(callback).was_called_with(server)
- end)
-
- it("deregisters callbacks", function()
- local server = {}
- local callback = spy.new()
- local deregister = dispatcher.register_server_ready_callback(callback)
- deregister()
- dispatcher.dispatch_server_ready(server)
-
- assert.spy(callback).was_not_called()
- end)
-
- it("calls all registers callbacks, even if one errors", function()
- local server = {}
- local callback1 = spy.new()
- local callback2 = spy.new(function()
- error "I have an error"
- end)
- local callback3 = spy.new()
- local notify = spy.on(vim, "notify")
- dispatcher.register_server_ready_callback(callback1)
- dispatcher.register_server_ready_callback(callback2)
- dispatcher.register_server_ready_callback(callback3)
- dispatcher.dispatch_server_ready(server)
-
- assert.spy(callback1).was_called(1)
- assert.spy(callback1).was_called_with(server)
- assert.spy(callback2).was_called(1)
- assert.spy(callback2).was_called_with(server)
- assert.spy(callback3).was_called(1)
- assert.spy(callback3).was_called_with(server)
- assert.spy(notify).was_called(1)
- assert.spy(notify).was_called_with(match.has_match "^.*I have an error$", vim.log.levels.ERROR)
- end)
-end)
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
diff --git a/tests/middleware_spec.lua b/tests/middleware_spec.lua
deleted file mode 100644
index 35aa5fe0..00000000
--- a/tests/middleware_spec.lua
+++ /dev/null
@@ -1,71 +0,0 @@
-local util = require "lspconfig.util"
-local servers = require "nvim-lsp-installer.servers"
-local middleware = require "nvim-lsp-installer.middleware"
-
-describe("middleware", function()
- local server
- before_each(function()
- -- 1. setup dummy server
- local default_options = {
- cmd = { "dummy-lsp" },
- cmd_env = { PATH = "/keep/my/path/out/your/f/mouth" },
- }
- server = ServerGenerator {
- default_options = default_options,
- }
- servers.register(server)
-
- -- 2. register hook
- middleware.register_lspconfig_hook()
- end)
-
- after_each(function()
- -- reset hook
- util.on_setup = nil
- end)
-
- it(
- "should apply config changes to installed servers",
- async_test(function()
- server:install()
- assert.wait_for(function()
- assert.is_true(server:is_installed())
- end)
- local config = {
- name = "dummy",
- cmd = { "should", "be", "overwritten" },
- custom = "setting",
- cmd_env = { SOME_DEFAULT_ENV = "important" },
- }
- util.on_setup(config)
- assert.same({
- cmd = { "dummy-lsp" },
- name = "dummy",
- custom = "setting",
- cmd_env = {
- PATH = "/keep/my/path/out/your/f/mouth",
- SOME_DEFAULT_ENV = "important",
- },
- }, config)
- end)
- )
-
- it(
- "should not apply config changes to uninstalled servers",
- async_test(function()
- local config = {
- name = "uninstalled_dummy",
- cmd = { "should", "not", "be", "overwritten" },
- custom = "setting",
- cmd_env = { SOME_DEFAULT_ENV = "important" },
- }
- util.on_setup(config)
- assert.same({
- name = "uninstalled_dummy",
- cmd = { "should", "not", "be", "overwritten" },
- custom = "setting",
- cmd_env = { SOME_DEFAULT_ENV = "important" },
- }, config)
- end)
- )
-end)
diff --git a/tests/minimal_debug_init.lua b/tests/minimal_debug_init.lua
index f090b353..82a8b0d2 100644
--- a/tests/minimal_debug_init.lua
+++ b/tests/minimal_debug_init.lua
@@ -11,9 +11,9 @@ vim.opt.completeopt = "menu"
local temp_dir = vim.loop.os_getenv "TEMP" or "/tmp"
-vim.opt.packpath = join_paths(temp_dir, "nvim-lsp-installer-debug", "site")
+vim.opt.packpath = join_paths(temp_dir, "mason-debug", "site")
-local package_root = join_paths(temp_dir, "nvim-lsp-installer-debug", "site", "pack")
+local package_root = join_paths(temp_dir, "mason-debug", "site", "pack")
local install_path = join_paths(package_root, "packer", "start", "packer.nvim")
local compile_path = join_paths(install_path, "plugin", "packer_compiled.lua")
@@ -22,7 +22,7 @@ local function load_plugins()
{
"wbthomason/packer.nvim",
"neovim/nvim-lspconfig",
- "williamboman/nvim-lsp-installer",
+ "williamboman/mason.nvim",
},
config = {
package_root = package_root,
@@ -38,7 +38,7 @@ function _G.load_config()
vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc")
end
- require("nvim-lsp-installer").setup {
+ require("mason").setup {
log = vim.log.levels.DEBUG,
}
diff --git a/tests/minimal_init.vim b/tests/minimal_init.vim
index 9af729b0..07a2ad62 100644
--- a/tests/minimal_init.vim
+++ b/tests/minimal_init.vim
@@ -3,11 +3,11 @@ set display=lastline
set directory=""
set noswapfile
-let $lsp_installer = getcwd()
+let $mason = getcwd()
let $test_helpers = getcwd() .. "/tests/helpers"
let $dependencies = getcwd() .. "/dependencies"
-set rtp+=$lsp_installer,$test_helpers
+set rtp+=$mason,$test_helpers
set packpath=$dependencies
packloadall
@@ -16,7 +16,10 @@ lua require("luassertx")
lua require("test_helpers")
lua <<EOF
-require("nvim-lsp-installer").settings {
+local pkg_index = require "mason._generated.package_index"
+pkg_index["dummy"] = "dummy_package"
+
+require("mason").setup {
install_root_dir = os.getenv("INSTALL_ROOT_DIR"),
}
EOF
@@ -25,6 +28,7 @@ function! RunTests() abort
lua <<EOF
require("plenary.test_harness").test_directory(os.getenv("FILE") or "./tests", {
minimal_init = vim.fn.getcwd() .. "/tests/minimal_init.vim",
+ sequential = true,
})
EOF
endfunction
diff --git a/tests/server_spec.lua b/tests/server_spec.lua
deleted file mode 100644
index f8c3206f..00000000
--- a/tests/server_spec.lua
+++ /dev/null
@@ -1,55 +0,0 @@
-local spy = require "luassert.spy"
-local lsp_installer = require "nvim-lsp-installer"
-local server = require "nvim-lsp-installer.server"
-local a = require "nvim-lsp-installer.core.async"
-
-local function timestamp()
- local seconds, microseconds = vim.loop.gettimeofday()
- return (seconds * 1000) + math.floor(microseconds / 1000)
-end
-
-describe("server", function()
- it(
- "calls registered on_ready handlers upon successful installation",
- async_test(function()
- local on_ready_handler = spy.new()
- local generic_handler = spy.new()
-
- lsp_installer.on_server_ready(generic_handler)
-
- local srv = ServerGenerator {
- name = "on_ready_fixture",
- root_dir = server.get_server_root_path "on_ready_fixture",
- }
- srv:on_ready(on_ready_handler)
- srv:install()
- assert.wait_for(function()
- assert.spy(on_ready_handler).was_called(1)
- assert.spy(generic_handler).was_called(1)
- assert.spy(generic_handler).was_called_with(srv)
- end)
- assert.is_true(srv:is_installed())
- end)
- )
-
- it(
- "doesn't call on_ready handler when server fails installation",
- async_test(function()
- local on_ready_handler = spy.new()
- local generic_handler = spy.new()
-
- lsp_installer.on_server_ready(generic_handler)
-
- local srv = FailingServerGenerator {
- name = "on_ready_fixture_failing",
- root_dir = server.get_server_root_path "on_ready_fixture_failing",
- }
- srv:on_ready(on_ready_handler)
- srv:install()
- a.sleep(500)
- assert.spy(on_ready_handler).was_not_called()
- assert.spy(generic_handler).was_not_called()
- assert.is_false(srv:is_installed())
- end)
- )
-end)
diff --git a/tests/setup/automatic_installation_exclude_spec.lua b/tests/setup/automatic_installation_exclude_spec.lua
deleted file mode 100644
index bfa5c81b..00000000
--- a/tests/setup/automatic_installation_exclude_spec.lua
+++ /dev/null
@@ -1,44 +0,0 @@
-local spy = require "luassert.spy"
-local lspconfig = require "lspconfig"
-local configs = require "lspconfig.configs"
-local servers = require "nvim-lsp-installer.servers"
-
-describe("automatic_installation_exclude", function()
- it(
- "should install servers set up via lspconfig",
- async_test(function()
- local server1_installer_spy = spy.new()
- local server2_installer_spy = spy.new()
- local server1 = ServerGenerator {
- name = "automatic_installation_exclude1",
- installer = function()
- server1_installer_spy()
- end,
- }
- local server2 = ServerGenerator {
- name = "automatic_installation_exclude2",
- installer = function()
- server2_installer_spy()
- end,
- }
-
- servers.register(server1)
- servers.register(server2)
-
- configs[server1.name] = { default_config = {} }
- configs[server2.name] = { default_config = {} }
-
- require("nvim-lsp-installer").setup {
- automatic_installation = { exclude = { server2.name } },
- }
-
- lspconfig[server1.name].setup {}
- lspconfig[server2.name].setup {}
-
- assert.wait_for(function()
- assert.spy(server1_installer_spy).was_called(1)
- assert.spy(server2_installer_spy).was_called(0)
- end)
- end)
- )
-end)
diff --git a/tests/setup/automatic_installation_spec.lua b/tests/setup/automatic_installation_spec.lua
deleted file mode 100644
index ed35a63a..00000000
--- a/tests/setup/automatic_installation_spec.lua
+++ /dev/null
@@ -1,43 +0,0 @@
-local spy = require "luassert.spy"
-local lspconfig = require "lspconfig"
-local configs = require "lspconfig.configs"
-local servers = require "nvim-lsp-installer.servers"
-
-describe("automatic_installation", function()
- it(
- "should install servers set up via lspconfig",
- async_test(function()
- local server1_installer_spy = spy.new()
- local server2_installer_spy = spy.new()
- local server1 = ServerGenerator {
- name = "automatic_installation1",
- installer = function()
- server1_installer_spy()
- end,
- }
- local server2 = ServerGenerator {
- name = "automatic_installation2",
- installer = function()
- server2_installer_spy()
- end,
- }
-
- servers.register(server1)
- servers.register(server2)
-
- configs[server1.name] = { default_config = {} }
- configs[server2.name] = { default_config = {} }
-
- require("nvim-lsp-installer").setup {
- automatic_installation = true,
- }
-
- lspconfig[server1.name].setup {}
-
- assert.wait_for(function()
- assert.spy(server1_installer_spy).was_called(1)
- assert.spy(server2_installer_spy).was_called(0)
- end)
- end)
- )
-end)
diff --git a/tests/setup/ensure_installed_spec.lua b/tests/setup/ensure_installed_spec.lua
deleted file mode 100644
index 19bb1c8e..00000000
--- a/tests/setup/ensure_installed_spec.lua
+++ /dev/null
@@ -1,39 +0,0 @@
-local spy = require "luassert.spy"
-local configs = require "lspconfig.configs"
-local servers = require "nvim-lsp-installer.servers"
-
-describe("ensure_installed", function()
- it(
- "should install servers",
- async_test(function()
- local server1_installer_spy = spy.new()
- local server2_installer_spy = spy.new()
- local server1 = ServerGenerator {
- name = "ensure_installed1",
- installer = function()
- server1_installer_spy()
- end,
- }
- local server2 = ServerGenerator {
- name = "ensure_installed2",
- installer = function()
- server2_installer_spy()
- end,
- }
-
- servers.register(server1)
- servers.register(server2)
-
- configs[server1.name] = { default_config = {} }
- configs[server2.name] = { default_config = {} }
-
- require("nvim-lsp-installer").setup {
- ensure_installed = { server1.name, server2.name },
- }
- assert.wait_for(function()
- assert.spy(server1_installer_spy).was_called(1)
- assert.spy(server2_installer_spy).was_called(1)
- end)
- end)
- )
-end)
diff --git a/tests/ui_status_win_spec.lua b/tests/ui_status_win_spec.lua
deleted file mode 100644
index 83ebf348..00000000
--- a/tests/ui_status_win_spec.lua
+++ /dev/null
@@ -1,49 +0,0 @@
-local ServerHints = require "nvim-lsp-installer.ui.server_hints"
-
-describe("status win server hints", function()
- it("should produce valid server hints", function()
- local srv = ServerGenerator {
- name = "rust_analyzer",
- languages = { "rust", "analyz", "totallynotjavascript" },
- }
- local hints = ServerHints.new(srv)
- assert.same({ "analyz", "totallynotjavascript" }, hints:get_hints())
- assert.equal("(analyz, totallynotjavascript)", tostring(hints))
- end)
-
- it("should not produce server hints", function()
- local srv = ServerGenerator {
- name = "rust_analyzer",
- languages = { "rust" },
- }
- local srv2 = ServerGenerator {
- name = "cssmodules_ls",
- languages = { "css" },
- }
- local hints = ServerHints.new(srv)
- assert.same({}, hints:get_hints())
- assert.equal("", tostring(hints))
-
- local hints2 = ServerHints.new(srv2)
- assert.same({}, (hints2:get_hints()))
- assert.equal("", tostring(hints2))
- end)
-
- it("should produce server hints even when there's a match if language is short or long", function()
- local srv = ServerGenerator {
- name = "clangd",
- languages = { "c", "c++" },
- }
- local srv2 = ServerGenerator {
- name = "this_is_a_very_cool_rust_server",
- languages = { "rust" },
- }
- local hints = ServerHints.new(srv)
- assert.same({ "c", "c++" }, hints:get_hints())
- assert.equal("(c, c++)", tostring(hints))
-
- local hints2 = ServerHints.new(srv2)
- assert.same({ "rust" }, hints2:get_hints())
- assert.equal("(rust)", tostring(hints2))
- end)
-end)