aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/mason-core/installer/context_spec.lua88
-rw-r--r--tests/mason-core/installer/managers/cargo_spec.lua5
-rw-r--r--tests/mason-core/installer/managers/npm_spec.lua3
-rw-r--r--tests/mason-core/installer/managers/pypi_spec.lua47
-rw-r--r--tests/mason-core/spawn_spec.lua18
-rw-r--r--tests/mason-registry/registry_spec.lua48
6 files changed, 208 insertions, 1 deletions
diff --git a/tests/mason-core/installer/context_spec.lua b/tests/mason-core/installer/context_spec.lua
index 92ef1c49..5b0716c3 100644
--- a/tests/mason-core/installer/context_spec.lua
+++ b/tests/mason-core/installer/context_spec.lua
@@ -2,7 +2,6 @@ local a = require "mason-core.async"
local match = require "luassert.match"
local path = require "mason-core.path"
local pypi = require "mason-core.installer.managers.pypi"
-local registry = require "mason-registry"
local spy = require "luassert.spy"
local stub = require "luassert.stub"
local test_helpers = require "mason-test.helpers"
@@ -279,4 +278,91 @@ cmd.exe /C echo %GREETING% %*]]
assert.equals("Error!", error)
assert.spy(guard).was_called(0)
end)
+
+ describe("system packages", function()
+ local Result = require "mason-core.result"
+ local SystemPackage = require "mason-core.system-package"
+ local _ = require "mason-core.functional"
+
+ local NeedsInstallSystemPackage = SystemPackage:new "needs-install"
+ NeedsInstallSystemPackage.needs_install = _.always(Result.success(true))
+ NeedsInstallSystemPackage.install = _.always(Result.success())
+
+ local InstalledSystemPackage = SystemPackage:new "no-needs-install"
+ InstalledSystemPackage.needs_install = _.always(Result.success(false))
+ InstalledSystemPackage.install = _.always(Result.success())
+
+ local FailingSystemPackage = SystemPackage:new "failing-install"
+ FailingSystemPackage.needs_install = _.always(Result.success(true))
+ FailingSystemPackage.install = _.always(Result.failure "There was an issue.")
+
+ it("should install required system packages", function()
+ local ctx = test_helpers.create_context()
+
+ spy.on(ctx.runner, "suspend")
+ spy.on(ctx.runner, "resume")
+ spy.on(NeedsInstallSystemPackage, "install")
+
+ ctx:execute(function()
+ ctx:require(NeedsInstallSystemPackage)
+ end)
+
+ assert.spy(NeedsInstallSystemPackage.install).was_called(1)
+ assert.spy(ctx.runner.suspend).was_called(1)
+ assert.spy(ctx.runner.resume).was_called(1)
+ end)
+
+ it("should not install required system package if needs_install is false", function()
+ local ctx = test_helpers.create_context()
+
+ spy.on(ctx.runner, "suspend")
+ spy.on(ctx.runner, "resume")
+ spy.on(InstalledSystemPackage, "install")
+
+ ctx:execute(function()
+ ctx:require(InstalledSystemPackage)
+ end)
+
+ assert.spy(InstalledSystemPackage.install).was_called(0)
+ assert.spy(ctx.runner.suspend).was_called(0)
+ assert.spy(ctx.runner.resume).was_called(0)
+ end)
+
+ it("should abort installation if system package installation fails", function()
+ local ctx = test_helpers.create_context()
+ local guard = spy.new()
+
+ spy.on(ctx.runner, "suspend")
+ spy.on(ctx.runner, "resume")
+ spy.on(FailingSystemPackage, "install")
+
+ local result = ctx:execute(function()
+ ctx:require(FailingSystemPackage)
+ guard()
+ end)
+
+ assert.spy(FailingSystemPackage.install).was_called(1)
+ assert.spy(ctx.runner.suspend).was_called(1)
+ assert.spy(ctx.runner.resume).was_called(0)
+ assert.spy(guard).was_called(0)
+ assert.same(result, Result.failure "There was an issue.")
+ end)
+
+ it("should continue installation if system package fails to install but --force is enabled", function()
+ local ctx = test_helpers.create_context { install_opts = { force = true } }
+
+ spy.on(ctx.runner, "suspend")
+ spy.on(ctx.runner, "resume")
+ spy.on(FailingSystemPackage, "install")
+
+ local result = ctx:execute(function()
+ ctx:require(FailingSystemPackage)
+ return Result.success "We forced this."
+ end)
+
+ assert.spy(FailingSystemPackage.install).was_called(1)
+ assert.spy(ctx.runner.suspend).was_called(1)
+ assert.same(result, Result.success "We forced this.")
+ end)
+ end)
end)
diff --git a/tests/mason-core/installer/managers/cargo_spec.lua b/tests/mason-core/installer/managers/cargo_spec.lua
index 66f89ca2..58969855 100644
--- a/tests/mason-core/installer/managers/cargo_spec.lua
+++ b/tests/mason-core/installer/managers/cargo_spec.lua
@@ -20,6 +20,7 @@ describe("cargo manager", function()
vim.NIL, -- features
vim.NIL, -- locked
"my-crate",
+ firewall = true,
}
end)
@@ -53,6 +54,7 @@ describe("cargo manager", function()
vim.NIL, -- features
"--locked", -- locked
"my-crate",
+ firewall = true,
}
end)
@@ -73,6 +75,7 @@ describe("cargo manager", function()
{ "--features", "lsp,cli" }, -- features
vim.NIL, -- locked
"my-crate",
+ firewall = true,
}
end)
@@ -95,6 +98,7 @@ describe("cargo manager", function()
vim.NIL, -- features
vim.NIL, -- locked
"my-crate",
+ firewall = true,
}
end)
@@ -118,6 +122,7 @@ describe("cargo manager", function()
vim.NIL, -- features
vim.NIL, -- locked
"my-crate",
+ firewall = true,
}
end)
end)
diff --git a/tests/mason-core/installer/managers/npm_spec.lua b/tests/mason-core/installer/managers/npm_spec.lua
index 71dca637..e6d5a813 100644
--- a/tests/mason-core/installer/managers/npm_spec.lua
+++ b/tests/mason-core/installer/managers/npm_spec.lua
@@ -72,6 +72,7 @@ describe("npm manager", function()
"my-package@1.0.0",
vim.NIL, -- extra_packages
vim.NIL, -- install_extra_args
+ firewall = true,
}
end)
@@ -89,6 +90,7 @@ describe("npm manager", function()
"my-package@1.0.0",
{ "extra-package" },
vim.NIL, -- install_extra_args
+ firewall = true,
}
end)
@@ -107,6 +109,7 @@ describe("npm manager", function()
"my-package@1.0.0",
vim.NIL, -- extra_packages
{ "--registry", "https://registry.npmjs.org/" }, -- install_extra_args
+ firewall = true,
}
end)
diff --git a/tests/mason-core/installer/managers/pypi_spec.lua b/tests/mason-core/installer/managers/pypi_spec.lua
index ef57411b..34a9f8e3 100644
--- a/tests/mason-core/installer/managers/pypi_spec.lua
+++ b/tests/mason-core/installer/managers/pypi_spec.lua
@@ -83,6 +83,7 @@ describe("pypi manager", function()
"--ignore-installed",
{ "--proxy", "http://localhost" },
{ "pip" },
+ firewall = true,
}
end)
@@ -92,6 +93,8 @@ describe("pypi manager", function()
stub(ctx.fs, "file_exists")
stub(providers.pypi, "get_supported_python_versions", mockx.returns(Result.success ">=3.12"))
stub(vim.fn, "executable")
+ vim.fn.executable.on_call_with("python3.14").returns(0)
+ vim.fn.executable.on_call_with("python3.13").returns(0)
vim.fn.executable.on_call_with("python3.12").returns(1)
stub(spawn, "python3.12")
spawn["python3.12"].on_call_with({ "--version" }).returns(Result.success { stdout = "Python 3.12.0" })
@@ -115,6 +118,43 @@ describe("pypi manager", function()
}
end)
+ it("should find versioned candidates in ascending order", function()
+ local ctx = test_helpers.create_context()
+ stub(ctx, "promote_cwd")
+ stub(ctx.fs, "file_exists")
+ stub(providers.pypi, "get_supported_python_versions", mockx.returns(Result.success ">=3.12"))
+ stub(vim.fn, "executable")
+ vim.fn.executable.on_call_with("python3.14").returns(1)
+ vim.fn.executable.on_call_with("python3.13").returns(1)
+ vim.fn.executable.on_call_with("python3.12").returns(1)
+ stub(spawn, "python3.14")
+ stub(spawn, "python3.13")
+ stub(spawn, "python3.12")
+ spawn["python3.14"].on_call_with({ "--version" }).returns(Result.success { stdout = "Python 3.14.0" })
+ spawn["python3.13"].on_call_with({ "--version" }).returns(Result.success { stdout = "Python 3.13.0" })
+ spawn["python3.12"].on_call_with({ "--version" }).returns(Result.success { stdout = "Python 3.12.0" })
+ ctx.fs.file_exists.on_call_with(match.ref(ctx.fs), "venv/bin/python").returns(true)
+
+ ctx:execute(function()
+ pypi.init {
+ package = { name = "cmake-language-server", version = "0.1.10" },
+ upgrade_pip = false,
+ install_extra_args = {},
+ }
+ end)
+
+ assert.spy(ctx.spawn["python3.14"]).was_not_called()
+ assert.spy(ctx.spawn["python3.13"]).was_not_called()
+ assert.spy(ctx.promote_cwd).was_called(1)
+ assert.spy(ctx.spawn["python3.12"]).was_called(1)
+ assert.spy(ctx.spawn["python3.12"]).was_called_with {
+ "-m",
+ "venv",
+ "--system-site-packages",
+ "venv",
+ }
+ end)
+
it("should error if unable to find a suitable python3 version", function()
local ctx = test_helpers.create_context()
spy.on(ctx.stdio_sink, "stderr")
@@ -122,6 +162,8 @@ describe("pypi manager", function()
stub(ctx.fs, "file_exists")
stub(providers.pypi, "get_supported_python_versions", mockx.returns(Result.success ">=3.8"))
stub(vim.fn, "executable")
+ vim.fn.executable.on_call_with("python3.14").returns(0)
+ vim.fn.executable.on_call_with("python3.13").returns(0)
vim.fn.executable.on_call_with("python3.12").returns(0)
vim.fn.executable.on_call_with("python3.11").returns(0)
vim.fn.executable.on_call_with("python3.10").returns(0)
@@ -156,6 +198,8 @@ describe("pypi manager", function()
stub(ctx.fs, "file_exists")
stub(providers.pypi, "get_supported_python_versions", mockx.returns(Result.success ">=3.8"))
stub(vim.fn, "executable")
+ vim.fn.executable.on_call_with("python3.14").returns(0)
+ vim.fn.executable.on_call_with("python3.13").returns(0)
vim.fn.executable.on_call_with("python3.12").returns(0)
vim.fn.executable.on_call_with("python3.11").returns(0)
vim.fn.executable.on_call_with("python3.10").returns(0)
@@ -239,6 +283,7 @@ describe("pypi manager", function()
"pypi-package==1.0.0",
vim.NIL, -- extra_packages
},
+ firewall = true,
}
end)
@@ -281,6 +326,7 @@ describe("pypi manager", function()
"pypi-package[lsp]==1.0.0",
vim.NIL, -- extra_packages
},
+ firewall = true,
}
end)
@@ -308,6 +354,7 @@ describe("pypi manager", function()
"pypi-package==1.0.0",
{ "extra-package" },
},
+ firewall = true,
}
end)
end)
diff --git a/tests/mason-core/spawn_spec.lua b/tests/mason-core/spawn_spec.lua
index b224bfc3..abbe557e 100644
--- a/tests/mason-core/spawn_spec.lua
+++ b/tests/mason-core/spawn_spec.lua
@@ -193,6 +193,24 @@ describe("async spawn", function()
)
end)
+ it("should handle being unable to find PATH env", function()
+ stub(process, "spawn", function(_, _, callback)
+ callback(true, 0, 0)
+ end)
+
+ local result = a.run_blocking(spawn.bash, { "arg1", env_raw = { SOME_ENV = "value" } })
+ assert.is_true(result:is_success())
+ assert.spy(process.spawn).was_called(1)
+ assert.spy(process.spawn).was_called_with(
+ vim.fn.exepath "bash",
+ match.tbl_containing {
+ args = match.same { "arg1" },
+ env = match.is_table(),
+ },
+ match.is_function()
+ )
+ end)
+
it("should use exepath if env_raw.PATH is set", function()
stub(process, "spawn", function(_, _, callback)
callback(true, 0, 0)
diff --git a/tests/mason-registry/registry_spec.lua b/tests/mason-registry/registry_spec.lua
index daa8fc9f..cf909667 100644
--- a/tests/mason-registry/registry_spec.lua
+++ b/tests/mason-registry/registry_spec.lua
@@ -1,5 +1,7 @@
local Pkg = require "mason-core.package"
+local match = require "luassert.match"
local registry = require "mason-registry"
+local spy = require "luassert.spy"
local test_helpers = require "mason-test.helpers"
describe("mason-registry", function()
@@ -33,4 +35,50 @@ describe("mason-registry", function()
test_helpers.sync_install(dummy)
assert.is_true(registry.is_installed "dummy")
end)
+
+ describe("refresh/update", function()
+ local a = require "mason-core.async"
+ local settings = require "mason.settings"
+ local installer = require "mason-registry.installer"
+
+ after_each(function()
+ settings.set(settings._DEFAULT_SETTINGS)
+ end)
+
+ it("should refresh registry synchronously", function()
+ local ok, updated_registries = registry.refresh()
+ assert.is_true(ok)
+ assert.same({}, updated_registries)
+ end)
+
+ it("should call registry.refresh callback", function()
+ local spy = spy.new()
+ registry.refresh(spy)
+ assert.wait(function()
+ assert.spy(spy).was_called(1)
+ assert.spy(spy).was_called_with(true, {})
+ end)
+ end)
+
+ it("should call registry.update callback", function()
+ local spy = spy.new()
+ registry.update(spy)
+ assert.wait(function()
+ assert.spy(spy).was_called(1)
+ assert.spy(spy).was_called_with(true, match.is_table())
+ end)
+ end)
+
+ it("should immediately return if refresh is disabled", function()
+ settings.current.registry_cache.refresh = false
+ local ok, registries = registry.refresh()
+ assert.is_true(ok)
+ assert.same({}, registries)
+
+ local spy = spy.new()
+ registry.refresh(spy)
+ assert.spy(spy).was_called(1)
+ assert.spy(spy).was_called_with(true, {})
+ end)
+ end)
end)