summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2025-03-24 22:40:33 +0100
committerWilliam Boman <william@redwill.se>2025-03-24 22:43:57 +0100
commite638ed8e0dbf297feedc127e65e95667e9da373c (patch)
tree8dbeb816c421769972ad81f159a59d07f7356262
parentrefactor(command): use callback in Package:install() when running :MasonInsta... (diff)
downloadmason-e638ed8e0dbf297feedc127e65e95667e9da373c.tar
mason-e638ed8e0dbf297feedc127e65e95667e9da373c.tar.gz
mason-e638ed8e0dbf297feedc127e65e95667e9da373c.tar.bz2
mason-e638ed8e0dbf297feedc127e65e95667e9da373c.tar.lz
mason-e638ed8e0dbf297feedc127e65e95667e9da373c.tar.xz
mason-e638ed8e0dbf297feedc127e65e95667e9da373c.tar.zst
mason-e638ed8e0dbf297feedc127e65e95667e9da373c.zip
fix(registry): fix registry.is_installed()
-rw-r--r--lua/mason-registry/init.lua4
-rw-r--r--tests/mason-registry/registry_spec.lua8
2 files changed, 10 insertions, 2 deletions
diff --git a/lua/mason-registry/init.lua b/lua/mason-registry/init.lua
index bd35f073..b129380c 100644
--- a/lua/mason-registry/init.lua
+++ b/lua/mason-registry/init.lua
@@ -13,8 +13,8 @@ Registry.aliases = {}
---@param pkg_name string
function Registry.is_installed(pkg_name)
- local ok, stat = pcall(uv.fs_stat, InstallLocation.global():package(pkg_name), "r", 438)
- return ok and stat.type == "directory"
+ local stat = uv.fs_stat(InstallLocation.global():package(pkg_name))
+ return stat ~= nil and stat.type == "directory"
end
---Returns an instance of the Package class if the provided package name exists. This function errors if a package
diff --git a/tests/mason-registry/registry_spec.lua b/tests/mason-registry/registry_spec.lua
index 359c0630..35c37853 100644
--- a/tests/mason-registry/registry_spec.lua
+++ b/tests/mason-registry/registry_spec.lua
@@ -1,4 +1,5 @@
local Pkg = require "mason-core.package"
+local test_helpers = require "mason-test.helpers"
local registry = require "mason-registry"
describe("mason-registry", function()
@@ -21,4 +22,11 @@ describe("mason-registry", function()
it("should get all package specs", function()
assert.equals(3, #registry.get_all_package_specs())
end)
+
+ it("should check if package is installed", function ()
+ local dummy = registry.get_package "dummy"
+ assert.is_false(registry.is_installed "dummy")
+ test_helpers.sync_install(dummy)
+ assert.is_true(registry.is_installed "dummy")
+ end)
end)