aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2022-09-14 17:58:11 +0200
committerGitHub <noreply@github.com>2022-09-14 17:58:11 +0200
commitd39e46db31c9b2eee458ca59a814ebc4fe8a5bd5 (patch)
treecac215882f0692cd2e181944210e768a32d23a58
parentfix(r-languageserver): use github releases as version source (#417) (diff)
downloadmason-d39e46db31c9b2eee458ca59a814ebc4fe8a5bd5.tar
mason-d39e46db31c9b2eee458ca59a814ebc4fe8a5bd5.tar.gz
mason-d39e46db31c9b2eee458ca59a814ebc4fe8a5bd5.tar.bz2
mason-d39e46db31c9b2eee458ca59a814ebc4fe8a5bd5.tar.lz
mason-d39e46db31c9b2eee458ca59a814ebc4fe8a5bd5.tar.xz
mason-d39e46db31c9b2eee458ca59a814ebc4fe8a5bd5.tar.zst
mason-d39e46db31c9b2eee458ca59a814ebc4fe8a5bd5.zip
refactor: store link state in install context object (#419)
-rw-r--r--lua/mason-core/installer/context.lua7
-rw-r--r--lua/mason-core/installer/linker.lua3
-rw-r--r--tests/helpers/lua/luassertx.lua8
-rw-r--r--tests/mason-core/installer/installer_spec.lua26
-rw-r--r--vim.yml5
5 files changed, 41 insertions, 8 deletions
diff --git a/lua/mason-core/installer/context.lua b/lua/mason-core/installer/context.lua
index 7d0a505b..50850219 100644
--- a/lua/mason-core/installer/context.lua
+++ b/lua/mason-core/installer/context.lua
@@ -141,6 +141,7 @@ end
---@field public package Package
---@field public cwd CwdManager
---@field public stdio_sink StdioSink
+---@field private bin_links table<string, string>
local InstallContext = {}
InstallContext.__index = InstallContext
@@ -160,6 +161,7 @@ function InstallContext.new(handle, opts)
receipt = receipt.InstallReceiptBuilder.new(),
requested_version = Optional.of_nilable(opts.requested_version),
stdio_sink = handle.stdio.sink,
+ bin_links = {},
}, InstallContext)
end
@@ -310,8 +312,11 @@ function InstallContext:write_shell_exec_wrapper(new_executable_rel_path, comman
}
end
+---@param executable string
+---@param rel_path string
function InstallContext:link_bin(executable, rel_path)
- self.receipt:with_link("bin", executable, rel_path)
+ self.bin_links[executable] = rel_path
+ return self
end
return InstallContext
diff --git a/lua/mason-core/installer/linker.lua b/lua/mason-core/installer/linker.lua
index 0419f392..a1cc53d0 100644
--- a/lua/mason-core/installer/linker.lua
+++ b/lua/mason-core/installer/linker.lua
@@ -33,7 +33,7 @@ end
---@async
---@param context InstallContext
local function link_bin(context)
- local links = context.receipt.links.bin
+ local links = context.bin_links
local pkg = context.package
for name, rel_path in pairs(links) do
local target_abs_path = path.concat { pkg:get_install_path(), rel_path }
@@ -71,6 +71,7 @@ local function link_bin(context)
)
end,
}
+ context.receipt:with_link("bin", name, rel_path)
end
end
diff --git a/tests/helpers/lua/luassertx.lua b/tests/helpers/lua/luassertx.lua
index 3eba3fa4..d6d24d8e 100644
--- a/tests/helpers/lua/luassertx.lua
+++ b/tests/helpers/lua/luassertx.lua
@@ -64,7 +64,15 @@ local function instanceof(_, arguments, _)
end
end
+local function capture(_, arguments, _)
+ return function(value)
+ arguments[1](value)
+ return true
+ end
+end
+
assert:register("matcher", "tbl_containing", tbl_containing)
assert:register("matcher", "list_containing", list_containing)
assert:register("matcher", "instanceof", instanceof)
+assert:register("matcher", "capture", capture)
assert:register("assertion", "wait_for", wait_for)
diff --git a/tests/mason-core/installer/installer_spec.lua b/tests/mason-core/installer/installer_spec.lua
index 8dc9b516..ead08f18 100644
--- a/tests/mason-core/installer/installer_spec.lua
+++ b/tests/mason-core/installer/installer_spec.lua
@@ -57,12 +57,26 @@ describe("installer", function()
"should write receipt",
async_test(function()
spy.on(fs.async, "write_file")
- 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/mason-receipt.json"):format(handle.package:get_install_path()), match.is_string())
+ local handler = InstallHandleGenerator "dummy"
+ ---@param ctx InstallContext
+ handler.package.spec.install = function(ctx)
+ ctx.receipt:with_primary_source { type = "source", metadata = {} }
+ ctx.fs:write_file("target", "script-contents")
+ ctx:link_bin("executable", "target")
+ end
+ installer.execute(handler, {})
+ assert.spy(fs.async.write_file).was_called_with(
+ ("%s/mason-receipt.json"):format(handler.package:get_install_path()),
+ match.capture(function(arg)
+ ---@type InstallReceipt
+ local receipt = vim.json.decode(arg)
+ assert.equals("dummy", receipt.name)
+ assert.same({ type = "source", metadata = {} }, receipt.primary_source)
+ assert.same({}, receipt.secondary_sources)
+ assert.same("1.0", receipt.schema_version)
+ assert.same({ bin = { executable = "target" } }, receipt.links)
+ end)
+ )
end)
)
diff --git a/vim.yml b/vim.yml
index 72b86e7c..5bd4947d 100644
--- a/vim.yml
+++ b/vim.yml
@@ -39,6 +39,9 @@ globals:
before_each:
args:
- type: function
+ after_each:
+ args:
+ - type: function
it:
args:
- type: string
@@ -65,3 +68,5 @@ globals:
- type: any
assert.spy:
any: true
+ assert.snapshot:
+ args: []