aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/mason-core/installer/compiler/compilers/npm_spec.lua23
-rw-r--r--tests/mason-core/installer/compiler/compilers/pypi_spec.lua7
-rw-r--r--tests/mason-core/installer/managers/npm_spec.lua20
-rw-r--r--tests/mason-core/installer/managers/powershell_spec.lua2
-rw-r--r--tests/mason-core/package/package_spec.lua32
-rw-r--r--tests/mason-core/spawn_spec.lua18
-rw-r--r--tests/mason-core/ui_spec.lua2
-rw-r--r--tests/mason/setup_spec.lua6
8 files changed, 103 insertions, 7 deletions
diff --git a/tests/mason-core/installer/compiler/compilers/npm_spec.lua b/tests/mason-core/installer/compiler/compilers/npm_spec.lua
index 94d67801..b6a252c9 100644
--- a/tests/mason-core/installer/compiler/compilers/npm_spec.lua
+++ b/tests/mason-core/installer/compiler/compilers/npm_spec.lua
@@ -1,6 +1,7 @@
local Purl = require "mason-core.purl"
local Result = require "mason-core.result"
local npm = require "mason-core.installer.compiler.compilers.npm"
+local settings = require "mason.settings"
local stub = require "luassert.stub"
local test_helpers = require "mason-test.helpers"
@@ -14,12 +15,25 @@ local function purl(overrides)
end
describe("npm compiler :: parsing", function()
+ after_each(function()
+ settings.set(settings._DEFAULT_SETTINGS)
+ end)
+
it("should parse package", function()
+ settings.set {
+ npm = {
+ install_args = { "--registry", "https://registry.npmjs.org/" },
+ },
+ }
+
assert.same(
Result.success {
package = "@namespace/package",
version = "v1.5.0",
extra_packages = { "extra" },
+ npm = {
+ extra_args = { "--registry", "https://registry.npmjs.org/" },
+ },
},
npm.parse({ extra_packages = { "extra" } }, purl())
)
@@ -48,12 +62,19 @@ describe("npm compiler :: installing", function()
package = "@namespace/package",
version = "v1.5.0",
extra_packages = { "extra" },
+ npm = {
+ extra_args = { "--registry", "https://registry.npmjs.org/" },
+ },
})
end)
assert.is_true(result:is_success())
assert.spy(manager.init).was_called(1)
assert.spy(manager.install).was_called(1)
- assert.spy(manager.install).was_called_with("@namespace/package", "v1.5.0", { extra_packages = { "extra" } })
+ assert.spy(manager.install).was_called_with(
+ "@namespace/package",
+ "v1.5.0",
+ { extra_packages = { "extra" }, install_extra_args = { "--registry", "https://registry.npmjs.org/" } }
+ )
end)
end)
diff --git a/tests/mason-core/installer/compiler/compilers/pypi_spec.lua b/tests/mason-core/installer/compiler/compilers/pypi_spec.lua
index 03c57a9e..397af950 100644
--- a/tests/mason-core/installer/compiler/compilers/pypi_spec.lua
+++ b/tests/mason-core/installer/compiler/compilers/pypi_spec.lua
@@ -15,6 +15,10 @@ local function purl(overrides)
end
describe("pypi compiler :: parsing", function()
+ after_each(function()
+ settings.set(settings._DEFAULT_SETTINGS)
+ end)
+
it("should parse package", function()
settings.set {
pip = {
@@ -35,7 +39,6 @@ describe("pypi compiler :: parsing", function()
},
pypi.parse({ extra_packages = { "extra" } }, purl())
)
- settings.set(settings._DEFAULT_SETTINGS)
end)
end)
@@ -47,6 +50,7 @@ describe("pypi compiler :: installing", function()
end)
after_each(function()
+ settings.set(settings._DEFAULT_SETTINGS)
snapshot:revert()
end)
@@ -88,6 +92,5 @@ describe("pypi compiler :: installing", function()
"1.5.0",
{ extra = "lsp", extra_packages = { "extra" }, install_extra_args = { "--proxy", "http://localghost" } }
)
- settings.set(settings._DEFAULT_SETTINGS)
end)
end)
diff --git a/tests/mason-core/installer/managers/npm_spec.lua b/tests/mason-core/installer/managers/npm_spec.lua
index e3a2bc76..71dca637 100644
--- a/tests/mason-core/installer/managers/npm_spec.lua
+++ b/tests/mason-core/installer/managers/npm_spec.lua
@@ -71,6 +71,7 @@ describe("npm manager", function()
"install",
"my-package@1.0.0",
vim.NIL, -- extra_packages
+ vim.NIL, -- install_extra_args
}
end)
@@ -87,6 +88,25 @@ describe("npm manager", function()
"install",
"my-package@1.0.0",
{ "extra-package" },
+ vim.NIL, -- install_extra_args
+ }
+ end)
+
+ it("should install with extra args", function()
+ local ctx = test_helpers.create_context()
+
+ ctx:execute(function()
+ npm.install("my-package", "1.0.0", {
+ install_extra_args = { "--registry", "https://registry.npmjs.org/" },
+ })
+ end)
+
+ assert.spy(ctx.spawn.npm).was_called(1)
+ assert.spy(ctx.spawn.npm).was_called_with {
+ "install",
+ "my-package@1.0.0",
+ vim.NIL, -- extra_packages
+ { "--registry", "https://registry.npmjs.org/" }, -- install_extra_args
}
end)
diff --git a/tests/mason-core/installer/managers/powershell_spec.lua b/tests/mason-core/installer/managers/powershell_spec.lua
index 14478305..5560c4f2 100644
--- a/tests/mason-core/installer/managers/powershell_spec.lua
+++ b/tests/mason-core/installer/managers/powershell_spec.lua
@@ -69,7 +69,7 @@ describe("powershell manager", function()
"-NoProfile",
"-NonInteractive",
"-Command",
- [[ $ErrorActionPreference = "Stop"; $ProgressPreference = 'SilentlyContinue'; [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; echo 'Is this bash?']],
+ [[ $ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue'; [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; echo 'Is this bash?']],
})
end)
diff --git a/tests/mason-core/package/package_spec.lua b/tests/mason-core/package/package_spec.lua
index 8d1929d8..b05a2355 100644
--- a/tests/mason-core/package/package_spec.lua
+++ b/tests/mason-core/package/package_spec.lua
@@ -145,6 +145,38 @@ describe("Package ::", function()
end)
end)
+ it("should successfully uninstall package", function()
+ local dummy = registry.get_package "dummy"
+ local package_uninstall_success_handler = spy.new()
+ local package_uninstall_failed_handler = spy.new()
+ local uninstall_success_handler = spy.new()
+ local uninstall_failed_handler = spy.new()
+ registry:once("package:uninstall:success", package_uninstall_success_handler)
+ registry:once("package:uninstall:failed", package_uninstall_failed_handler)
+ dummy:once("uninstall:success", uninstall_success_handler)
+ dummy:once("uninstall:failed", uninstall_failed_handler)
+
+ local handle = dummy:install { version = "1337" }
+
+ assert.wait(function()
+ assert.is_true(handle:is_closed())
+ assert.is_true(dummy:is_installed())
+ end)
+
+ dummy:uninstall()
+
+ assert.wait(function()
+ assert.spy(uninstall_success_handler).was_called(1)
+ assert.spy(uninstall_success_handler).was_called_with(match.instanceof(receipt.InstallReceipt))
+ assert.spy(package_uninstall_success_handler).was_called(1)
+ assert
+ .spy(package_uninstall_success_handler)
+ .was_called_with(match.is_ref(dummy), match.instanceof(receipt.InstallReceipt))
+ assert.spy(package_uninstall_failed_handler).was_called(0)
+ assert.spy(uninstall_failed_handler).was_called(0)
+ end)
+ end)
+
it("should fail to install package", function()
local dummy = registry.get_package "dummy"
stub(dummy.spec.source, "install", function()
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-core/ui_spec.lua b/tests/mason-core/ui_spec.lua
index efd60712..4f77bd5d 100644
--- a/tests/mason-core/ui_spec.lua
+++ b/tests/mason-core/ui_spec.lua
@@ -233,7 +233,7 @@ describe("integration test", function()
match.tbl_containing { nowait = true, silent = true, buffer = match.is_number() }
)
- assert.spy(clear_namespace).was_called(1)
+ assert.spy(clear_namespace).was_called()
assert.spy(clear_namespace).was_called_with(match.is_number(), match.is_number(), 0, -1)
mutate_state(function(state)
diff --git a/tests/mason/setup_spec.lua b/tests/mason/setup_spec.lua
index a4320bb3..a6865eb3 100644
--- a/tests/mason/setup_spec.lua
+++ b/tests/mason/setup_spec.lua
@@ -47,6 +47,8 @@ describe("mason setup", function()
mason.setup()
local user_commands = vim.api.nvim_get_commands {}
+ local lua_func = vim.fn.has "nvim-0.12" == 1 and match.is_function() or "<Lua function>"
+
assert.is_true(match.tbl_containing {
bang = false,
bar = false,
@@ -59,7 +61,7 @@ describe("mason setup", function()
bar = false,
definition = "Install one or more packages.",
nargs = "+",
- complete = "<Lua function>",
+ complete = lua_func,
}(user_commands["MasonInstall"]))
assert.is_true(match.tbl_containing {
@@ -67,7 +69,7 @@ describe("mason setup", function()
bar = false,
definition = "Uninstall one or more packages.",
nargs = "+",
- complete = "<Lua function>",
+ complete = lua_func,
}(user_commands["MasonUninstall"]))
assert.is_true(match.tbl_containing {